iface

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileSystem

type FileSystem interface {
	// Open opens the named object for reading.
	Open(name string) (fs.File, error)

	// Stat returns a FileInfo for the given name.
	Stat(name string) (fs.FileInfo, error)

	// ReadDir reads the directory and returns a list of DirEntry.
	ReadDir(name string) ([]fs.DirEntry, error)

	// ReadLink returns the destination of the named symbolic link. If there is an error, it will be of type *os.PathError.
	ReadLink(name string) (string, error)

	// WorkDir returns the path of working directory
	WorkDir() string

	// UserHomeDir returns the current user's home directory.
	UserHomeDir() (string, error)

	// CountDirContents: returns the number of files/directories direnctly under a given directory
	CountDirContents(name string) (int, error)

	// same as filepath.Abs
	Abs(path string) (string, error)

	// same as filepath.Dir, but also work with path ending with a slash/sep
	Dir(path string) string

	// same as filepath.IsAbs
	IsAbs(path string) bool

	// same as filepath.Join
	Join(elem ...string) string

	// same as filepath.Rel
	Rel(basepath, targpath string) (string, error)

	SplitAll(path string) []string

	// same as Join, but give a color to path sep (slash or backslash)
	JoinColor(color string, reset string, elem ...string) string

	SplitExt(filename string) *common.ParsedName
}

implements the fs.FS interface.

type FormattedItemList

type FormattedItemList interface {
	Len() int
	Get(int) []string
}

type Formatter

type Formatter interface {
	// LongSet applies --long flag to given column name map
	LongSet(cols map[string]bool)

	// LongLinkTarget returns true if symlink targets are to be shown with --long
	LongLinkTarget() bool

	// LinkTargetSep returns separator between filename and link target with --links
	LinkTargetSep() string

	// DefaultTimeFormat returns default time format
	DefaultTimeStyle() string

	// SizeFormat returns format for file sizes
	SizeFormat() common.SizeFormat

	// PrintError formats and prints any error
	PrintError(w io.Writer, err error)

	// FolderHeader formats and prints folder header
	// when we list out any subdirectories, print those paths conspicuously
	// above the contents. this helps with visual separation
	FolderHeader(w io.Writer, path string, itemCount int)

	//  FolderHeader formats and prints folder tail
	FolderTail(w io.Writer, path string)

	// TableHeader formats and prints table header
	TableHeader(w io.Writer, tableObj *table.Table)

	// FormatValue formats a cell value
	// used for csv and json serualization
	FormatValue(colName string, value string) (string, error)

	// FormatItem formats a file/directory item/entry
	// it does not apply table alignments
	FormatItem(tableObj *table.Table, item any) ([]string, error)

	// PrintItems applies table alignments to a list of formatted file items
	// and prints them to given io.Writer
	PrintItems(w io.Writer, tableObj *table.Table, items FormattedItemList) error
}

type Terminal added in v1.1.0

type Terminal interface {
	// TermWidth returns terminal width
	TermWidth() (int, error)

	// OutputIsTerminal returns true if standard output is connected to a terminal
	OutputIsTerminal(stdout *os.File) bool

	// ColorsEnabled returns true if colors are enabled
	ColorsEnabled(colorFlag string) (bool, error)
}

Jump to

Keyboard shortcuts

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