msg

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Example (Printf)
SetWriter(os.Stdout)
defer SetWriter(os.Stderr)
Printf("hello")
Output:

hello
Example (Printlf)
SetWriter(os.Stdout)
defer SetWriter(os.Stderr)
Printlf(DEBUG, "debug mode is off")
SetDebugMode(true)
Printlf(DEBUG, "debug mode is on")
Output:

[DEBUG] debug mode is on

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Print added in v0.0.2

func Print(str string)

Print prints the given string on the terminals to user.

func Printf

func Printf(str string, objs ...interface{})

Printf prints formatted strings on the terminals to user.

func Printlf

func Printlf(level Level, str string, objs ...interface{})

Printlf prints formatted strings with a message level prefix on the terminals to user.

func SetDebugMode

func SetDebugMode(debugMode bool)

SetDebugMode set the debug mode. Debug level message sent to user only when debug mode is on.

func SetWriter

func SetWriter(writer io.Writer)

SetWriter sets the io writer to the msg.

Types

type Level

type Level uint

Level defines the log level of the message that is printed to the user. Debug level messages are printed to the user only when debug mode is on.

const (
	DEBUG Level = iota
	INFO
	WARN
	ERROR
	FATAL
)

type Prompter

type Prompter struct {
	// contains filtered or unexported fields
}

Prompter contains the logic to interact with users.

func NewPrompter

func NewPrompter() *Prompter

NewPrompter returns a new Prompter.

func (*Prompter) Prompt

func (p *Prompter) Prompt(m string)

Prompt prompts message to users.

Example
// Disable parallel because we temporarily redirect the writer.
SetWriter(os.Stdout)
defer SetWriter(os.Stderr)
p := NewPrompter()
p.Prompt("hello")
Output:

>>> hello

func (*Prompter) Promptf

func (p *Prompter) Promptf(str string, objs ...interface{})

Promptf prompts message to users.

Example
// Disable parallel because we temporarily redirect the writer.
SetWriter(os.Stdout)
defer SetWriter(os.Stderr)
p := NewPrompter()
p.Promptf("%s\n %s", "some", "message")
Output:

>>> some
 message

func (*Prompter) ReadString

func (p *Prompter) ReadString() (string, error)

ReadString reads input string from users.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL