Documentation
¶
Overview ¶
Package bytefmt contains helper methods and constants for converting to and from a human-readable byte format.
bytefmt.ByteSize(100.5*bytefmt.MEGABYTE) // "100.5M" bytefmt.ByteSize(uint64(1024)) // "1K" invoked from code.cloudfoundry.org/bytefmt
Index ¶
- Constants
- Variables
- func ByteSize(bytes uint64) string
- func DateString(date time.Time) (sdate string)
- func DefaultNoColor()
- func FileLSColorString(fullpath, s string) (string, error)
- func GetColorizePermission(mode os.FileMode) string
- func GetColorizedDirName(path string, root string) string
- func GetColorizedSize(size uint64) (csize string)
- func GetColorizedTime(date time.Time) string
- func GetFileLSColor(file *File) *color.Color
- func KindEXAColorString(kind, s string) string
- func KindLSColorString(kind, s string) string
- func NewEXAColor(key string) *color.Color
- func NewFileListFilter(fl *FileList, filters []Filter) *fileListFilter
- func NewLSColor(key string) *color.Color
- func SetNoColor()
- func ToBytes(s string) (uint64, error)
- func ToMegabytes(s string) (uint64, error)
- type ByLowerString
- type DirsBy
- type EdgeType
- type Field
- func (f *Field) ColorHeadString() string
- func (f *Field) ColorValueString() string
- func (f *Field) GetHeadColor(c *color.Color) *color.Color
- func (f *Field) GetValueColor(c *color.Color) *color.Color
- func (f *Field) HeadString() string
- func (f *Field) SetColorfulValue(value interface{})
- func (f *Field) SetHeadColor(c *color.Color)
- func (f *Field) SetValue(value interface{})
- func (f *Field) SetValueColor(c *color.Color)
- func (f *Field) ValueString() string
- type FieldSlice
- func (f *FieldSlice) Add(field *Field)
- func (f *FieldSlice) ColorHeads() []string
- func (f *FieldSlice) ColorHeadsString() string
- func (f *FieldSlice) ColorMetaValues() []string
- func (f *FieldSlice) ColorMetaValuesString() string
- func (f *FieldSlice) ColorValues() []string
- func (f *FieldSlice) Colors() []*color.Color
- func (f *FieldSlice) Count() int
- func (f *FieldSlice) Fields() []*Field
- func (f *FieldSlice) Get(key PDFieldFlag) *Field
- func (f *FieldSlice) GetByName(name string) *Field
- func (f *FieldSlice) HeadAligns() []paw.Align
- func (f *FieldSlice) HeadWidths() []int
- func (f *FieldSlice) Heads() []string
- func (f *FieldSlice) HeadsString() string
- func (f *FieldSlice) HeadsStringWidth() int
- func (f *FieldSlice) Insert(startIndex int, fds ...*Field)
- func (f *FieldSlice) MetaHeadsStringWidth() int
- func (f *FieldSlice) MetaValues() []string
- func (f *FieldSlice) MetaValuesString() string
- func (f *FieldSlice) MetaValuesStringWidth() int
- func (f *FieldSlice) Remove(key PDFieldFlag)
- func (f *FieldSlice) RemoveByName(name string)
- func (f *FieldSlice) SetColorfulValues(file *File, git GitStatus)
- func (f *FieldSlice) SetValues(file *File, git GitStatus)
- func (f *FieldSlice) Values() []interface{}
- func (f *FieldSlice) ValuesString() []string
- type File
- func (f *File) AccessedTime() time.Time
- func (f *File) BaseNameToLink() string
- func (f *File) Blocks() uint64
- func (f *File) ColorAccessedTime() string
- func (f *File) ColorBaseName() string
- func (f *File) ColorBaseNameToLink() string
- func (f *File) ColorCreatedTime() string
- func (f *File) ColorDirName(root string) string
- func (f *File) ColorGitStatus(git GitStatus) string
- func (f *File) ColorLinkPath() string
- func (f *File) ColorMeta(git GitStatus) (string, int)
- func (f *File) ColorModifyTime() string
- func (f File) ColorName() string
- func (f *File) ColorPermission() string
- func (f *File) ColorSize() string
- func (f *File) CreatedTime() time.Time
- func (f *File) DirSlice() []string
- func (f *File) INode() uint64
- func (f *File) IsChardev() bool
- func (f *File) IsDev() bool
- func (f *File) IsDir() bool
- func (f *File) IsFiFo() bool
- func (f *File) IsFile() bool
- func (f *File) IsLink() bool
- func (f *File) IsNotIdentify() bool
- func (f *File) IsSocket() bool
- func (f *File) LSColorString(s string) string
- func (f *File) LinkPath() string
- func (f *File) ModifiedTime() time.Time
- func (f *File) NLinks() uint64
- func (f File) Name() string
- func (f *File) PathSlice() []string
- func (f *File) Permission() string
- func (f File) String() string
- func (f *File) TypeString() string
- type FileList
- func (f *FileList) AddFile(file *File)
- func (f *FileList) DirInfo(file *File) (cdinf string, wdinf int)
- func (f *FileList) Dirs() []string
- func (f *FileList) DisableColor()
- func (f *FileList) Dump() string
- func (f *FileList) EnableColor()
- func (f *FileList) FindFiles(depth int, ignore IgnoreFunc) error
- func (f *FileList) GetGitStatus() GitStatus
- func (f *FileList) GetHead4Meta(pad, username, groupname string, git GitStatus) (chead string, width int)
- func (f *FileList) Map() FileMap
- func (f *FileList) NDirs() int
- func (f *FileList) NFiles() int
- func (f *FileList) NSubDirsAndFiles(dir string) (ndirs, nfiles int)
- func (f *FileList) ResetStringBuilder()
- func (f *FileList) ResetWriters()
- func (f *FileList) Root() string
- func (f *FileList) SetDirsSorter(by DirsBy)
- func (f *FileList) SetFilesSorter(by FilesBy)
- func (f *FileList) SetWriters(writers ...io.Writer)
- func (f *FileList) Sort()
- func (f *FileList) SortBy(dirsBy DirsBy, filesBy FilesBy)
- func (f FileList) String() string
- func (f *FileList) StringBuilder() *strings.Builder
- func (f *FileList) ToClassifyView(pad string) string
- func (f *FileList) ToClassifyViewString(pad string) string
- func (f *FileList) ToLevelExtendViewBytes(pad string) []byte
- func (f *FileList) ToLevelView(pad string, isExtended bool) string
- func (f *FileList) ToLevelViewBytes(pad string) []byte
- func (f *FileList) ToListExtendView(pad string) string
- func (f *FileList) ToListExtendViewBytes(pad string) []byte
- func (f *FileList) ToListTreeExtendView(pad string) string
- func (f *FileList) ToListTreeExtendViewBytes(pad string) []byte
- func (f *FileList) ToListTreeView(pad string) string
- func (f *FileList) ToListTreeViewBytes(pad string) []byte
- func (f *FileList) ToListView(pad string) string
- func (f *FileList) ToListViewBytes(pad string) []byte
- func (f *FileList) ToTableExtendViewBytes(pad string) []byte
- func (f *FileList) ToTableView(pad string, isExtended bool) string
- func (f *FileList) ToTableViewBytes(pad string) []byte
- func (f *FileList) ToTreeExtendView(pad string) string
- func (f *FileList) ToTreeExtendViewBytes(pad string) []byte
- func (f *FileList) ToTreeView(pad string) string
- func (f *FileList) ToTreeViewBytes(pad string) []byte
- func (f *FileList) Writer() io.Writer
- type FileMap
- type FilesBy
- type Filter
- type GitStatus
- type IgnoreFunc
- type PDFieldFlag
- type PDFiltFlag
- type PDFilterOption
- type PDSortFlag
- type PDSortOption
- type PDViewFlag
- type PrintDirOption
- type XY
Constants ¶
const ( BYTE = 1 << (10 * iota) KILOBYTE MEGABYTE GIGABYTE TERABYTE PETABYTE EXABYTE )
const ( // PathSeparator is OS-specific path separator ('/') PathSeparator = string(os.PathSeparator) // PathListSeparator is OS-specific path list separator (':') PathListSeparator = string(os.PathListSeparator) )
const ( // RootMark = "." RootMark = "." UpDirMark = ".." )
const ( PDSort PDSortFlag = 1 << iota PDSortReverse PDSortByName = PDSort | pdSortKeyName PDSortByMtime = PDSort | pdSortKeyMTime PDSortBySize = PDSort | pdSortKeySize PDSortByReverseName = PDSortByName | PDSortReverse PDSortByReverseMtime = PDSortByMtime | PDSortReverse PDSortByReverseSize = PDSortBySize | PDSortReverse )
const ( PDFiltNoEmptyDir = 1 << iota PDFiltJustDirs PDFiltJustFiles PDFiltJustDirsButNoEmpty = PDFiltNoEmptyDir | PDFiltJustDirs PDFiltJustFilesButNoEmptyDir = PDFiltJustFiles )
Variables ¶
var ( DefaultFilesBy FilesBy = func(fi *File, fj *File) bool { if fi.IsDir() && fj.IsFile() { return true } else if fi.IsFile() && fj.IsDir() { return false } return paw.ToLower(fi.Path) < paw.ToLower(fj.Path) } DefaultDirsBy DirsBy = func(di string, dj string) bool { return paw.ToLower(di) < paw.ToLower(dj) } )
var ( // NoColor check from the type of terminal and // determine output to terminal in color (`true`) or not (`false`) NoColor = os.Getenv("TERM") == "dumb" || !(isatty.IsTerminal(os.Stdout.Fd()) || isatty.IsCygwinTerminal(os.Stdout.Fd())) // LSColorsFileKindDesc ... LSColorsFileKindDesc = map[string]string{ "di": "directory", "fi": "file", "ln": "symbolic link", "pi": "fifo file", "so": "socket file", "bd": "block (buffered) special file", "cd": "character (unbuffered) special file", "or": "symbolic link pointing to a non-existent file (orphan)", "mi": "non-existent file pointed to by a symbolic link (visible when you type ls -l)", "ex": "file which is executable (ie. has 'x' set in permissions)", } EXAColors = map[string][]color.Attribute{ "fi": LSColors["fi"], "di": LSColors["di"], "ex": LSColors["ex"], "ln": LSColors["ln"], "ur": []color.Attribute{38, 5, 230, 1}, "uw": []color.Attribute{38, 5, 209, 1}, "ux": []color.Attribute{38, 5, 156, 1}, "ue": []color.Attribute{38, 5, 156, 1}, "gr": []color.Attribute{38, 5, 230, 1}, "gw": []color.Attribute{38, 5, 209, 1}, "gx": []color.Attribute{38, 5, 156, 1}, "tr": []color.Attribute{38, 5, 230, 1}, "tw": []color.Attribute{38, 5, 209, 1}, "tx": []color.Attribute{38, 5, 156, 1}, "sn": []color.Attribute{38, 5, 156, 1}, "sb": []color.Attribute{38, 5, 156}, "uu": []color.Attribute{38, 5, 229, 1}, "un": []color.Attribute{38, 5, 214}, "gu": []color.Attribute{38, 5, 229, 1}, "gn": []color.Attribute{38, 5, 214}, "da": []color.Attribute{38, 5, 153}, "hd": []color.Attribute{38, 5, 251, 4}, "-": []color.Attribute{38, 5, 8}, ".": []color.Attribute{38, 5, 8}, " ": []color.Attribute{38, 5, 8}, "ga": []color.Attribute{38, 5, 156}, "gm": []color.Attribute{38, 5, 117}, "gd": []color.Attribute{38, 5, 209}, "gv": []color.Attribute{38, 5, 230}, "gt": []color.Attribute{38, 5, 135}, "dir": []color.Attribute{38, 5, 189}, "xattr": []color.Attribute{38, 5, 249, 4}, "in": []color.Attribute{38, 5, 213}, "lk": []color.Attribute{38, 5, 209, 1}, "bk": []color.Attribute{38, 5, 189}, } // LSColors = make(map[string]string) is LS_COLORS code according to // extention of file LSColors = map[string][]color.Attribute{}/* 588 elements not displayed */ )
var DefaultIgnoreFn = func(f *File, err error) error { if err != nil { return err } _, file := filepath.Split(f.Path) if paw.HasPrefix(file, ".") { return SkipThis } return nil }
DefaultIgnoreFn is default IgnoreFn using in FindFiles
_, file := filepath.Split(f.Path)
Skip file: prefix "." of file
var ( FieldsMap = map[PDFieldFlag]*Field{ PFieldINode: NewField(PFieldINode), PFieldPermissions: NewField(PFieldPermissions), PFieldLinks: NewField(PFieldLinks), PFieldSize: NewField(PFieldSize), PFieldBlocks: NewField(PFieldBlocks), PFieldUser: NewField(PFieldUser), PFieldGroup: NewField(PFieldGroup), PFieldModified: NewField(PFieldModified), PFieldCreated: NewField(PFieldCreated), PFieldAccessed: NewField(PFieldAccessed), PFieldGit: NewField(PFieldGit), PFieldName: NewField(PFieldName), PFieldNone: NewField(PFieldNone), } )
var SkipThis = errors.New("skip the path")
SkipThis is used as a return value indicate that the regular path (file or directory) named in the Callback is to be skipped. It is not returned as an error by any function.
var (
SpaceIndentSize = paw.Spaces(IndentSize)
)
Functions ¶
func ByteSize ¶
ByteSize returns a human-readable byte string of the form 10M, 12.5K, and so forth. The following units are available:
E: Exabyte P: Petabyte T: Terabyte G: Gigabyte M: Megabyte K: Kilobyte B: Byte
The unit that results in the smallest number greater than or equal to 1 is always chosen.
func DateString ¶
func DefaultNoColor ¶
func DefaultNoColor()
DefaultNoColor will resume the default value of `NoColor`
func FileLSColorString ¶
FileLSColorString will return the color string of `s` according `fullpath` (xxx.yyy)
func GetColorizePermission ¶
GetColorizePermission will return a colorful string of mode The length of placeholder in terminal is 10.
func GetColorizedDirName ¶
GetColorizedDirName will return a colorful string of {{ dir }}/{{ name }}
func GetColorizedSize ¶
GetColorizedSize will return a humman-readable and colorful string of size. The length of placeholder in terminal is 6.
func GetColorizedTime ¶
GetColorizedTime will return a colorful string of time. The length of placeholder in terminal is 14.
func GetFileLSColor ¶
func KindEXAColorString ¶
func KindLSColorString ¶
KindLSColorString will colorful string `s` using key `kind`
func NewEXAColor ¶
NewEXAColor will return `*color.Color` using `EXAColors[key]`
func NewFileListFilter ¶
func NewLSColor ¶
NewLSColor will return `*color.Color` using `LSColors[key]`
func ToBytes ¶
ToBytes parses a string formatted by ByteSize as bytes. Note binary-prefixed and SI prefixed units both mean a base-2 units KB = K = KiB = 1024 MB = M = MiB = 1024 * K GB = G = GiB = 1024 * M TB = T = TiB = 1024 * G PB = P = PiB = 1024 * T EB = E = EiB = 1024 * P
func ToMegabytes ¶
ToMegabytes parses a string formatted by ByteSize as megabytes.
Types ¶
type ByLowerString ¶
type ByLowerString []string
ByLowerString is using in sort.Sort(data)
paw.ToLower(a[i]) < paw.ToLower(a[j])
func (ByLowerString) Len ¶
func (a ByLowerString) Len() int
func (ByLowerString) Less ¶
func (a ByLowerString) Less(i, j int) bool
func (ByLowerString) Swap ¶
func (a ByLowerString) Swap(i, j int)
type DirsBy ¶
DirsBy is the type of a "less" function that defines the ordering of its Dir arguments of FileList.
Example:
lowerDirhName := func(di, dj *string) bool { return paw.ToLower(di) < paw.ToLower(dj) } DirsBy(lowerDirName).Sort(dirs)
type Field ¶
type Field struct { Key PDFieldFlag Name string Width int Value interface{} ValueC interface{} Align paw.Align ValueColor *color.Color HeadColor *color.Color }
Field stores content of a field
Elements:
Name: name of field NameC: colorful name of field Width: number of name on console Value: value of the field ValueC: colorfulString of value of the field ValueColor: *color.Color use to create colorful srtring for value;no default color, use SetValueColor to setup HeadColor: *color.Color use to create colorful srtring for head; has default color, use SetHeadColor to setup
func (*Field) ColorHeadString ¶
ColorHeadString will return colorful string of Field.Name with width Field.Width as see
func (*Field) ColorValueString ¶
ColorValueString will colorful string of Field.Value
func (*Field) GetHeadColor ¶
GetHeadColor returns color of Field.Name
func (*Field) GetValueColor ¶
GetValueColor returns color of Field.Value
func (*Field) HeadString ¶
HeadString will return string of Field.Name with width Field.Width
func (*Field) SetColorfulValue ¶
func (f *Field) SetColorfulValue(value interface{})
SetColorfulValue sets up colorful value of Field.Value
func (*Field) SetHeadColor ¶
SetHeadColor sets up color of Field.Name
func (*Field) SetValueColor ¶
SetValueColor sets up color of Field.Value
func (*Field) ValueString ¶
ValueString will return string of Field.Value
type FieldSlice ¶
type FieldSlice struct {
// contains filtered or unexported fields
}
FieldSlice is Field union
func NewFieldSliceFrom ¶
func NewFieldSliceFrom(keys []PDFieldFlag, git GitStatus) (fds *FieldSlice)
NewFieldSliceFrom will return *fieldSlice created from []PDFieldFlag and GitStatus
func (*FieldSlice) Add ¶
func (f *FieldSlice) Add(field *Field)
Add will append a Field to FieldSlice
func (*FieldSlice) ColorHeads ¶
func (f *FieldSlice) ColorHeads() []string
ColorHeads will return the colorful string slice from Field.Name of FieldSlie
func (*FieldSlice) ColorHeadsString ¶
func (f *FieldSlice) ColorHeadsString() string
ColorHeadsString will return colorful string join by a space of FieldSlice.Head()
func (*FieldSlice) ColorMetaValues ¶
func (f *FieldSlice) ColorMetaValues() []string
ColorMetaValues will return string slice of Field.ColorValueString() exclude `PFieldName`
func (*FieldSlice) ColorMetaValuesString ¶
func (f *FieldSlice) ColorMetaValuesString() string
ColorHeadsString will return colorful string join by a space of FieldSlice.ColorMetaValues() exclude `PFieldName`
func (*FieldSlice) ColorValues ¶
func (f *FieldSlice) ColorValues() []string
ColorValues will return the colorful string slice from Field.ColorValueString() of FieldSlie
func (*FieldSlice) Colors ¶
func (f *FieldSlice) Colors() []*color.Color
Colors will return the []*color.Color slice from Field.ValueColor of FieldSlie
func (*FieldSlice) Count ¶
func (f *FieldSlice) Count() int
Count will return number of fields in FieldSlice
func (*FieldSlice) Fields ¶
func (f *FieldSlice) Fields() []*Field
Fields will return Fields of FieldSlice
func (*FieldSlice) Get ¶
func (f *FieldSlice) Get(key PDFieldFlag) *Field
Get will return *Field for first matched key in FieldSlice
func (*FieldSlice) GetByName ¶
func (f *FieldSlice) GetByName(name string) *Field
Get will return *Field for first matched name in FieldSlice
func (*FieldSlice) HeadAligns ¶
func (f *FieldSlice) HeadAligns() []paw.Align
HeadAligns will return the paw.Align slice from Field.Align of FieldSlie
func (*FieldSlice) HeadWidths ¶
func (f *FieldSlice) HeadWidths() []int
HeadWidths will return the int slice from Field.Width of FieldSlie
func (*FieldSlice) Heads ¶
func (f *FieldSlice) Heads() []string
Heads will return the string slice from Field.Name of FieldSlie
func (*FieldSlice) HeadsString ¶
func (f *FieldSlice) HeadsString() string
HeadsString will return string join by a space of FieldSlice.Head()
func (*FieldSlice) HeadsStringWidth ¶
func (f *FieldSlice) HeadsStringWidth() int
HeadsStringWidth will return width of FieldSlice.HeadString() as you see
func (*FieldSlice) Insert ¶
func (f *FieldSlice) Insert(startIndex int, fds ...*Field)
Insert will insert a field into the poisition of FieldSlice according to the index `startIndex`
func (*FieldSlice) MetaHeadsStringWidth ¶
func (f *FieldSlice) MetaHeadsStringWidth() int
MetaHeadsStringWidth will return width of FieldSlice.HeadString() exclude `PFieldName` as you see
func (*FieldSlice) MetaValues ¶
func (f *FieldSlice) MetaValues() []string
MetaValuesString will return string slice of Field.ValueString() exclude `PFieldName`
func (*FieldSlice) MetaValuesString ¶
func (f *FieldSlice) MetaValuesString() string
MetaValuesString will return string of FieldSlice.MetaValuesString() exclude `PFieldName` as you see
func (*FieldSlice) MetaValuesStringWidth ¶
func (f *FieldSlice) MetaValuesStringWidth() int
MetaValuesStringWidth will return width of FieldSlice.MetaValuesString() exclude `PFieldName` as you see
func (*FieldSlice) Remove ¶
func (f *FieldSlice) Remove(key PDFieldFlag)
Remove will remove the first matched field according to PDFieldFlag
func (*FieldSlice) RemoveByName ¶
func (f *FieldSlice) RemoveByName(name string)
RemoveByName will remove the first matched field according to Field.Name
func (*FieldSlice) SetColorfulValues ¶
func (f *FieldSlice) SetColorfulValues(file *File, git GitStatus)
SetColorfulValues sets up colorful values of FieldSlice from File and GitStatus
func (*FieldSlice) SetValues ¶
func (f *FieldSlice) SetValues(file *File, git GitStatus)
SetValues sets up values of FieldSlice from File and GitStatus
func (*FieldSlice) Values ¶
func (f *FieldSlice) Values() []interface{}
Values will return the interface{} slice from Field.Value of FieldSlie
func (*FieldSlice) ValuesString ¶
func (f *FieldSlice) ValuesString() []string
ValuesString will return the string slice from Field.Value of FieldSlie
type File ¶
type File struct { Path string Dir string BaseName string File string Ext string Stat os.FileInfo Size uint64 XAttributes []string }
File will store information of a file
Fields:
`Path` is an absolute representation of path. If the path is not absolute it will be joined with the current working directory to turn it into an absolute path. The absolute path name for a given file is not guaranteed to be unique. `Dir` is all but the last element of `Path`, typically the directory of path. After dropping the final element, and clean on the path and trailing slashes are removed. If the path is empty, Dir returns ".". If the path consists entirely of separators, Dir returns a single separator. The returned path does not end in a separator unless it is the root directory. `BaseName` is the last element of path. Trailing path separators are removed before extracting the last element. If the path is empty, Base returns ".". If the path consists entirely of separators, Base returns a single separator. `File` is the part of triming the suffix `Ext` of `File` `Ext` is the file name extension used by `Path`. The extension is the suffix beginning at the final dot in the final element of path; it is empty if there is no dot. `Stat` is `os.Stat(Path)` but ignoring error. `Size` is size of File `XAttributes` is extend attributes of File but ignore error
func NewFileRelTo ¶
NewFileRelTo will the pointer of instance of `File`, and is a constructor of `File`, but `File.Dir` is sub-directory of `root`
If `path` == `root`, then f.Dir = "."
func (*File) AccessedTime ¶
AccessedTime reports the last access time of File.
func (*File) BaseNameToLink ¶
BaseNameToLink return colorized name & symlink
func (*File) ColorAccessedTime ¶
ColorAccessTime will return a colorful string of File.AccessTime() like as exa. The length of placeholder in terminal is 14.
func (*File) ColorBaseName ¶
ColorBaseName will return a colorful string of BaseName using LS_COLORS like as exa
func (*File) ColorBaseNameToLink ¶
ColorBaseNameToLink return colorized name & symlink
func (*File) ColorCreatedTime ¶
ColorCreatedTime will return a colorful string of File.CreateTime() like as exa. The length of placeholder in terminal is 14.
func (*File) ColorDirName ¶
ColorDirName will return a colorful string of {{dir of Path}}+{{name of path }} for human-reading like as exa
func (*File) ColorGitStatus ¶
ColorGitStatus will return a colorful string of git status like as exa. The length of placeholder in terminal is 3.
func (*File) ColorLinkPath ¶
ColorLinkPath return colorized far-end path string of a symbolic link.
func (*File) ColorMeta ¶
ColorMeta will return a colorful string of meta information of File (including Permission, Size, User, Group, Data Modified, Git and Name of File) and its' length.
func (*File) ColorModifyTime ¶
ColorModifyTime will return a colorful string of Stat.ModTime() like as exa. The length of placeholder in terminal is 14.
func (*File) ColorPermission ¶
ColorPermission will return a colorful string of Stat.Mode() like as exa. The length of placeholder in terminal is 11.
func (*File) ColorSize ¶
ColorSize will return a colorful string of Size for human-reading like as exa. The length of placeholder in terminal is 6.
func (*File) CreatedTime ¶
CreatedTime reports the create time of file.
func (*File) DirSlice ¶
DirSlice will split `f.Dir` following Spearator, seperating it into a string slice.
func (*File) IsDir ¶
IsDir reports whether `f` describes a directory. That is, it tests for the ModeDir bit being set in `f`.
func (*File) IsFile ¶
IsFile reports whether File describes a file (not directory and symbolic link).
func (*File) IsNotIdentify ¶
IsNotIdentify() report whether File describes a not-identify.
func (*File) LSColorString ¶
LSColorString will return a color string using LS_COLORS according to `f.Path` of file
func (*File) ModifiedTime ¶
ModifiedTime reports the modify time of file.
func (*File) PathSlice ¶
PathSlice will split `f.Path` following Spearator, seperating it into a string slice.
func (*File) Permission ¶
Permission will return a string of Stat.Mode() like as exa. The length of placeholder in terminal is 11.
func (*File) TypeString ¶
type FileList ¶
type FileList struct { // writers []io.Writer IsSort bool // increasing order of Lower(path) IsGrouped bool // grouping files and directories separetly // contains filtered or unexported fields }
FileList stores the list information of File
func NewFileList ¶
NewFileList will return the instance of `FileList`
func PrintDir ¶
func PrintDir(w io.Writer, path string, isGrouped bool, opt *PrintDirOption, pad string) (error, *FileList)
PrintDir will find files using codintion `ignore` func
func (*FileList) DirInfo ¶
DirInfo will return the colorful string of sub-dir ( file.IsDir is true) and the width on console.
func (*FileList) DisableColor ¶
func (f *FileList) DisableColor()
func (*FileList) EnableColor ¶
func (f *FileList) EnableColor()
func (*FileList) FindFiles ¶
func (f *FileList) FindFiles(depth int, ignore IgnoreFunc) error
FindFiles will find files using codintion `ignore` func
depth : depth of subfolders depth < 0 : walk through all directories of {root directory} depth == 0 : {root directory}/ depth > 0 : {root directory}/{level 1 directory}/.../{{ level n directory }}/ ignore: IgnoreFn func(f *File, err error) error ignoring condition of files or directory ignore == nil, using DefaultIgnoreFn
func (*FileList) GetGitStatus ¶
GetGitStatus will return git short status of `FileList`
func (*FileList) GetHead4Meta ¶
func (f *FileList) GetHead4Meta(pad, username, groupname string, git GitStatus) (chead string, width int)
GetHead4Meta will return a colorful string of head line for meta information of File
func (*FileList) NSubDirsAndFiles ¶
NSubDirsAndFiles will return the number of sub-dirs and sub-files in dir
func (*FileList) ResetStringBuilder ¶
func (f *FileList) ResetStringBuilder()
ResetStringBuilder will reset the buffer of FileList
func (*FileList) ResetWriters ¶
func (f *FileList) ResetWriters()
ResetWriters will reset default writers... (Buffer of FileList) to writer of FileList
func (*FileList) SetDirsSorter ¶
SetDirsSorter will set sorter of Dirs of FileList
func (*FileList) SetFilesSorter ¶
SetFilesSorter will set sorter of Files of FileList
func (*FileList) SetWriters ¶
SetWriters will set writers... to writer of FileList
func (*FileList) Sort ¶
func (f *FileList) Sort()
Sort will sort FileList by sorter of dirsBy and filesBy.
Default:
Dirs: ToLower(a[i]) < ToLower(a[j]) Map[dir][]*file: ToLower(a[i].Path) < ToLower(a[j].Path)
func (FileList) String ¶
String ...
`size` of directory shown in the string, is accumulated size of sub contents
func (*FileList) StringBuilder ¶
StringBuilder will return the *strings.Builder buffer of FileList
func (*FileList) ToClassifyView ¶
ToClassifyView will return the string of FileList to display type indicator by file names (like as `exa -F` or `exa --classify`)
func (*FileList) ToClassifyViewString ¶
ToClassifyView will return the string of FileList to display type indicator by file names (like as `exa -F` or `exa --classify`)
func (*FileList) ToLevelExtendViewBytes ¶
ToLevelExtendViewString will return the string involving extend attribute of FileList in level form
`size` of directory shown in the string, is accumulated size of sub contents
func (*FileList) ToLevelView ¶
ToLevelView will return the string of FileList in level form
`size` of directory shown in the returned value, is accumulated size of sub contents If `isExtended` is true to involve extend attribute
func (*FileList) ToLevelViewBytes ¶
ToLevelViewBytes will return the []byte of FileList in table form
`size` of directory shown in the string, is accumulated size of sub contents
func (*FileList) ToListExtendView ¶
ToListExtendView will return the string of FileList in extend list form (like as `exa --header --long --time-style=iso --group --git --@`)
func (*FileList) ToListExtendViewBytes ¶
ToListExtendViewBytes will return the []byte of FileList in extend list form (like as `exa --header --long --time-style=iso --group --git -@`)
func (*FileList) ToListTreeExtendView ¶
ToListTreeExtendView will return the string of FileList in list+tree form (like as `exa -T(--tree)`)
func (*FileList) ToListTreeExtendViewBytes ¶
ToListTreeExtendViewBytes will return the string of `ToListViewTree(pad)` in list+tree form (like as `exa -T(--tree)`)
func (*FileList) ToListTreeView ¶
ToListTreeView will return the string of FileList in list+tree form (like as `exa -T(--tree)`)
func (*FileList) ToListTreeViewBytes ¶
ToListTreeViewBytes will return the []byte of `ToListViewTree(pad)` in list+tree form (like as `exa -T(--tree)`)
func (*FileList) ToListView ¶
ToListView will return the string of FileList in list form (like as `exa --header --long --time-style=iso --group --git`)
func (*FileList) ToListViewBytes ¶
ToListViewBytes will return the []byte of FileList in list form (like as `exa --header --long --time-style=iso --group --git`)
func (*FileList) ToTableExtendViewBytes ¶
ToTableExtendViewBytes will return the []byte involving extend attribute of FileList in table form
`size` of directory shown in the string, is accumulated size of sub contents
func (*FileList) ToTableView ¶
ToTableView will return the string of FileList in table form
`size` of directory shown in the returned value, is accumulated size of sub contents If `isExtended` is true to involve extend attribute
func (*FileList) ToTableViewBytes ¶
ToTableViewBytes will return the []byte of FileList in table form
`size` of directory shown in the string, is accumulated size of sub contents
func (*FileList) ToTreeExtendView ¶
ToTreeExtendView will return the string of FileList icluding extend attribute in tree form
func (*FileList) ToTreeExtendViewBytes ¶
ToTreeExtendViewBytes will return the string of FileList in tree form
func (*FileList) ToTreeView ¶
ToTreeView will return the string of FileList in tree form
func (*FileList) ToTreeViewBytes ¶
ToTreeViewBytes will return the []byte of FileList in tree form
type FilesBy ¶
FilesBy is the type of a "less" function that defines the ordering of its File arguments.
Example:
lowerPathName := func(fi, fj *File) bool { return paw.ToLower(fi.Path) < paw.ToLower(fj.Path) } FilesBy(lowerPathName).Sort(files)
type Filter ¶
type Filter func(fl *FileList)
Filter is the type of filter function that define the filtering of its arguments
var ( FiltEmptyDirs Filter = func(fl *FileList) { // paw.Info.Println("FiltEmptyDirs") var emptyDirs []string for _, dir := range fl.dirs { hasEmpty := false var name, pdir string if len(fl.store[dir]) <= 1 { emptyDirs = append(emptyDirs, dir) hasEmpty = true tdirs := paw.Split(dir, PathSeparator) name = tdirs[len(tdirs)-1] pdir = filepath.Join(tdirs[:len(tdirs)-1]...) if pdir == UpDirMark { pdir = RootMark } } if hasEmpty { fm := fl.store[pdir] jdx := paw.LastIndexOf(len(fm), func(i int) bool { return fm[i].IsDir() && fm[i].BaseName == name }) if jdx != -1 { fl.store[pdir] = append(fm[:jdx], fm[jdx+1:]...) } hasEmpty = false } } for _, v := range emptyDirs { delete(fl.store, v) idx := paw.LastIndexOfString(fl.dirs, v) if idx != -1 { fl.dirs = append(fl.dirs[:idx], fl.dirs[idx+1:]...) } } } FiltJustDirs Filter = func(fl *FileList) { for _, dir := range fl.dirs { fm := fl.store[dir] for _, f := range fm { j := paw.LastIndexOf(len(fm), func(i int) bool { return !f.IsDir() }) if j != -1 { fl.store[dir] = append(fm[:j], fm[j+1:]...) } } } } FiltJustFiles Filter = func(fl *FileList) { FiltEmptyDirs(fl) var dirs []string for _, dir := range fl.dirs { fm := fl.store[dir] if len(fm) <= 1 { continue } var files []*File files = append(files, fl.store[dir][0]) for _, file := range fl.store[dir][1:] { if !file.IsDir() { files = append(files, file) if paw.IndexOfString(dirs, dir) == -1 { dirs = append(dirs, file.Dir) } } } fl.store[dir] = files } fl.dirs = dirs } )
type GitStatus ¶
GitStatus stores git status of `Branch`
NoGit are true : no git Branch are branch of git FilesStatus are map[{{ path }}]{{ XY }} XY are ??, 2 characters string, see also "https://git-scm.com/docs/git-status"
func GetShortGitStatus ¶
GetShortGitStatus read the git status of the repository located at path
if err != nil : no git
type IgnoreFunc ¶
IgnoreFn is the type of the function called for each file or directory visited by FindFiles. The f argument contains the File argument to FindFiles.
If there was a problem walking to the file or directory named by path, the incoming error will describe the problem and the function can decide how to handle that error (and FindFiles will not descend into that directory). In the case of an error, the info argument will be nil. If an error is returned, processing stops. The sole exception is when the function returns the special value ErrSkipDir or ErrSkipFile. If the function returns ErrSkipDir when invoked on a directory, FindFiles skips the directory's contents entirely. If the function returns ErrSkipDir when invoked on a non-directory file, FindFiles skips the remaining files in the containing directory. If the returned error is SkipFile when inviked on a file, FindFiles will skip the file.
type PDFieldFlag ¶
type PDFieldFlag int
const ( // PFieldINode uses inode field PFieldINode PDFieldFlag = 1 << iota // PFieldPermissions uses permission field PFieldPermissions // PFieldLinks uses hard link field PFieldLinks // PFieldSize uses size field PFieldSize // PFieldBlocks uses blocks field PFieldBlocks // PFieldUser uses user field PFieldUser // PFieldGroup uses group field PFieldGroup // PFieldModified uses date modified field PFieldModified // PFieldAccessed uses date accessed field PFieldAccessed // PFieldCreated uses date created field PFieldCreated // PFieldGit uses git field PFieldGit // PFieldName uses name field PFieldName // PFieldNone uses non-default field PFieldNone )
type PDFiltFlag ¶
type PDFiltFlag int
type PDFilterOption ¶
type PDFilterOption struct { IsFilt bool FiltWay PDFiltFlag }
type PDSortFlag ¶
type PDSortFlag int
type PDSortOption ¶
type PDSortOption struct { IsSort bool SortWay PDSortFlag }
PDSortOption defines sorting way view of PrintDir
Defaut:
increasing sort by lower name of path
type PDViewFlag ¶
type PDViewFlag int
const ( // PListView is the option of list view using in PrintDir PListView PDViewFlag = 1 << iota // 1 << 0 which is 00000001 // PListExtendView is the option of list view icluding extend attributes using in PrintDir PListExtendView // PTreeView is the option of tree view using in PrintDir PTreeView // PTreeExtendView is the option of tree view icluding extend atrribute using in PrintDir PTreeExtendView // PLevelView is the option of level view using in PrintDir PLevelView // PLevelExtendView is the option of level view icluding extend attributes using in PrintDir PLevelExtendView // PTableView is the option of table view using in PrintDir PTableView // PTableView is the option of table view icluding extend attributes using in PrintDir PTableExtendView // PClassifyView display type indicator by file names (like as `exa -F` or `exa --classify`) in PrintDir PClassifyView // PListTreeView is the option of combining list & tree view using in PrintDir PListTreeView = PListView | PTreeView // PListTreeExtendView is the option of combining list & tree view including extend attribute using in PrintDir PListTreeExtendView = PListView | PTreeExtendView )
type PrintDirOption ¶
type PrintDirOption struct { Depth int OutOpt PDViewFlag FieldFlag PDFieldFlag SortOpt *PDSortOption FiltOpt *PDFilterOption Ignore IgnoreFunc }
PrintDirOption is the option of PrintDir
Fields:
Depth: Depth < 0 : print all files and directories recursively of argument path of PrintDir. Depth = 0 : print files and directories only in argument path of PrintDir. Depth > 0 : print files and directories recursively under depth of directory in argument path of PrintDir.
OutOpt: the view-option of PrintDir Call
func NewPrintDirOption ¶
func NewPrintDirOption() *PrintDirOption