micro: github.com/zyedidia/micro/internal/util Index | Files

package util

import "github.com/zyedidia/micro/internal/util"


Package Files

lua.go profile.go util.go


var (

    // Version is the version number or commit hash
    Version = "0.0.0-unknown"
    // 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 = "ON"
    // 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

func Abs Uses

func Abs(n int) int

Abs is a simple absolute value function for ints

func Clamp Uses

func Clamp(val, min, max int) int

Clamp clamps a value between min and max

func EscapePath Uses

func EscapePath(path string) string

EscapePath replaces every path separator in a given path with a %

func FSize Uses

func FSize(f *os.File) int64

FSize gets the size of a file

func GetCharPosInLine Uses

func GetCharPosInLine(b []byte, visualPos int, tabsize int) int

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 Uses

func GetLeadingWhitespace(b []byte) []byte

GetLeadingWhitespace returns the leading whitespace of the given byte array

func GetMemStats Uses

func GetMemStats() string

GetMemStats returns a string describing the memory usage and gc time used so far

func GetModTime Uses

func GetModTime(path string) (time.Time, error)

GetModTime returns the last modification time for a given file

func GetPathAndCursorPosition Uses

func GetPathAndCursorPosition(path string) (string, []string)

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 IntOpt Uses

func IntOpt(opt interface{}) int

IntOpt turns a float64 setting to an int

func IsBytesWhitespace Uses

func IsBytesWhitespace(b []byte) bool

IsBytesWhitespace returns true if the given bytes are all whitespace

func IsNonAlphaNumeric Uses

func IsNonAlphaNumeric(c rune) bool

func IsSpaces Uses

func IsSpaces(str []byte) bool

IsSpaces checks if a given string is only spaces

func IsSpacesOrTabs Uses

func IsSpacesOrTabs(str []byte) bool

IsSpacesOrTabs checks if a given string contains only spaces and tabs

func IsWhitespace Uses

func IsWhitespace(c rune) bool

IsWhitespace returns true if the given rune is a space, tab, or newline

func IsWordChar Uses

func IsWordChar(r rune) bool

IsWordChar returns whether or not the string is a 'word character' Word characters are defined as numbers, letters, or '_'

func LuaGetLeadingWhitespace Uses

func LuaGetLeadingWhitespace(s string) string

LuaGetLeadingWhitespace returns the leading whitespace of a string (used by lua plugins)

func LuaIsWordChar Uses

func LuaIsWordChar(s string) bool

LuaIsWordChar returns true if the first rune in a string is a word character

func LuaRuneAt Uses

func LuaRuneAt(str string, runeidx int) string

LuaRuneAt is a helper function for lua plugins to return the rune at an index within a string

func MakeRelative Uses

func MakeRelative(path, base string) (string, error)

MakeRelative will attempt to make a relative path between path and base

func Max Uses

func Max(a, b int) int

Max takes the max of two ints

func Min Uses

func Min(a, b int) int

Min takes the min of two ints

func ParseBool Uses

func ParseBool(str string) (bool, error)

ParseBool is almost exactly like strconv.ParseBool, except it also accepts 'on' and 'off' as 'true' and 'false' respectively

func ParseSpecial Uses

func ParseSpecial(s string) string

func ReplaceHome Uses

func ReplaceHome(path string) (string, error)

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 Uses

func RunePos(b []byte, i int) int

RunePos returns the rune index of a given byte index Make sure the byte index is not between code points

func SliceEnd Uses

func SliceEnd(slc []byte, index int) []byte

SliceEnd returns a byte slice where the index is a rune index Slices off the start of the slice

func SliceEndStr Uses

func SliceEndStr(str string, index int) string

SliceEndStr is the same as SliceEnd but for strings

func SliceStart Uses

func SliceStart(slc []byte, index int) []byte

SliceStart returns a byte slice where the index is a rune index Slices off the end of the slice

func SliceStartStr Uses

func SliceStartStr(str string, index int) string

SliceStartStr is the same as SliceStart but for strings

func SliceVisualEnd Uses

func SliceVisualEnd(b []byte, n, tabsize int) ([]byte, int, int)

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 Spaces Uses

func Spaces(n int) string

Spaces returns a string with n spaces

func String Uses

func String(s []byte) string

String converts a byte array to a string (for lua plugins)

func StringWidth Uses

func StringWidth(b []byte, n, tabsize int) int

StringWidth returns the visual width of a byte array indexed from 0 to n (rune index) with a given tabsize

func Tic Uses

func Tic(s string) time.Time

func Toc Uses

func Toc(start time.Time)

Package util imports 16 packages (graph) and is imported by 6 packages. Updated 2020-02-14. Refresh now. Tools for package owners.