ctw

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCustomTerminalWidth

func GetCustomTerminalWidth() int

Types

type CTW

type CTW interface {
	AddRow(color string, args ...string)
	Flush(buf *bytes.Buffer)
	GetGitColor(gitStatus string) string
	// contains filtered or unexported methods
}

func NewCTW

func NewCTW(longMode, oneFilePerLine, icon bool) CTW

type LongCTW

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

LongCTW is a specialized column-table-writer for "long" listings. It contains logic to store data rows, compute column widths, and handle colorization for icons and Git status columns.

func NewLongCTW

func NewLongCTW(cols int) *LongCTW

NewLongCTW creates a new LongCTW that is set up to have `cols` columns.

If cols = 5, for example, internally it will treat it as numCols = 4. This code historically assumes there's a special 'git column' plus an 'icon column'.

func (*LongCTW) AddRow

func (l *LongCTW) AddRow(color string, columns ...string)

AddRow appends a new row to the table.

The first parameter, iconColor, is the color that will be used to print the "icon column" for this row. The remaining arguments are the data for each column. The length of args must be exactly numCols+1.

func (*LongCTW) Flush

func (l *LongCTW) Flush(buf *bytes.Buffer)

Flush writes the entire table to the provided buffer.

It will skip columns that end up with zero-width, and it overrides certain columns (like the 'git column' and the 'icon column') to have explicit widths.

func (LongCTW) GetGitColor

func (c LongCTW) GetGitColor(gitStatus string) string

type StandardCTW

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

StandardCTW is a specialized column-table-writer for a "standard" listing. Unlike LongCTW, it tries to fit multiple columns of data in the available terminal width, along with optional icons and Git status columns.

Each row has up to 4 sub-columns in the following order:

  1. size
  2. icon
  3. name + extension + indicator
  4. gitStatus

func NewStandardCTW

func NewStandardCTW(termW int) *StandardCTW

NewStandardCTW creates a new StandardCTW, specifying the terminal width. The internal `numCols` is fixed at 3 (which yields 4 sub-columns: size, icon, name, gitStatus).

func (*StandardCTW) AddRow

func (s *StandardCTW) AddRow(color string, args ...string)

AddRow appends a new row to the table, each row having exactly 4 pieces of data:

size, icon, name, gitStatus

color is the ANSI color code for the icon column.

func (*StandardCTW) Flush

func (s *StandardCTW) Flush(buf *bytes.Buffer)

Flush calculates how to best fit columns into the given terminal width, then prints them all to buf.

func (StandardCTW) GetGitColor

func (c StandardCTW) GetGitColor(gitStatus string) string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳