Documentation ¶
Overview ¶
Package console implements console printing helpers
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // DebugPrint enables/disables console debug printing. DebugPrint = false // Print prints a message. Print = func(data ...interface{}) { consolePrint("Print", Theme["Print"], data...) } // PrintC prints a message with color. PrintC = func(data ...interface{}) { consolePrint("PrintC", Theme["PrintC"], data...) } // Printf prints a formatted message. Printf = func(format string, data ...interface{}) { consolePrintf("Print", Theme["Print"], format, data...) } // Println prints a message with a newline. Println = func(data ...interface{}) { consolePrintln("Print", Theme["Print"], data...) } // Fatal print a error message and exit. Fatal = func(data ...interface{}) { consolePrint("Fatal", Theme["Fatal"], data...) os.Exit(1) } // Fatalf print a error message with a format specified and exit. Fatalf = func(format string, data ...interface{}) { consolePrintf("Fatal", Theme["Fatal"], format, data...) os.Exit(1) } // Fatalln print a error message with a new line and exit. Fatalln = func(data ...interface{}) { consolePrintln("Fatal", Theme["Fatal"], data...) os.Exit(1) } // Error prints a error message. Error = func(data ...interface{}) { consolePrint("Error", Theme["Error"], data...) } // Errorf print a error message with a format specified. Errorf = func(format string, data ...interface{}) { consolePrintf("Error", Theme["Error"], format, data...) } // Errorln prints a error message with a new line. Errorln = func(data ...interface{}) { consolePrintln("Error", Theme["Error"], data...) } // Info prints a informational message. Info = func(data ...interface{}) { consolePrint("Info", Theme["Info"], data...) } // Infof prints a informational message in custom format. Infof = func(format string, data ...interface{}) { consolePrintf("Info", Theme["Info"], format, data...) } // Infoln prints a informational message with a new line. Infoln = func(data ...interface{}) { consolePrintln("Info", Theme["Info"], data...) } // Debug prints a debug message without a new line // Debug prints a debug message. Debug = func(data ...interface{}) { if DebugPrint { consolePrint("Debug", Theme["Debug"], data...) } } // Debugf prints a debug message with a new line. Debugf = func(format string, data ...interface{}) { if DebugPrint { consolePrintf("Debug", Theme["Debug"], format, data...) } } // Debugln prints a debug message with a new line. Debugln = func(data ...interface{}) { if DebugPrint { consolePrintln("Debug", Theme["Debug"], data...) } } // Colorize prints message in a colorized form, dictated by the corresponding tag argument. Colorize = func(tag string, data interface{}) string { if isatty.IsTerminal(os.Stdout.Fd()) { colorized, ok := Theme[tag] if ok { return colorized.SprintFunc()(data) } } return fmt.Sprint(data) } // Eraseline Print in new line and adjust to top so that we don't print over the ongoing progress bar. Eraseline = func() { consolePrintf("Print", Theme["Print"], "%c[2K\n", 27) consolePrintf("Print", Theme["Print"], "%c[A", 27) } )
View Source
var ( // Theme contains default color mapping. Theme = map[string]*color.Color{ "Debug": color.New(color.FgWhite, color.Faint, color.Italic), "Fatal": color.New(color.FgRed, color.Italic, color.Bold), "Error": color.New(color.FgYellow, color.Italic), "Info": color.New(color.FgGreen, color.Bold), "Print": color.New(), "PrintB": color.New(color.FgBlue, color.Bold), "PrintC": color.New(color.FgGreen, color.Bold), } )
Functions ¶
func ProgramName ¶
func ProgramName() string
ProgramName - return the name of the executable program.
func RewindLines ¶
func RewindLines(n int)
RewindLines - uses terminal escape symbols to clear and rewind upwards on the console for `n` lines.
Types ¶
type Table ¶
type Table struct { // per-row colors RowColors []*color.Color // per-column align-right flag (aligns left by default) AlignRight []bool // Left margin width for table TableIndentWidth int }
Table - data to print in table format with fixed row widths.
func NewTable ¶
NewTable - create a new Table instance. Takes per-row colors and per-column right-align flags and table indentation width (i.e. left margin width)
func (*Table) DisplayTable ¶
DisplayTable - prints the table
Click to show internal directories.
Click to hide internal directories.