stdio

package
v0.0.0-...-94027f3 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RESET  = "\033[0m"
	RED    = "\033[31m"
	GREEN  = "\033[32m"
	YELLOW = "\033[33m"
	BLUE   = "\033[34m"
)

Define ANSI color codes.

View Source
const (
	DEBUG = log.DebugLevel
	NORM  = log.Level(10)
	INFO  = log.InfoLevel
	WARN  = log.WarnLevel
	ERROR = log.ErrorLevel
	FATAL = log.FatalLevel
)

Variables

View Source
var (
	TypeSpinner    = reflect.TypeOf(&Spinner{})
	TYpeProcessBar = reflect.TypeOf(&ProcessBar{})
)
View Source
var (
	InfoSymbol    = info("[INFO]")
	SuccessSymbol = success("[SUCCEED]")
	WarningSymbol = warn("[WARNING]")
	ErrorSymbol   = err("[ERROR]")
	FailedSymbol  = err("[FAILED]")
)

Functions

func Confirm

func Confirm(msg string) (bool, error)

func Confirmf

func Confirmf(format string, a ...any) (bool, error)

func Error

func Error(msg string)

func Errorf

func Errorf(format string, a ...any)

func ExitProcessBar

func ExitProcessBar()

func Failed

func Failed(msg string)

func Failedf

func Failedf(format string, a ...interface{})

func FinishProcessBar

func FinishProcessBar()

func IncProcessBar

func IncProcessBar()

func Info

func Info(msg string)

func Infof

func Infof(format string, a ...any)

func InputPassword

func InputPassword(msg string) (string, error)

func IsBusy

func IsBusy() bool

func IsTTY

func IsTTY() bool

func LoadError

func LoadError(msg string)

func LoadErrorf

func LoadErrorf(format string, a ...any)

func LoadFailed

func LoadFailed(msg string)

func LoadFailedWithoutMsg

func LoadFailedWithoutMsg()

func LoadFailedf

func LoadFailedf(format string, a ...any)

func LoadInfo

func LoadInfo(msg string)

func LoadInfof

func LoadInfof(format string, a ...any)

func LoadStageSuccess

func LoadStageSuccess(msg string)

func LoadStageSuccessf

func LoadStageSuccessf(format string, a ...interface{})

func LoadSuccess

func LoadSuccess(msg string)

func LoadSuccessf

func LoadSuccessf(format string, a ...any)

func Print

func Print(msg string)

func PrintTable

func PrintTable(header []string, data [][]string)

func PrintTableWithTitle

func PrintTableWithTitle(title string, header []string, data [][]string)

func Printf

func Printf(format string, a ...any)

func PrintfWithoutNewline

func PrintfWithoutNewline(format string, a ...any)

func ReadLine

func ReadLine(blocked bool) (string, error)

func ReadLines

func ReadLines(blocked bool) ([]string, error)

func SetSilenceMode

func SetSilenceMode(silence bool)

func SetSkipConfirmMode

func SetSkipConfirmMode(skip bool)

func SetVerboseMode

func SetVerboseMode(verbose bool)

func StartLoading

func StartLoading(msg string)

func StartLoadingf

func StartLoadingf(format string, a ...any)

func StartOrUpdateLoading

func StartOrUpdateLoading(msg string)

func StartProcessBar

func StartProcessBar(msg string)

func StopLoading

func StopLoading()

func Success

func Success(msg string)

func Successf

func Successf(format string, a ...interface{})

func UpdateLoading

func UpdateLoading(msg string)

func UpdateLoadingf

func UpdateLoadingf(format string, a ...any)

func UpdateProcessBar

func UpdateProcessBar(i int)

func Verbose

func Verbose(msg string)

func Verbosef

func Verbosef(format string, a ...any)

func Warn

func Warn(msg string)

func Warnf

func Warnf(format string, a ...any)

Types

type Animate

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

func (*Animate) IsRunning

func (s *Animate) IsRunning() bool

type Animater

type Animater interface {
	IsRunning() bool
	// contains filtered or unexported methods
}

type BufferIO

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

BufferIO simulates an in-memory buffer that implements io.Reader, io.Writer, and io.Closer interfaces.

func NewBufferIO

func NewBufferIO(autoClear bool) *BufferIO

NewBufferIO creates a new BufferIO instance.

func (*BufferIO) Clear

func (bio *BufferIO) Clear()

Clear resets the buffer contents.

func (*BufferIO) Close

func (bio *BufferIO) Close() error

Close marks the buffer as closed.

func (*BufferIO) Flush

func (bio *BufferIO) Flush() error

Flush clears the buffer if autoClear is enabled.

func (*BufferIO) GetBuffer

func (bio *BufferIO) GetBuffer() bytes.Buffer

func (*BufferIO) IsTTY

func (bio *BufferIO) IsTTY() bool

IsTty always returns false to indicate it's not a terminal.

func (*BufferIO) Open

func (bio *BufferIO) Open()

Open resets the buffer and marks it as open.

func (*BufferIO) Read

func (bio *BufferIO) Read(p []byte) (n int, err error)

Read reads the next len(p) bytes from the buffer.

func (*BufferIO) String

func (bio *BufferIO) String() string

String returns the contents of the buffer as a string.

func (*BufferIO) Writable

func (bio *BufferIO) Writable() bool

Writable returns whether the buffer is open for writing.

func (*BufferIO) Write

func (bio *BufferIO) Write(p []byte) (n int, err error)

Write appends the given bytes to the buffer.

type FormattedText

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

FormattedText is a struct that holds text and its associated color.

func NewFormattedText

func NewFormattedText(text, color string) *FormattedText

NewFormattedText creates a new FormattedText with the given text and color.

func (*FormattedText) Format

func (ft *FormattedText) Format(istty bool) string

Format decides whether to return colored text or plain text based on istty.

func (*FormattedText) String

func (ft *FormattedText) String() string

String method to comply with the Stringer interface.

type IO

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

func NewIO

func NewIO() *IO

func (*IO) Confirm

func (io *IO) Confirm(msg string) (bool, error)

func (*IO) Confirmf

func (io *IO) Confirmf(format string, a ...any) (bool, error)

func (*IO) Error

func (io *IO) Error(msg string)

func (*IO) Errorf

func (io *IO) Errorf(format string, a ...any)

func (*IO) ExitProcessBar

func (io *IO) ExitProcessBar()

func (*IO) Failed

func (io *IO) Failed(msg string)

func (*IO) Failedf

func (io *IO) Failedf(format string, a ...any)

func (*IO) FinishProcessBar

func (io *IO) FinishProcessBar()

func (*IO) GetCurrentStream

func (io *IO) GetCurrentStream() io.Writer

func (*IO) GetOutputStream

func (io *IO) GetOutputStream() io.Writer

func (*IO) IncProcessBar

func (io *IO) IncProcessBar()

func (*IO) Info

func (io *IO) Info(msg string)

func (*IO) Infof

func (io *IO) Infof(format string, a ...any)

func (*IO) InputPassword

func (io *IO) InputPassword(msg string) (string, error)

func (*IO) IsBusy

func (io *IO) IsBusy() bool

func (*IO) LoadError

func (io *IO) LoadError(message string)

func (*IO) LoadErrorf

func (io *IO) LoadErrorf(format string, a ...interface{})

func (*IO) LoadFailed

func (io *IO) LoadFailed(message string)

func (*IO) LoadFailedf

func (io *IO) LoadFailedf(format string, a ...interface{})

func (*IO) LoadInfo

func (io *IO) LoadInfo(message string)

func (*IO) LoadInfof

func (io *IO) LoadInfof(format string, a ...interface{})

func (*IO) LoadStageSuccess

func (io *IO) LoadStageSuccess(message string)

func (*IO) LoadStageSuccessf

func (io *IO) LoadStageSuccessf(format string, a ...interface{})

func (*IO) LoadSuccess

func (io *IO) LoadSuccess(message string)

func (*IO) LoadSuccessf

func (io *IO) LoadSuccessf(format string, a ...interface{})

func (*IO) LoadWarning

func (io *IO) LoadWarning(message string)

func (*IO) LoadWarningf

func (io *IO) LoadWarningf(format string, a ...interface{})

func (*IO) NewSubIO

func (io *IO) NewSubIO() *IO

func (*IO) Print

func (io *IO) Print(msg string)

func (*IO) PrintTable

func (io *IO) PrintTable(header []string, data [][]string)

func (*IO) PrintTableWithTitle

func (io *IO) PrintTableWithTitle(title string, header []string, data [][]string)

func (*IO) PrintWithoutNewline

func (io *IO) PrintWithoutNewline(msg string)

func (*IO) Printf

func (io *IO) Printf(format string, a ...any)

func (*IO) PrintfWithoutNewline

func (io *IO) PrintfWithoutNewline(format string, a ...any)

func (*IO) SetSilenceMode

func (io *IO) SetSilenceMode(silence bool)

func (*IO) SetSkipConfirmMode

func (io *IO) SetSkipConfirmMode(skip bool)

func (*IO) SetVerboseMode

func (io *IO) SetVerboseMode(verbose bool)

func (*IO) StartLoading

func (io *IO) StartLoading(message string)

func (*IO) StartLoadingf

func (io *IO) StartLoadingf(format string, a ...interface{})

func (*IO) StartProcessBar

func (io *IO) StartProcessBar(message string)

func (*IO) StopLoading

func (io *IO) StopLoading()

func (*IO) Success

func (io *IO) Success(msg string)

func (*IO) Successf

func (io *IO) Successf(format string, a ...interface{})

func (*IO) UpdateLoading

func (io *IO) UpdateLoading(message string)

func (*IO) UpdateLoadingf

func (io *IO) UpdateLoadingf(format string, a ...interface{})

func (*IO) UpdateProcessBar

func (io *IO) UpdateProcessBar(i int)

func (*IO) Verbose

func (io *IO) Verbose(msg string)

func (*IO) Verbosef

func (io *IO) Verbosef(format string, a ...any)

func (*IO) Warn

func (io *IO) Warn(msg string)

func (*IO) Warnf

func (io *IO) Warnf(format string, a ...any)

type IOer

type IOer interface {
	Verbose(msg string)
	Verbosef(format string, a ...any)
	Print(msg string)
	Printf(format string, a ...any)
	Info(msg string)
	Infof(format string, a ...any)
	Warn(msg string)
	Warnf(format string, a ...any)
	Error(msg string)
	Errorf(format string, a ...any)
	Confirm(msg string) (bool, error)
	Confirmf(format string, a ...any) (bool, error)
	StartLoading(message string) *IO
	UpdateLoading(message string)
	StopLoading()
	StartProcessBar(message string)
	UpdateProcessBar(message string)
	IncProcessBar()
	StopProcessBar()
}

type LogSymbol

type LogSymbol struct {
	Symbol *FormattedText
}

type PbConfigForDag

type PbConfigForDag struct {
	Msg          string
	MaxStage     int
	CurrentStage int
	Writer       io.Writer
	// contains filtered or unexported fields
}

type ProcessBar

type ProcessBar struct {
	Animate
	// contains filtered or unexported fields
}

func (*ProcessBar) Exit

func (pb *ProcessBar) Exit() error

func (*ProcessBar) Finish

func (pb *ProcessBar) Finish() error

func (*ProcessBar) Increment

func (pb *ProcessBar) Increment() error

func (*ProcessBar) Set

func (pb *ProcessBar) Set(i int) error

func (*ProcessBar) Start

func (pb *ProcessBar) Start() error

type Spinner

type Spinner struct {
	Animate
	// contains filtered or unexported fields
}

func (*Spinner) LoadStageSuccess

func (s *Spinner) LoadStageSuccess(text string)

func (*Spinner) Start

func (s *Spinner) Start(prefix string)

func (*Spinner) Stop

func (s *Spinner) Stop()

func (*Spinner) Update

func (s *Spinner) Update(prefix string)

type SysStdin

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

func NewSysStdin

func NewSysStdin() *SysStdin

func (*SysStdin) IsTTY

func (s *SysStdin) IsTTY() bool

IsTTY checks if Stdin is a terminal.

func (*SysStdin) ReadLine

func (s *SysStdin) ReadLine(blocked bool) (string, error)

ReadLine reads a line from Stdin, potentially in a non-blocking manner.

func (*SysStdin) ReadLines

func (s *SysStdin) ReadLines(blocked bool) ([]string, error)

ReadLines reads all available lines, potentially in a non-blocking manner.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳