Documentation
¶
Index ¶
- Constants
- Variables
- func Abs(n int) int
- func CharacterCount(b []byte) int
- func CharacterCountInString(str string) int
- func Clamp(val, min, max int) int
- func DecodeCharacter(b []byte) (rune, []rune, int)
- func DecodeCharacterInString(str string) (rune, []rune, int)
- func DetermineEscapePath(dir string, path string) (string, string)
- func EscapePathLegacy(path string) string
- func EscapePathUrl(path string) string
- func FSize(f *os.File) int64
- func GetCharPosInLine(b []byte, visualPos int, tabsize int) int
- func GetLeadingWhitespace(b []byte) []byte
- func GetMemStats() string
- func GetModTime(path string) (time.Time, error)
- func GetPathAndCursorPosition(path string) (string, []string)
- func GetTrailingWhitespace(b []byte) []byte
- func HasTrailingWhitespace(b []byte) bool
- func HashStringMd5(str string) string
- func HttpRequest(method string, url string, headers []string) (resp *http.Response, err error)
- func IndexAnyUnquoted(s, chars string) int
- func IntOpt(opt any) int
- func IsAlphanumeric(r rune) bool
- func IsAutocomplete(c rune) bool
- func IsBytesWhitespace(b []byte) bool
- func IsLowerAlphanumeric(r rune) bool
- func IsLowerLetter(r rune) bool
- func IsNonWordChar(r rune) bool
- func IsSpaces(str []byte) bool
- func IsSpacesOrTabs(str []byte) bool
- func IsSubwordDelimiter(r rune) bool
- func IsUpperAlphanumeric(r rune) bool
- func IsUpperLetter(r rune) bool
- func IsWhitespace(c rune) bool
- func IsWordChar(r rune) bool
- func LuaGetLeadingWhitespace(s string) string
- func LuaIsWordChar(s string) bool
- func LuaRuneAt(str string, runeidx int) string
- func MakeRelative(path, base string) (string, error)
- func Max(a, b int) int
- func Min(a, b int) int
- func ParseBool(str string) (bool, error)
- func ReplaceHome(path string) (string, error)
- func RunePos(b []byte, i int) int
- func SafeWrite(path string, bytes []byte, rename bool) error
- func SliceEnd(slc []byte, index int) []byte
- func SliceEndStr(str string, index int) string
- func SliceStart(slc []byte, index int) []byte
- func SliceStartStr(str string, index int) string
- func SliceVisualEnd(b []byte, n, tabsize int) ([]byte, int, int)
- func Spaces(n int) string
- func String(s []byte) string
- func StringWidth(b []byte, n, tabsize int) int
- func Tic(s string) time.Time
- func Toc(start time.Time)
- func Unzip(src, dest string) error
- type OverwriteError
Constants ¶
const BackupSuffix = ".micro-backup"
const FileMode os.FileMode = 0666
To be used for file writes before umask is applied
const OverwriteFailMsg = `` /* 262-byte string literal not displayed */
Variables ¶
var ( // Version is the version number or commit hash Version = "0.0.0-unknown" // SemVersion is the Semantic version SemVersion semver.Version // CommitHash is the commit this version was built on CommitHash = "Unknown" // CompileDate is the date this binary was compiled on CompileDate = "Unknown" // Debug logging Debug = "OFF" // FakeCursor is used to disable the terminal cursor and have micro // draw its own (enabled for windows consoles where the cursor is slow) FakeCursor = false // Stdout is a buffer that is written to stdout when micro closes Stdout *bytes.Buffer // Sigterm is a channel where micro exits when written Sigterm chan os.Signal // To be used for fails on (over-)write with safe writes ErrOverwrite = OverwriteError{} )
Functions ¶
func CharacterCount ¶
CharacterCount returns the number of characters in a byte array Similar to utf8.RuneCount but for unicode characters
func CharacterCountInString ¶
CharacterCount returns the number of characters in a string Similar to utf8.RuneCountInString but for unicode characters
func DecodeCharacter ¶
DecodeCharacter returns the next character from an array of bytes A character is a rune along with any accompanying combining runes
func DecodeCharacterInString ¶
DecodeCharacterInString returns the next character from a string A character is a rune along with any accompanying combining runes
func DetermineEscapePath ¶ added in v2.0.15
DetermineEscapePath escapes a path, determining whether it should be escaped using URL encoding (preferred, since it encodes unambiguously) or legacy encoding with '%' (for backward compatibility, if the legacy-escaped path exists in the given directory). In case the length of the escaped path (plus the backup extension) exceeds the filename length limit, a hash of the path is returned instead. In such case the second return value is the name of a file the original path should be saved to (since the original path cannot be derived from its hash). Otherwise the second return value is an empty string.
func EscapePathLegacy ¶ added in v2.0.15
EscapePathLegacy replaces every path separator in a given path with a %
func EscapePathUrl ¶ added in v2.0.15
EscapePathUrl encodes the path in URL query form
func GetCharPosInLine ¶
GetCharPosInLine gets the char position of a visual x y coordinate (this is necessary because tabs are 1 char but 4 visual spaces)
func GetLeadingWhitespace ¶
GetLeadingWhitespace returns the leading whitespace of the given byte array
func GetMemStats ¶
func GetMemStats() string
GetMemStats returns a string describing the memory usage and gc time used so far
func GetModTime ¶
GetModTime returns the last modification time for a given file
func GetPathAndCursorPosition ¶
GetPathAndCursorPosition returns a filename without everything following a `:` This is used for opening files like util.go:10:5 to specify a line and column Special cases like Windows Absolute path (C:\myfile.txt:10:5) are handled correctly.
func GetTrailingWhitespace ¶ added in v2.0.14
GetTrailingWhitespace returns the trailing whitespace of the given byte array
func HasTrailingWhitespace ¶ added in v2.0.14
HasTrailingWhitespace returns true if the given byte array ends with a whitespace
func HashStringMd5 ¶ added in v2.0.15
func HttpRequest ¶ added in v2.0.12
HttpRequest returns a new http.Client for making custom requests (for lua plugins)
func IndexAnyUnquoted ¶ added in v2.0.15
IndexAnyUnquoted returns the first position in s of a character from chars. Escaped (with backslash) and quoted (with single or double quotes) characters are ignored. Returns -1 if not successful
func IsAlphanumeric ¶ added in v2.0.14
IsAlphanumeric returns whether or not a rune is an 'alphanumeric character' Alphanumeric characters are defined as numbers or letters
func IsAutocomplete ¶ added in v2.0.5
IsAutocomplete returns whether a character should begin an autocompletion.
func IsBytesWhitespace ¶
IsBytesWhitespace returns true if the given bytes are all whitespace
func IsLowerAlphanumeric ¶ added in v2.0.14
IsLowerAlphanumeric returns whether or not a rune is a 'lower alphanumeric character' Lower alphanumeric characters are defined as numbers or lower-case letters
func IsLowerLetter ¶ added in v2.0.14
IsLowerLetter returns whether or not a rune is a 'lower letter character' Lower letter characters are defined as lower-case letters
func IsNonWordChar ¶ added in v2.0.14
IsNonWordChar returns whether or not a rune is not a 'word character' Non word characters are defined as all characters not being numbers, letters or sub-word delimiters See IsWordChar()
func IsSpacesOrTabs ¶
IsSpacesOrTabs checks if a given string contains only spaces and tabs
func IsSubwordDelimiter ¶ added in v2.0.14
IsSubwordDelimiter returns whether or not a rune is a 'sub-word delimiter character' i.e. is considered a part of the word and is used as a delimiter between sub-words of the word. For now the only sub-word delimiter character is '_'.
func IsUpperAlphanumeric ¶ added in v2.0.14
IsUpperAlphanumeric returns whether or not a rune is an 'upper alphanumeric character' Upper alphanumeric characters are defined as numbers or upper-case letters
func IsUpperLetter ¶ added in v2.0.14
IsUpperLetter returns whether or not a rune is an 'upper letter character' Upper letter characters are defined as upper-case letters
func IsWhitespace ¶
IsWhitespace returns true if the given rune is a space, tab, or newline
func IsWordChar ¶
IsWordChar returns whether or not a rune is a 'word character' Word characters are defined as numbers, letters or sub-word delimiters
func LuaGetLeadingWhitespace ¶
LuaGetLeadingWhitespace returns the leading whitespace of a string (used by lua plugins)
func LuaIsWordChar ¶
LuaIsWordChar returns true if the first rune in a string is a word character
func LuaRuneAt ¶
LuaRuneAt is a helper function for lua plugins to return the rune at an index within a string
func MakeRelative ¶
MakeRelative will attempt to make a relative path between path and base
func ParseBool ¶
ParseBool is almost exactly like strconv.ParseBool, except it also accepts 'on' and 'off' as 'true' and 'false' respectively
func ReplaceHome ¶
ReplaceHome takes a path as input and replaces ~ at the start of the path with the user's home directory. Does nothing if the path does not start with '~'.
func RunePos ¶
RunePos returns the rune index of a given byte index Make sure the byte index is not between code points
func SafeWrite ¶ added in v2.0.15
SafeWrite writes bytes to a file in a "safe" way, preventing loss of the contents of the file if it fails to write the new contents. This means that the file is not overwritten directly but by writing to a temporary file first.
If rename is true, write is performed atomically, by renaming the temporary file to the target file after the data is successfully written to the temporary file. This guarantees that the file will not remain in a corrupted state, but it also has limitations, e.g. the file should not be a symlink (otherwise SafeWrite silently replaces this symlink with a regular file), the file creation date in Linux is not preserved (since the file inode changes) etc. Use SafeWrite with rename=true for files that are only created and used by micro for its own needs and are not supposed to be used directly by the user.
If rename is false, write is performed by overwriting the target file after the data is successfully written to the temporary file. This means that the target file may remain corrupted if overwrite fails, but in such case the temporary file is preserved as a backup so the file can be recovered later. So it is less convenient than atomic write but more universal. Use SafeWrite with rename=false for files that may be managed directly by the user, like settings.json and bindings.json.
func SliceEnd ¶
SliceEnd returns a byte slice where the index is a rune index Slices off the start of the slice
func SliceEndStr ¶
SliceEndStr is the same as SliceEnd but for strings
func SliceStart ¶
SliceStart returns a byte slice where the index is a rune index Slices off the end of the slice
func SliceStartStr ¶
SliceStartStr is the same as SliceStart but for strings
func SliceVisualEnd ¶
SliceVisualEnd will take a byte slice and slice off the start up to a given visual index. If the index is in the middle of a rune the number of visual columns into the rune will be returned It will also return the char pos of the first character of the slice
func StringWidth ¶
StringWidth returns the visual width of a byte array indexed from 0 to n (rune index) with a given tabsize
Types ¶
type OverwriteError ¶ added in v2.0.15
OverwriteError is a custom error to add additional information
func (OverwriteError) Error ¶ added in v2.0.15
func (e OverwriteError) Error() string
func (OverwriteError) Is ¶ added in v2.0.15
func (e OverwriteError) Is(target error) bool
func (OverwriteError) Unwrap ¶ added in v2.0.15
func (e OverwriteError) Unwrap() error