Documentation ¶
Overview ¶
Package utils provides common utility functions that are not reminder specific
Index ¶
- Variables
- func AskBoolean(msg string) (bool, error)
- func AskOption(options []string, label string) (int, string, error)
- func AssertEqual(t *testing.T, got interface{}, want interface{})
- func ChopStrings(texts []string, length int) []string
- func CurrentUnixTimestamp() int64
- func GenerateNoteSearchSelect(items []string, searchFunc func(filter string, value string, index int) bool) (int, error)
- func GeneratePrompt(promptName string, defaultText string) (string, error)
- func GetCommonMembersOfSlices[V comparable](list1 []V, list2 []V) []V
- func GetLocalZone() (string, time.Duration)
- func GetZoneFromLocation(loc string) (time.Duration, error)
- func IsMemberOfSlice[V comparable](a V, list []V) bool
- func LogError(err error)
- func MatchedTimestamp(...) (bool, int64)
- func PerformCat(filePath string) error
- func PerformCwdiff(oldFilePath string, newFilePath string) error
- func PerformFilePresence(filePath string) error
- func PerformShellOperation(exe string, args ...string) (string, error)
- func PerformWhich(shellCmd string) error
- func SkipCI(t *testing.T)
- func Spinner(delay time.Duration)
- func StrToTime(tString string, timezone string) (time.Time, error)
- func TemplateResult(reportTemplate string, funcMap template.FuncMap, data interface{}) (string, error)
- func TerminalWidth() (int, error)
- func TimeToStr(t time.Time) string
- func TryConvertTildaBasedPath(path string) string
- func UTCLocation() *time.Location
- func UnixTimestampForCorrespondingCurrentYear(month int, day int) int64
- func UnixTimestampForCorrespondingCurrentYearMonth(day int) int64
- func UnixTimestampToLongTimeStr(unixTimestamp int64) string
- func UnixTimestampToMediumTimeStr(unixTimestamp int64) string
- func UnixTimestampToShortTimeStr(unixTimestamp int64) string
- func UnixTimestampToTime(unixTimestamp int64) time.Time
- func UnixTimestampToTimeStr(unixTimestamp int64, timeFormat string) string
- func ValidateDateString() survey.Validator
- func YearForDueDateDDMM(dateMonth string) (int, error)
Constants ¶
This section is empty.
Variables ¶
var CurrentTime = func() time.Time { return time.Now() }
CurrentTime function gets current time. Note: It is deliberately defined as a variable to make it easer to patch in tests.
var HomeDir func() string = func() string { usr, _ := user.Current() dir := usr.HomeDir return dir }
HomeDir return the home directory path for current user. Note: It is deliberately defined as a variable to make it easer to patch in tests.
var Location *time.Location
Location variable provides location info for `time`. It can be set to update behavior of UnixTimestampToTime.
var Symbols = map[string]string{
"add": "➕",
"backup": "💾",
"calendar": "📅",
"checkerdFlag": "🏁",
"clip": "🔗",
"clock": "⏰",
"comment": "💬",
"done": "✅",
"downArrow": "⬇️",
"downVote": "👎",
"error": "❌",
"glossary": "📖",
"hat": "🎩",
"home": "⛺",
"noAction": "❎",
"pad": "📋",
"redFlag": "🚩",
"refresh": "🔄",
"search": "🔎",
"spark": "⚡",
"tag": "🏷t",
"telescope": "🔭",
"text": "📝",
"think": "🤔",
"upArrow": "⬆️",
"upVote": "👍",
"warning": "⚠️ ",
"zzz": "💤",
}
var TerminalSize = func() (int, int, error) { out, err := PerformShellOperation("stty", "size") if err != nil { return 0, 0, err } output := strings.TrimSpace(string(out)) dims := strings.Split(output, " ") height, _ := strconv.Atoi(dims[0]) width, _ := strconv.Atoi(dims[1]) return height, width, nil }
TerminalSize function gets terminal size. Note: It is deliberately defined as a variable to make it easer to patch in tests.
Functions ¶
func AskBoolean ¶ added in v1.9.27
AskBoolean asks a boolean question to the user.
func AskOption ¶
AskOption function asks option to the user. It print error, if encountered any (so that they don't have to printed by calling function). It return a tuple (chosen index, chosen string, err if any).
func AssertEqual ¶
AssertEqual function makes assertion that `go` and `want` are nearly equal.
func ChopStrings ¶
ChopStrings function returns a chopped strings (to a desired length).
func CurrentUnixTimestamp ¶
func CurrentUnixTimestamp() int64
CurrentUnixTimestamp function gets current unix timestamp.
func GenerateNoteSearchSelect ¶
func GenerateNoteSearchSelect(items []string, searchFunc func(filter string, value string, index int) bool) (int, error)
GenerateNoteSearchSelect function generates survey.Select and return index of selected option.
func GeneratePrompt ¶
GeneratePrompt function generates survey.Input.
func GetCommonMembersOfSlices ¶ added in v1.9.28
func GetCommonMembersOfSlices[V comparable](list1 []V, list2 []V) []V
GetCommonMembersOfSlices function gets common elements of slices.
func GetLocalZone ¶ added in v1.9.20
GetLocalZone returns the local timezone abbreviation and offset (in time.Duration).
func GetZoneFromLocation ¶ added in v1.9.20
GetZoneFromLocation returns zone offset (in time.Duration) for given location string like "Melbourne/Australia".
func IsMemberOfSlice ¶ added in v1.9.28
func IsMemberOfSlice[V comparable](a V, list []V) bool
IsMemberOf function performs membership test.
func LogError ¶ added in v1.9.13
func LogError(err error)
LogError function ignores but prints the error (if present).
func MatchedTimestamp ¶ added in v1.9.28
func MatchedTimestamp(noteTimestampCurrent, noteTimestampPrevious, noteTimestampNext, daysBefore, daysAfter int64) (bool, int64)
MatchedTimestamp function determines if currentTime matches with (within allowed daysBefore and daysAfter) given 3 timestamps (current, previous, and next). That is, it checks to see if any of the current timestamp falls in between [TIMESTAMP - DaysBefore, TIMESTAMP + DaysAfter]
func PerformCwdiff ¶
PerformCwdiff function gets colored wdiff between two files.
func PerformFilePresence ¶
PerformFilePresence function checks presence of a file.
func PerformShellOperation ¶
PerformShellOperation function performs shell operation and return its output. Note: it is better to avoid such functions.
func PerformWhich ¶
PerformWhich function checks if a shell command is available.
func StrToTime ¶ added in v1.9.16
StrToTime converts RFC3339 time sting to time.Time, and sets location to given timezone. If location is blank, then it returns the time as it is.
func TemplateResult ¶
func TemplateResult(reportTemplate string, funcMap template.FuncMap, data interface{}) (string, error)
TemplateResult function runs given go template with given data and function map, and return the result as string. It is interesting to note that even though data is recieved as `interface{}`, the template is able to access those attributes without even having to perform type assertion to get the underneath concrete value; this is contrary to masking behavior of interfaces.
func TryConvertTildaBasedPath ¶ added in v1.9.14
TryConvertTildaBasedPath converts tilda (~) based path to complete path. For a non-tilda based path, return as it is.
func UnixTimestampForCorrespondingCurrentYear ¶
UnixTimestampForCorrespondingCurrentYear function gets unix timestamp for date corresponding to current year.
func UnixTimestampForCorrespondingCurrentYearMonth ¶
UnixTimestampForCorrespondingCurrentYearMonth function gets unix timestamp for date corresponding to current year and current month.
func UnixTimestampToLongTimeStr ¶
UnixTimestampToLongTimeStr function converts unix timestamp to long time string.
func UnixTimestampToMediumTimeStr ¶
UnixTimestampToMediumTimeStr function converts unix timestamp to medium time string.
func UnixTimestampToShortTimeStr ¶
UnixTimestampToShortTimeStr function converts unix timestamp to short time string.
func UnixTimestampToTime ¶
UnixTimestampToTime function converts unix timestamp to time. It serves as central place to switch between UTC and local time. by default use local time, but behavior can be changed via `Location`. In either case, the value of the time (in seconds) remains same, the use of the Location just changes how time is displayed. For example, 5:30 PM in SGT is equivalent to 12 Noon in India.
func UnixTimestampToTimeStr ¶
UnixTimestampToTimeStr function converts unix timestamp to time string.
func ValidateDateString ¶
func ValidateDateString() survey.Validator
ValidateDateString function validates date string (DD-MM-YYYY) or (DD-MM). nil is also valid input
func YearForDueDateDDMM ¶
YearForDueDateDDMM return the current year if DD-MM is falling after current date, otherwise returns next year
Types ¶
This section is empty.