filetree

package
v0.0.7-2021.1.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 20, 2021 License: MIT Imports: 26 Imported by: 1

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

View Source
const (
	BYTE = 1 << (10 * iota)
	KILOBYTE
	MEGABYTE
	GIGABYTE
	TERABYTE
	PETABYTE
	EXABYTE
)
View Source
const (
	// PathSeparator is OS-specific path separator ('/')
	PathSeparator = string(os.PathSeparator)
	// PathListSeparator is OS-specific path list separator (':')
	PathListSeparator = string(os.PathListSeparator)
)
View Source
const (
	// RootMark = "."
	RootMark  = "."
	UpDirMark = ".."
)
View Source
const (
	PDSort PDSortFlag = 1 << iota
	PDSortReverse

	PDSortByName         = PDSort | pdSortKeyName
	PDSortByMtime        = PDSort | pdSortKeyMTime
	PDSortBySize         = PDSort | pdSortKeySize
	PDSortByReverseName  = PDSortByName | PDSortReverse
	PDSortByReverseMtime = PDSortByMtime | PDSortReverse
	PDSortByReverseSize  = PDSortBySize | PDSortReverse
)
View Source
const (
	PDFiltNoEmptyDir = 1 << iota
	PDFiltJustDirs
	PDFiltJustFiles
	PDFiltJustDirsButNoEmpty     = PDFiltNoEmptyDir | PDFiltJustDirs
	PDFiltJustFilesButNoEmptyDir = PDFiltJustFiles
)

Variables

View Source
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)
	}
)
View Source
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 */

)
View Source
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
View Source
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.

View Source
var (
	SpaceIndentSize = paw.Spaces(IndentSize)
)

Functions

func ByteSize

func ByteSize(bytes uint64) string

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 DateString(date time.Time) (sdate string)

func DefaultNoColor

func DefaultNoColor()

DefaultNoColor will resume the default value of `NoColor`

func FileLSColorString

func FileLSColorString(fullpath, s string) (string, error)

FileLSColorString will return the color string of `s` according `fullpath` (xxx.yyy)

func GetColorizePermission

func GetColorizePermission(mode os.FileMode) string

GetColorizePermission will return a colorful string of mode The length of placeholder in terminal is 10.

func GetColorizedDirName

func GetColorizedDirName(path string, root string) string

GetColorizedDirName will return a colorful string of {{ dir }}/{{ name }}

func GetColorizedSize

func GetColorizedSize(size uint64) (csize string)

GetColorizedSize will return a humman-readable and colorful string of size. The length of placeholder in terminal is 6.

func GetColorizedTime

func GetColorizedTime(date time.Time) string

GetColorizedTime will return a colorful string of time. The length of placeholder in terminal is 14.

func GetFileLSColor

func GetFileLSColor(file *File) *color.Color

func KindEXAColorString

func KindEXAColorString(kind, s string) string

func KindLSColorString

func KindLSColorString(kind, s string) string

KindLSColorString will colorful string `s` using key `kind`

func NewEXAColor

func NewEXAColor(key string) *color.Color

NewEXAColor will return `*color.Color` using `EXAColors[key]`

func NewFileListFilter

func NewFileListFilter(fl *FileList, filters []Filter) *fileListFilter

func NewLSColor

func NewLSColor(key string) *color.Color

NewLSColor will return `*color.Color` using `LSColors[key]`

func SetNoColor

func SetNoColor()

SetNoColor will set `true` to `NoColor`

func ToBytes

func ToBytes(s string) (uint64, error)

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

func ToMegabytes(s string) (uint64, error)

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

type DirsBy func(di, dj string) bool

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)

func (DirsBy) Sort

func (by DirsBy) Sort(dirs []string)

Sort is a method on the function type, By, that sorts the argument slice according to the function.

type EdgeType

type EdgeType string

ToListTree

const (
	EdgeTypeLink EdgeType = "│"   //treeprint.EdgeTypeLink
	EdgeTypeMid  EdgeType = "├──" //treeprint.EdgeTypeMid
	EdgeTypeEnd  EdgeType = "└──" //treeprint.EdgeTypeEnd
	IndentSize            = 3     //treeprint.IndentSize

)

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 NewField

func NewField(flag PDFieldFlag) *Field

NewField will return *Field

func (*Field) ColorHeadString

func (f *Field) ColorHeadString() string

ColorHeadString will return colorful string of Field.Name with width Field.Width as see

func (*Field) ColorValueString

func (f *Field) ColorValueString() string

ColorValueString will colorful string of Field.Value

func (*Field) GetHeadColor

func (f *Field) GetHeadColor(c *color.Color) *color.Color

GetHeadColor returns color of Field.Name

func (*Field) GetValueColor

func (f *Field) GetValueColor(c *color.Color) *color.Color

GetValueColor returns color of Field.Value

func (*Field) HeadString

func (f *Field) HeadString() string

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

func (f *Field) SetHeadColor(c *color.Color)

SetHeadColor sets up color of Field.Name

func (*Field) SetValue

func (f *Field) SetValue(value interface{})

SetValue sets up Field.Value

func (*Field) SetValueColor

func (f *Field) SetValueColor(c *color.Color)

SetValueColor sets up color of Field.Value

func (*Field) ValueString

func (f *Field) ValueString() string

ValueString will return string of Field.Value

type FieldSlice

type FieldSlice struct {
	// contains filtered or unexported fields
}

FieldSlice is Field union

func NewFieldSlice

func NewFieldSlice() *FieldSlice

NewFieldSlice will return *fieldSlice

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 NewFile

func NewFile(path string) (*File, error)

NewFile will the pointer of instance of `File`, and is a constructor of `File`.

func NewFileRelTo

func NewFileRelTo(path, root string) (*File, error)

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

func (f *File) AccessedTime() time.Time

AccessedTime reports the last access time of File.

func (f *File) BaseNameToLink() string

BaseNameToLink return colorized name & symlink

func (*File) Blocks

func (f *File) Blocks() uint64

Blocks will return number of file system blocks of File

func (*File) ColorAccessedTime

func (f *File) ColorAccessedTime() string

ColorAccessTime will return a colorful string of File.AccessTime() like as exa. The length of placeholder in terminal is 14.

func (*File) ColorBaseName

func (f *File) ColorBaseName() string

ColorBaseName will return a colorful string of BaseName using LS_COLORS like as exa

func (f *File) ColorBaseNameToLink() string

ColorBaseNameToLink return colorized name & symlink

func (*File) ColorCreatedTime

func (f *File) ColorCreatedTime() string

ColorCreatedTime will return a colorful string of File.CreateTime() like as exa. The length of placeholder in terminal is 14.

func (*File) ColorDirName

func (f *File) ColorDirName(root string) string

ColorDirName will return a colorful string of {{dir of Path}}+{{name of path }} for human-reading like as exa

func (*File) ColorGitStatus

func (f *File) ColorGitStatus(git GitStatus) string

ColorGitStatus will return a colorful string of git status like as exa. The length of placeholder in terminal is 3.

func (*File) ColorLinkPath

func (f *File) ColorLinkPath() string

ColorLinkPath return colorized far-end path string of a symbolic link.

func (*File) ColorMeta

func (f *File) ColorMeta(git GitStatus) (string, int)

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

func (f *File) ColorModifyTime() string

ColorModifyTime will return a colorful string of Stat.ModTime() like as exa. The length of placeholder in terminal is 14.

func (File) ColorName

func (f File) ColorName() string

func (*File) ColorPermission

func (f *File) ColorPermission() string

ColorPermission will return a colorful string of Stat.Mode() like as exa. The length of placeholder in terminal is 11.

func (*File) ColorSize

func (f *File) ColorSize() string

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

func (f *File) CreatedTime() time.Time

CreatedTime reports the create time of file.

func (*File) DirSlice

func (f *File) DirSlice() []string

DirSlice will split `f.Dir` following Spearator, seperating it into a string slice.

func (*File) INode

func (f *File) INode() uint64

INode will return the inode number of File

func (*File) IsChardev

func (f *File) IsChardev() bool

IsChardev() report whether File describes a chardev.

func (*File) IsDev

func (f *File) IsDev() bool

IsDev() report whether File describes a dev.

func (*File) IsDir

func (f *File) IsDir() bool

IsDir reports whether `f` describes a directory. That is, it tests for the ModeDir bit being set in `f`.

func (*File) IsFiFo

func (f *File) IsFiFo() bool

IsFiFo() report whether File describes a named pipe.

func (*File) IsFile

func (f *File) IsFile() bool

IsFile reports whether File describes a file (not directory and symbolic link).

func (f *File) IsLink() bool

IsLink() report whether File describes a symbolic link.

func (*File) IsNotIdentify

func (f *File) IsNotIdentify() bool

IsNotIdentify() report whether File describes a not-identify.

func (*File) IsSocket

func (f *File) IsSocket() bool

IsSocket() report whether File describes a socket.

func (*File) LSColorString

func (f *File) LSColorString(s string) string

LSColorString will return a color string using LS_COLORS according to `f.Path` of file

func (*File) LinkPath

func (f *File) LinkPath() string

LinkPath report far-end path of a symbolic link.

func (*File) ModifiedTime

func (f *File) ModifiedTime() time.Time

ModifiedTime reports the modify time of file.

func (f *File) NLinks() uint64

NLinks will return the number of hard links of File

func (File) Name

func (f File) Name() string

func (*File) PathSlice

func (f *File) PathSlice() []string

PathSlice will split `f.Path` following Spearator, seperating it into a string slice.

func (*File) Permission

func (f *File) Permission() string

Permission will return a string of Stat.Mode() like as exa. The length of placeholder in terminal is 11.

func (File) String

func (f File) String() string

func (*File) TypeString

func (f *File) TypeString() string

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

func NewFileList(root string) *FileList

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) AddFile

func (f *FileList) AddFile(file *File)

AddFile will add file into the file list

func (*FileList) DirInfo

func (f *FileList) DirInfo(file *File) (cdinf string, wdinf int)

DirInfo will return the colorful string of sub-dir ( file.IsDir is true) and the width on console.

func (*FileList) Dirs

func (f *FileList) Dirs() []string

Dirs will retun keys of `FileMap`

func (*FileList) DisableColor

func (f *FileList) DisableColor()

func (*FileList) Dump

func (f *FileList) Dump() string

Dump will dump buffer of FileList to a string

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

func (f *FileList) GetGitStatus() GitStatus

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) Map

func (f *FileList) Map() FileMap

Map will retun the `FileMap`

func (*FileList) NDirs

func (f *FileList) NDirs() int

NDirs is the numbers of sub-directories of `root`

func (*FileList) NFiles

func (f *FileList) NFiles() int

NFiles is the numbers of all files

func (*FileList) NSubDirsAndFiles

func (f *FileList) NSubDirsAndFiles(dir string) (ndirs, nfiles int)

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) Root

func (f *FileList) Root() string

Root will return the `root` field (root directory)

func (*FileList) SetDirsSorter

func (f *FileList) SetDirsSorter(by DirsBy)

SetDirsSorter will set sorter of Dirs of FileList

func (*FileList) SetFilesSorter

func (f *FileList) SetFilesSorter(by FilesBy)

SetFilesSorter will set sorter of Files of FileList

func (*FileList) SetWriters

func (f *FileList) SetWriters(writers ...io.Writer)

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) SortBy

func (f *FileList) SortBy(dirsBy DirsBy, filesBy FilesBy)

SortBy will sort FileList using sorters `dirsBy` and `filesBy`

func (FileList) String

func (f FileList) String() string

String ...

`size` of directory shown in the string, is accumulated size of sub contents

func (*FileList) StringBuilder

func (f *FileList) StringBuilder() *strings.Builder

StringBuilder will return the *strings.Builder buffer of FileList

func (*FileList) ToClassifyView

func (f *FileList) ToClassifyView(pad string) string

ToClassifyView will return the string of FileList to display type indicator by file names (like as `exa -F` or `exa --classify`)

func (*FileList) ToClassifyViewString

func (f *FileList) ToClassifyViewString(pad string) string

ToClassifyView will return the string of FileList to display type indicator by file names (like as `exa -F` or `exa --classify`)

func (*FileList) ToLevelExtendViewBytes

func (f *FileList) ToLevelExtendViewBytes(pad string) []byte

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

func (f *FileList) ToLevelView(pad string, isExtended bool) string

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

func (f *FileList) ToLevelViewBytes(pad string) []byte

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

func (f *FileList) ToListExtendView(pad string) string

ToListExtendView will return the string of FileList in extend list form (like as `exa --header --long --time-style=iso --group --git --@`)

func (*FileList) ToListExtendViewBytes

func (f *FileList) ToListExtendViewBytes(pad string) []byte

ToListExtendViewBytes will return the []byte of FileList in extend list form (like as `exa --header --long --time-style=iso --group --git -@`)

func (*FileList) ToListTreeExtendView

func (f *FileList) ToListTreeExtendView(pad string) string

ToListTreeExtendView will return the string of FileList in list+tree form (like as `exa -T(--tree)`)

func (*FileList) ToListTreeExtendViewBytes

func (f *FileList) ToListTreeExtendViewBytes(pad string) []byte

ToListTreeExtendViewBytes will return the string of `ToListViewTree(pad)` in list+tree form (like as `exa -T(--tree)`)

func (*FileList) ToListTreeView

func (f *FileList) ToListTreeView(pad string) string

ToListTreeView will return the string of FileList in list+tree form (like as `exa -T(--tree)`)

func (*FileList) ToListTreeViewBytes

func (f *FileList) ToListTreeViewBytes(pad string) []byte

ToListTreeViewBytes will return the []byte of `ToListViewTree(pad)` in list+tree form (like as `exa -T(--tree)`)

func (*FileList) ToListView

func (f *FileList) ToListView(pad string) string

ToListView will return the string of FileList in list form (like as `exa --header --long --time-style=iso --group --git`)

func (*FileList) ToListViewBytes

func (f *FileList) ToListViewBytes(pad string) []byte

ToListViewBytes will return the []byte of FileList in list form (like as `exa --header --long --time-style=iso --group --git`)

func (*FileList) ToTableExtendViewBytes

func (f *FileList) ToTableExtendViewBytes(pad string) []byte

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

func (f *FileList) ToTableView(pad string, isExtended bool) string

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

func (f *FileList) ToTableViewBytes(pad string) []byte

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

func (f *FileList) ToTreeExtendView(pad string) string

ToTreeExtendView will return the string of FileList icluding extend attribute in tree form

func (*FileList) ToTreeExtendViewBytes

func (f *FileList) ToTreeExtendViewBytes(pad string) []byte

ToTreeExtendViewBytes will return the string of FileList in tree form

func (*FileList) ToTreeView

func (f *FileList) ToTreeView(pad string) string

ToTreeView will return the string of FileList in tree form

func (*FileList) ToTreeViewBytes

func (f *FileList) ToTreeViewBytes(pad string) []byte

ToTreeViewBytes will return the []byte of FileList in tree form

func (*FileList) Writer

func (f *FileList) Writer() io.Writer

Writer will return the field writer of FileList

type FileMap

type FileMap map[string][]*File

FileMap stores directory map to `map[{{ sub-path }}]{{ *File }}`

type FilesBy

type FilesBy func(fi, fj *File) bool

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)

func (FilesBy) Sort

func (by FilesBy) Sort(files []*File)

Sort is a method on the function type, By, that sorts the argument slice according to the function.

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

type GitStatus struct {
	NoGit       bool
	Branch      string
	FilesStatus map[string]XY // == map[string]XY

}

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

func GetShortGitStatus(path string) (GitStatus, error)

GetShortGitStatus read the git status of the repository located at path

if err != nil : no git

func ParseShort

func ParseShort(root string, r io.Reader) GitStatus

Parse parses a git status output command It is compatible with the short version of the git status command

type IgnoreFunc

type IgnoreFunc func(f *File, err error) error

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

type XY

type XY []rune

func ToXY

func ToXY(st string) XY

func (XY) Split

func (s XY) Split() (x, y rune)

func (XY) String

func (s XY) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL