display

package
v1.1.10 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2021 License: MPL-2.0 Imports: 16 Imported by: 16

Documentation

Overview

Package display implements functions for displaying output to users.

Index

Constants

This section is empty.

Variables

View Source
var TestHandler log.Handler

TestHandler collects log entries during testing.

Functions

func ClearProgress

func ClearProgress()

ClearProgress stops a progress spinner.

func File

func File() string

File returns the log file name.

func Handler

func Handler(entry *log.Entry) error

Handler handles log entries. It multiplexes them into two outputs, writing human-readable messages to STDERR and machine-readable entries to a log file.

TODO: does this need to be synchronised?

func InProgress

func InProgress(message string)

InProgress shows a progress spinner with a message.

func JSON

func JSON(data interface{}) (int, error)

JSON is a convenience function for printing JSON to STDOUT.

func SetDebug

func SetDebug(debug bool, setVerbose bool)

SetDebug turns debug logging to STDERR on or off.

The log file always writes debug-level entries.

func SetFile

func SetFile(filename string) error

SetFile sets the log file. By default, this is set to a temporary file.

func SetInteractive

func SetInteractive(interactive bool)

SetInteractive turns colors and ANSI control characters on or off.

func SyncFile added in v1.0.10

func SyncFile() error

SyncFile syncs the FOSSA log file and writes all progress to disk.

func Template

func Template(tmpl *template.Template, data interface{}) (string, error)

Template renders a template and its context to a string.

func TemplateFile

func TemplateFile(filename string, data interface{}) (string, error)

TemplateFile renders a template file and its context to string.

func TemplateFormatTabs added in v0.7.27

func TemplateFormatTabs(tmpl string, data interface{}, minWidth, tabWidth, padding int) (string, error)

TemplateFormatTabs renders a template with the desired tab format.

func TemplateString added in v0.7.27

func TemplateString(templateString string, data interface{}) (string, error)

TemplateString renders a template from a string template.

func Test

func Test()

Test sets up logging with testing defaults.

Types

type Display added in v1.0.5

type Display interface {
	// Start a new process and start tracking its progress
	// `StartProcess("nodejs")`
	// -> [] nodejs
	StartProcess(processName string) ProgressTracker
	// Stop the progress display. All future updates from processes will be ignored
	Stop()
}

A Display provides progress indicators for running "processes".

Running "process" indicators are joined by spaces, e.g., [] nodejs(Discovery) golang(Analysis 1/5)

See ProgressTracker for examples

func StartDisplay added in v1.0.5

func StartDisplay() Display

type ProgressTracker added in v1.0.5

type ProgressTracker interface {
	// Begin a new step in this process
	// Clears the current count of Completed and Tasks
	Begin(stepName string)
	// Update the number of completed actions
	// When called before `AddTasks`, the count of tasks will display as "?"
	AddCompleted(n int)
	// Update the number of tasks that need to be run
	// When called before `AddCompleted`, the count of completed will display as "0"
	AddTasks(n int)
	// End the progress tracker for this process
	//
	// NOTE: When reusing the same ProgressTracker, be sure to call `Begin`
	End()
}

A ProgressTracker is created by calling `Display.StartProcess(processName string)`

A ProgressTracker is used to show the current step and progress for a given"process" Examples below are using `Display.StartProcess("nodejs")`

`Begin("Discovery")` -> [] nodejs(Discovery)

`Begin("Discovery")` `AddCompleted(5)` -> [] nodejs(Discovery 5/?)

`Begin("Analysis")` `AddTasks(5)` -> [] nodejs(Analysis 0/5) `AddCompleted(1)` -> [] nodejs(Analysis 1/5)

`End()` -> []

NOTE: only the `AddCompleted` and `AddTasks` functions are safe to be called concurrently.

Jump to

Keyboard shortcuts

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