Package util contains utility functions.
camel_to_dashed.go ceildiv.go claim.go deepprint.go feed.go gethome.go getwd.go limits.go log.go multierror.go pprinter.go search.go strings.go subseq.go temp_env.go test_utils.go testdir.go util.go wcwidth.go
Limit values for uint and int.
NOTE: The math package contains similar constants for explicitly sized integer types, but lack those for uint and int.
ErrClaimFileBadPattern is thrown when the pattern argument passed to ClaimFile does not contain exactly one asterisk.
ErrIndexOutOfRange is returned when out-of-range errors occur.
ApplyDir creates the given files specified by ta directory layout to the current directory.
CamelToDashed converts a CamelCaseIdentifier to a dash-separated-identifier, or a camelCaseIdentifier to a -dash-separated-identifier.
CeilDiv computes ceil(float(a)/b) without using float arithmetics.
ClaimFile takes a directory and a pattern string containing exactly one asterisk (e.g. "a*.log"). It opens a file in that directory, with a filename matching the template, with "*" replaced by a number. That number is one plus the largest of all existing files matching the template. If no such file exists, "*" is replaced by 1. The file is opened for read and write, with permission 0666 (before umask).
For example, if the directory /tmp/elvish contains a1.log, a2.log and a9.log, calling ClaimFile("/tmp/elvish", "a*.log") will open a10.log. If the directory has no files matching the pattern, this same call will open a1.log.
This function is useful for automatically determining unique names for log files. Unique filenames can also be derived by embedding the PID, but using this function preserves the chronical order of the files.
This function is concurrency-safe: it always opens a new, unclaimed file and is not subject to race condition.
DeepPrint is like printing with the %#v formatter of fmt, but it prints pointer fields recursively.
DontSearch determines whether the path to an external command should be taken literally and not searched.
Errors concatenate multiple errors into one. If all errors are nil, it returns nil. If there is one non-nil error, it is returned. Otherwise the return value is a MultiError containing all the non-nil arguments. Arguments of the type MultiError are flattened.
Feed calls the function with given values, breaking earlier if the function returns false.
FindContext takes a position in a text and finds its line number, corresponding line and column numbers. Line and column numbers are counted from 0. Used in diagnostic messages.
FindFirstEOL returns the index of the first '\n'. When there is no '\n', the length of s is returned.
FindLastSOL returns an index just after the last '\n'.
ForceWcwidth forces the string s to the given display width by trimming and padding.
GetHome finds the home directory of a specified user. When given an empty string, it finds the home directory of the current user.
GetLogger gets a logger with a prefix.
Getwd returns path of the working directory in a format suitable as the prompt.
HasSubseq determines whether s has t as its subsequence. A string t is a subsequence of a string s if and only if there is a possible sequence of steps of deleting characters from s that result in t.
InTestDir is like TestDir, but also changes into the test directory, and the cleanup function also changes back to the original working directory.
It panics if it could not get the working directory or change directory. It is only suitable for use in tests.
InTestDirWithSetup sets up a temporary directory using the given cli. If wd is not empty, it also changes into the given subdirectory. It returns a cleanup function to remove the temporary directory and restore the working directory.
It panics if there are any errors.
IsExecutable determines whether path refers to an executable file.
MatchSubseq returns whether pattern is a subsequence of s.
NthRune returns the n-th rune of s.
OverrideWcwidth overrides the wcwidth of a rune to be a specific non-negative value. OverrideWcwidth panics if w < 0.
SetOutput redirects the output of all loggers obtained with GetLogger to the new io.Writer. If the old output was a file opened by SetOutputFile, it is closed.
SetOutputFile redirects the output of all loggers obtained with GetLogger to the named file. If the old output was a file opened by SetOutputFile, it is closed. The new file is truncated. SetOutFile("") is equivalent to SetOutput(ioutil.Discard).
SubstringByRune returns the range of the i-th rune (inclusive) through the j-th rune (exclusive) in s.
TestDir creates a temporary directory for testing. It returns the path of the temporary directory and a cleanup function to remove the temporary directory. The path has symlinks resolved with filepath.EvalSymlinks.
It panics if the test directory cannot be created or symlinks cannot be resolved. It is only suitable for use in tests.
TildeAbbr abbreviates the user's home directory to ~.
TrimEachLineWcwidth trims each line of s so that it is no wider than the specified width.
TrimWcwidth trims the string s so that it has a width of at most wmax.
UnoverrideWcwidth removes the override of a rune.
Wcswidth returns the width of a string when displayed on the terminal, assuming no soft line breaks.
Wcwidth returns the width of a rune when displayed on the terminal.
WithTempEnv sets an environment variable to a temporary value, and returns a function for restoring the old value.
Dir describes the layout of a directory. The keys of the map represent filenames. Each value is either a string (for the content of a regular file with permission 0644), a File, or a Dir.
File describes a file to create.
MultiError pack multiple errors into one error.
PPrinter wraps the PPrint function.