Documentation ¶
Overview ¶
Package stdres provides the means to select colors for STDOUT based on action results. By using this package you are able to print text to the buffer, and postpone the color selection until action has finished.
Typical scenario: The tool decides what to do, and the tool informs the user what's going to happen. The tool starts to run the command and print more information. During execution of the action, the tool fails and sets the result to failure.
Before the tool starts to exuecute the next action, it calls method Buffer.Flush and the existing records and flushed in corresponding colors, in this case red text due to failure.
Example ¶
package main import ( "github.com/dekelund/stdres" ) func main() { var buffer stdres.Buffer buffer = stdres.Buffer{} firstAction := buffer.Println("Executing first action") secondAction := buffer.Println("Executing second action") thirdAction := buffer.Println("Executing third action") fourthAction := buffer.Printf("Executing fourth action, printed with number one - %d\n", 1) buffer.Print("Executing fifth action") // Never updated, printed with UNKNOWN state which result in Cyan color firstAction.Result = stdres.SUCCESS // First action succeeded, line printed in green secondAction.Result = stdres.FAILURE // Second action failed, line printed in red thirdAction.Result = stdres.INFO // Third action was just information, line printed in blue fourthAction.Result = stdres.PLAIN // Fourth action printed with white text stdres.DisableColor() // Use this method to remove color output buffer.Flush() // Only print if and when we flush, update result before flush. }
Output: Executing first action Executing second action Executing third action Executing fourth action, printed with number one - 1 Executing fifth action
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DisableColor ¶
func DisableColor()
func EnableColor ¶
func EnableColor()
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
func (*Buffer) Flush ¶
func (outBuffer *Buffer) Flush()
Flash iterates through all records in Buffer and flush it to stdout preceded by color matching current status. Each record will be followed by color reset if it was preceded by a color.
func (*Buffer) Print ¶
Println records message to buffer to be printed later. Text not printed until Buffer.Flush has been called. It returns current status and text string as Record.
Notes ¶
Bugs ¶
Current version is not thread-safe