utils

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ColumnTask       string = "task"
	ColumnSummary    string = "summary"
	ColumnProject    string = "project"
	ColumnClient     string = "client"
	ColumnStart      string = "start"
	ColumnEnd        string = "end"
	ColumnBillable   string = "billable"
	ColumnUnbillable string = "unbillable"
)

Variables

Columns lists all available columns that can be printed.

HideableColumns lists all columns that can be hidden when printing.

Functions

func GetTime

func GetTime(rawDate string, dateFormat string) (time.Time, error)

GetTime parses a string based on the given format and returns the time. If the rawDate was an empty string, the today's midnight will return.

func IsSliceContains

func IsSliceContains(entry string, slice []string) bool

IsSliceContains checks if a string slice contains the given element or not.

func NewProgressWriter

func NewProgressWriter(updateFrequency time.Duration) progress.Writer

NewProgressWriter returns a pre-configured progress writer.

func ParseColumnConfigs

func ParseColumnConfigs(key string, hiddenColumns []string) []table.ColumnConfig

ParseColumnConfigs parses the column configs taken from the config file. The hidden columns can be defined as flags and column config as well. During parsing, the flag based columns will take precedence.

func Prompt

func Prompt(message string) string

Prompt shows the user a message and asks for input, then returns that.

func Truncate

func Truncate(text string, length int) string

Truncate chops the text at length and replaces the remaining with "...".

Types

type BasePrinterOpts

type BasePrinterOpts struct {
	// Output is the location where `Print` prints.
	Output io.Writer
	// AutoIndex adds row number as the first column.
	AutoIndex bool
	// Title sets the printed data's title.
	// In case of tables, the title is the full-width first row.
	Title string
	// SortBy sets the list of columns that are used for sorting.
	// If a column name starts with `-` (hyphen), the direction is descending;
	// otherwise, the direction is treated as ascending.
	SortBy []string
	// HiddenColumns lists the columns that will be hidden during printing.
	HiddenColumns []string
}

BasePrinterOpts represents the configuration for common printer options.

type Printer

type Printer interface {
	// Print prints out the list of complete and incomplete entries.
	// The output location must be set through `BasePrinterOpts`.
	Print(completeEntries worklog.Entries, incompleteEntries worklog.Entries) error
}

Printer represents a printer that can write worklog entries.

func NewTablePrinter

func NewTablePrinter(opts *TablePrinterOpts) Printer

NewTablePrinter returns a new Printer that print tables to os.Stdout.

type TableColumnConfig

type TableColumnConfig struct {
	Config     table.ColumnConfig
	TruncateAt int
}

TableColumnConfig represents the configuration of a column. The configuration is built up from two parts, `Config` which stands for the table column config and `TruncateAt` which defines the max length a column text; longer texts will be truncated.

type TablePrinterOpts

type TablePrinterOpts struct {
	BasePrinterOpts
	Style           table.Style
	ColumnConfig    []table.ColumnConfig
	ColumnTruncates map[string]int
}

TablePrinterOpts represents the configuration for a table base printer. Table based printer sends the output to os.Stdout and draws an ascii-based table.

Jump to

Keyboard shortcuts

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