Documentation ¶
Overview ¶
Simple package to get user input from terminal.
Index ¶
- Constants
- Variables
- func Aux(vars ...interface{})
- func Aux2(vars ...interface{})
- func Aux3(vars ...interface{})
- func Aux4(vars ...interface{})
- func BlockShutdown()
- func ConfirmDefault(prompt string, default_answer bool) bool
- func Debug(vars ...interface{})
- func Defer(closer interface{}) func() error
- func DisableExport(flag uint32)
- func EnableExport(flag uint32)
- func Err(vars ...interface{})
- func Exit(exit_code int)
- func Fatal(vars ...interface{})
- func Flash(vars ...interface{})
- func GetConfirm(prompt string) bool
- func GetFile(flag uint32) io.Writer
- func GetInput(prompt string) string
- func GetOutput(flag uint32) io.Writer
- func GetSecret(prompt string) string
- func HideTS(flag ...uint32)
- func HookSyslog(syslog_writer SyslogWriter)
- func HumanSize(bytes int64) string
- func Itoa(buf *[]byte, i int, wid int)
- func LTZ()
- func Log(vars ...interface{})
- func LogFile(filename string, max_size_mb uint, max_rotation uint) (io.Writer, error)
- func NeedAnswer(prompt string, request func(prompt string) string) (output string)
- func Notice(vars ...interface{})
- func PressEnter(prompt string)
- func SetFile(flag uint32, input io.Writer)
- func SetOutput(flag uint32, w io.Writer)
- func SetPrefix(logger uint32, prefix_str string)
- func SetSignals(sig ...os.Signal)
- func SetTZ(location string) (err error)
- func ShowTS(flag ...uint32)
- func ShutdownInProgress() bool
- func SignalCallback(signal os.Signal, callback func() (continue_shutdown bool))
- func Stderr(vars ...interface{})
- func Stdout(vars ...interface{})
- func Stringer(vars ...interface{}) string
- func Trace(vars ...interface{})
- func UTC()
- func UnblockShutdown()
- func UnhookSyslog()
- func Warn(vars ...interface{})
- type ProgressBar
- type ReadSeekCloser
- type SyslogWriter
Constants ¶
const ( INFO = 1 << iota // Log Information ERROR // Log Errors WARN // Log Warning NOTICE // Log Notices DEBUG // Debug Logging TRACE // Trace Logging FATAL // Fatal Logging AUX // Auxiliary Log AUX2 // Auxiliary Log AUX3 // Auxiliary Log AUX4 // Auxiliary Log )
const ( STD = INFO | ERROR | WARN | NOTICE | FATAL | AUX | AUX2 | AUX3 | AUX4 ALL = INFO | ERROR | WARN | NOTICE | FATAL | AUX | AUX2 | AUX3 | AUX4 | DEBUG | TRACE )
Standard Loggers, minus debug and trace.
const ( LeftToRight = 1 << iota // Display progress bar left to right. (Default Behavior) RightToLeft // Display progress bar right to left. NoRate // Do not show transfer rate, left to right. MaxWidth // Scale width to maximum. ProgressBarSummary // Maintain progress bar when transfer complete. NoSummary // Do not log a summary after completion. )
Variables ¶
var ( FatalOnFileError = true // Fatal on log file or file rotation errors. FatalOnExportError = true // Fatal on export/syslog error. Animations = true // Enable/Disable Flash Output )
var None dummyWriter
False writer for discarding output.
var PleaseWait = new(loading)
PleaseWait is a wait prompt to display between requests.
Functions ¶
func BlockShutdown ¶
func BlockShutdown()
Global wait group, allows running processes to finish up tasks before app shutdown
func ConfirmDefault ¶
Get confirmation w/ Default answer.
func Defer ¶
func Defer(closer interface{}) func() error
Adds a function to the global defer, function must take no arguments and either return nothing or return an error. Returns function to be called by local keyword defer if you want to run it now and remove it from global defer.
func Exit ¶
func Exit(exit_code int)
Intended to be a defer statement at the begining of main, but can be called at anytime with an exit code. Tries to catch a panic if possible and log it as a fatal error, then proceeds to send a signal to the global defer/shutdown handler
func Flash ¶
func Flash(vars ...interface{})
Don't log, write text to standard error which will be overwritten on the next output.
func Itoa ¶
Cheap integer to fixed-width decimal ASCII. Give a negative width to avoid zero-padding.
func LogFile ¶
Opens a new log file for writing, max_size is threshold for rotation, max_rotation is number of previous logs to hold on to. Set max_size_mb to 0 to disable file rotation.
func NeedAnswer ¶
Loop until a non-blank answer is given
func SignalCallback ¶
Set a callback function(no arguments) to run after receiving a specific syscall, function returns true to continue shutdown process.
Types ¶
type ProgressBar ¶
type ProgressBar interface { Add(num int) // Add num to progress bar. Set(num int) // Set num of progress bar. Done() // Mark progress bar as complete. }
func NewProgressBar ¶
func NewProgressBar(name string, max int) ProgressBar
Updates loading to be a progress bar.
type ReadSeekCloser ¶
type ReadSeekCloser interface { Seek(offset int64, whence int) (int64, error) Read(p []byte) (n int, err error) Close() error }
ReadSeekCloser interface
func NopSeeker ¶
func NopSeeker(input io.ReadCloser) ReadSeekCloser
Wrap around close and seek functions.
func TransferCounter ¶
func TransferCounter(input ReadSeekCloser, counter func(int)) ReadSeekCloser
TransferCounter allows you to add a counter callback function to add bytes added during read.
func TransferMonitor ¶
func TransferMonitor(name string, total_size int64, flag int, source ReadSeekCloser, optional_prefix ...string) ReadSeekCloser
Add Transfer to transferDisplay. Parameters are "name" displayed for file transfer, "limit_sz" for when to pause transfer (aka between calls/chunks), and "total_sz" the total size of the transfer.