Documentation ¶
Index ¶
- Constants
- Variables
- func Aggregate[T Named, V any](t *MapTree[T], values map[string]V, zero V, fn func(a, b V) V)
- func CreateDir(path string) error
- func Date(year int, month time.Month, day int) time.Time
- func DateAndTime(d, t time.Time) time.Time
- func DateTime(year int, month time.Month, day, hours, minutes, seconds int) time.Time
- func DirExists(path string) bool
- func DirIsEmpty(path string) (bool, error)
- func DurationClip(start, end, min, max time.Time) time.Duration
- func EditFile(path string, editor string) error
- func FileExists(path string) bool
- func FindLatests(path string, isDir bool) (string, string, error)
- func FloatToBlock(value float64, space *rune) rune
- func Format(str string, repl map[string]string) string
- func FormatCmdTree(command *cobra.Command) (string, error)
- func FormatDuration(d time.Duration, zeroPadHours ...bool) string
- func FormatTimeWithOffset(t time.Time, reference time.Time) string
- func Monday(date time.Time) time.Time
- func ParseDate(text string) (time.Time, error)
- func ParseDateTime(text string) (time.Time, error)
- func ParseTimeRange(text string, date time.Time) (start, end time.Time, err error)
- func ParseTimeWithOffset(text string, date time.Time) (time.Time, error)
- func Reverse[S ~[]E, E any](s S)
- func Sanitize(file string) string
- func TerminalSize() (width int, height int, err error)
- func ToDate(t time.Time) time.Time
- func Unique[T comparable](slice []T) []T
- func WrappedArgs(fn cobra.PositionalArgs) cobra.PositionalArgs
- type CmdNode
- type CmdTree
- type CmdWrapper
- type MapNode
- type MapTree
- type Named
- type Pair
- type TreeFormatter
Constants ¶
const ( // DateFormat for date formatting DateFormat = "2006-01-02" // TimeFormat for time formatting TimeFormat = "15:04" // FileTimeFormat for file name time formatting FileTimeFormat = "15-04" // FileDateTimeFormat for date and time from paths FileDateTimeFormat = "2006-01-02 15-04" // DateTimeFormat for date and time formatting DateTimeFormat = "2006-01-02 15:04" // NoTimeString string representation for zero end time NoTimeString = " now " )
const ( // PrevDayPrefix is a prefix for a time on the previous day PrevDayPrefix = "<" // NextDaySuffix is a suffix for a time on the next day NextDaySuffix = ">" )
Variables ¶
var BlockRunes = [9]rune{'·', 9601, 9602, 9603, 9604, 9605, 9606, 9607, 9608}
BlockRunes are utf8 8th blocks from empty to full
var ( // ErrNoFiles is an error for no files found at all ErrNoFiles = errors.New("no files") )
var NoTime time.Time = time.Time{}
NoTime is a zero time
var SkipEditingForTests = false
SkipEditingForTests makes editing just fall through, for unit testing
Functions ¶
func DateAndTime ¶ added in v0.3.0
DateAndTime combines a date with a time
func DirIsEmpty ¶ added in v0.3.6
DirIsEmpty checks if a directory is empty
func DurationClip ¶ added in v0.3.0
DurationClip calculated the duration a time span, clipped by another time span
func EditFile ¶ added in v0.3.6
EditFile opens a file in the default editor and waits for the process to finish
func FileExists ¶ added in v0.3.6
FileExists checks if a file exists
func FindLatests ¶ added in v0.3.6
FindLatests finds the "latest" file or directory in a file, by name
func FloatToBlock ¶ added in v0.2.0
FloatToBlock returns utf8 8th blocks for values between 0 and 1
func Format ¶
Format formats a string with named placeholders.
Example: s := Format("foo {name} bar", map[string]string{"name": "baz"})
func FormatCmdTree ¶
FormatCmdTree creates a tree-like representation of a command and its sub-commands
func FormatDuration ¶
FormatDuration formats a duration
func FormatTimeWithOffset ¶ added in v0.3.0
FormatTimeWithOffset formats a time with day offset indicators
func ParseDateTime ¶
ParseDateTime parses a datetime string. Assumes the local time zone.
func ParseTimeRange ¶ added in v0.3.0
ParseTimeRange parses a time range string. Assumes the local time zone.
func ParseTimeWithOffset ¶ added in v0.3.0
ParseTimeWithOffset parses a time with offset markers
func TerminalSize ¶ added in v0.2.0
TerminalSize returns the size of the terminal
func Unique ¶ added in v0.3.5
func Unique[T comparable](slice []T) []T
Unique returns a slice with only unique elements of the original slice
func WrappedArgs ¶
func WrappedArgs(fn cobra.PositionalArgs) cobra.PositionalArgs
WrappedArgs are PositionalArgs that print usage on error
Types ¶
type CmdWrapper ¶ added in v0.3.3
CmdWrapper wraps *cobra.Command to implement the Named interface
func (CmdWrapper) GetName ¶ added in v0.3.3
func (cmd CmdWrapper) GetName() string
GetName implements the Named interface required for the MapTree
type MapTree ¶ added in v0.3.6
MapTree is a tree data structure
type Named ¶ added in v0.3.6
type Named interface {
GetName() string
}
Named is an interface for stuff that has a name
type TreeFormatter ¶
type TreeFormatter[T Named] struct { NameFunc func(t *MapNode[T], indent int) string Indent int // contains filtered or unexported fields }
TreeFormatter formats trees
func NewTreeFormatter ¶
func NewTreeFormatter[T Named]( nameFunc func(t *MapNode[T], indent int) string, indent int, ) TreeFormatter[T]
NewTreeFormatter creates a new TreeFormatter
func (*TreeFormatter[T]) FormatTree ¶
func (f *TreeFormatter[T]) FormatTree(t *MapTree[T]) string
FormatTree formats a tree