render

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2025 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultBorder     = '\ue0b0'
	DefaultBarBGColor = "#353533"
	DynamicWidth      = -1
)
View Source
const Version = "v0.2.0"

Variables

This section is empty.

Functions

func Chart added in v0.1.3

func Chart(width, height, radius int, totalSize int64, raw []RawChartSector, colors []lipgloss.Color) string

func DecodeFileColorSchema added in v0.2.0

func DecodeFileColorSchema(path string, cs *ColorSchema) error

DecodeFileColorSchema reads the color schema from the file by the provided path and applies it to the *ColorSchema instance. An error will be returned if the path is invalid or the JSON color schema content cannot be decoded.

func DirsKeyMap added in v0.2.0

func DirsKeyMap() [][]key.Binding

func DrivesKeyMap added in v0.2.0

func DrivesKeyMap() [][]key.Binding

func EntryIcon

func EntryIcon(e *structure.Entry) string

EntryIcon resolves an emoji icon for the provided Entry instance based on the file extension.

func FmtName added in v0.2.0

func FmtName(name string, maxWidth int) string

func FmtSize added in v0.1.3

func FmtSize[T numeric](bytesSize T, width int) string

func FmtUsage added in v0.2.0

func FmtUsage(usage float64) string
func NavigateKeyMap() [][]key.Binding

func NewProgressBar

func NewProgressBar(width int, full, empty rune) progress.Model

func NewStatusBar

func NewStatusBar(items []*BarItem, totalWidth int) string

NewStatusBar builds a new status bar based on the provided list of *BarItem instances. The total bar width is defined by the totalWidth parameter and all bar items will be fit in that width according to their parameters or evenly spread for the available width.

NOTE: This implementation does not guarantee that the manually defined element sizes will not exceed the totalWidth value.

func Overlay added in v0.1.3

func Overlay(_ int, background, overlay string, row, col int) string

Overlay renders the provided overlay string over the background value. The overlay will be rendered starting at the specified row and column. All characters from the background will be properly wrapped accordingly without breaking the ANSI sequences.

func OverlayCenter added in v0.1.3

func OverlayCenter(fullWidth, fullHeight int, background, overlay string) string

func ReportError added in v0.1.1

func ReportError(err error, stackTrace []byte) string

ReportError formats an occurred application error and prints the full report to the standard output. The report will contain the error message, the stack trace, and the info on how to report an issue.

func SetTeaProgram

func SetTeaProgram(tp *tea.Program)

func ShortHelp added in v0.2.0

func ShortHelp() []key.Binding

func ToggleHelpBinding added in v0.2.0

func ToggleHelpBinding() key.Binding

Types

type BarItem

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

BarItem represents a single status bar item, including its string content, background color, and width. The width parameter is optional, and the default width equals the content width.

The width value -1 denotes that the item will take all available screen width minus the sum of all other elements' widths. If multiple items have a width value of -1, the resulting width will be spread equally between them.

func DefaultBarItem

func DefaultBarItem(content string) *BarItem

DefaultBarItem returns a new *BarItem instance with default values for background color and width.

func NewBarItem

func NewBarItem(content, bgColor string, width int) *BarItem

NewBarItem returns a new *BarItem instance based on the provided parameters. If the background color is an empty string, a default color will be assigned.

type ChartColors added in v0.2.0

type ChartColors struct {
	Border  string `json:"border"`
	Sector1 string `json:"sector1"`
	Sector2 string `json:"sector2"`
	Sector3 string `json:"sector3"`
	Sector4 string `json:"sector4"`
	Sector5 string `json:"sector5"`
	Sector6 string `json:"sector6"`
	Sector7 string `json:"sector7"`
	Sector8 string `json:"sector8"`
	Sector9 string `json:"sector9"`
}

type ColorSchema added in v0.2.0

type ColorSchema struct {
	StatusBar         StatusBarColors `json:"statusBar"`
	ChartColors       ChartColors     `json:"chart"`
	TableHeaderBorder string          `json:"tableHeaderBorder"`
	SelectedRowText   string          `json:"selectedRowText"`
	SelectedRowBG     string          `json:"selectedRowBackground"`
	TopFilesText      string          `json:"topFilesText"`
	HelpText          string          `json:"helpText"`
	BindingText       string          `json:"bindingText"`
	DialogBoxBorder   string          `json:"dialogBoxBorder"`
	ConfirmButtonText string          `json:"confirmButtonText"`
	ConfirmButtonBG   string          `json:"confirmButtonBackground"`
	ActiveButtonText  string          `json:"activeButtonText"`
	ActiveButtonBG    string          `json:"activeButtonBackground"`
	FilterText        string          `json:"filterText"`
}

The ColorSchema schema contains color values for most UI elements, such as text and border colors, element backgrounds, etc. The Style component uses the ColorSchema instance during rendering elements. Each color value must be represented as a hex ("#FFBF69") or ANSI ("240") string color code.

DefaultColorSchema always used as a base schema and all customizations are applied over it.

func DefaultColorSchema added in v0.2.0

func DefaultColorSchema() ColorSchema

type Column

type Column struct {
	Title   string
	SortKey drive.SortKey
	Width   int
}

func (*Column) FmtName

func (c *Column) FmtName(sortState SortState) string

type DeleteChoice added in v0.1.3

type DeleteChoice int
const (
	CancelChoice DeleteChoice = iota
	ConfirmChoice
)

type DeleteDialogModel added in v0.1.3

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

func NewDeleteDialogModel added in v0.1.3

func NewDeleteDialogModel(nav *Navigation, targetPath string) *DeleteDialogModel

func (*DeleteDialogModel) Init added in v0.1.3

func (ddm *DeleteDialogModel) Init() tea.Cmd

func (*DeleteDialogModel) Update added in v0.1.3

func (ddm *DeleteDialogModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*DeleteDialogModel) View added in v0.1.3

func (ddm *DeleteDialogModel) View() string

type DirModel

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

func NewDirModel

func NewDirModel(nav *Navigation, filters ...filter.EntryFilter) *DirModel

func (*DirModel) Init

func (dm *DirModel) Init() tea.Cmd

func (*DirModel) Update

func (dm *DirModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*DirModel) View

func (dm *DirModel) View() string

type DirsStatusBarColors added in v0.2.0

type DirsStatusBarColors struct {
	PathBG  string `json:"pathBackground"`
	ModeBG  string `json:"modeBackground"`
	SizeBG  string `json:"sizeBackground"`
	DirsBG  string `json:"dirsBackground"`
	FilesBG string `json:"filesBackground"`
	ErrorBG string `json:"errorBackground"`
}

type DriveModel

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

func NewDriveModel

func NewDriveModel(n *Navigation) *DriveModel

func (*DriveModel) Init

func (dm *DriveModel) Init() tea.Cmd

func (*DriveModel) Update

func (dm *DriveModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*DriveModel) View

func (dm *DriveModel) View() string

type DrivesStatusBarColors added in v0.2.0

type DrivesStatusBarColors struct {
	ModeBG     string `json:"modeBackground"`
	CapacityBG string `json:"capacityBackground"`
	FreeBG     string `json:"freeBackground"`
	UsedBG     string `json:"usedBackground"`
}

type EnqueueRefresh added in v0.1.3

type EnqueueRefresh struct{}

type EntryDeleted added in v0.1.3

type EntryDeleted struct {
	Err     error
	Deleted bool
}

type Mode

type Mode string
const (
	PENDING Mode = "PENDING"
	READY   Mode = "READY"
	INPUT   Mode = "INPUT"
	DELETE  Mode = "DELETE"
)
type Navigation struct {
	// contains filtered or unexported fields
}

Navigation defines the behavior for traversing the file system tree structure and handles the changes of state. It contains the current active drive/volume, traversing history, and handles the race condition cases.

func NewNavigation

func NewNavigation(t *structure.Tree) *Navigation

func NewRootNavigation added in v0.1.1

func NewRootNavigation(t *structure.Tree) (*Navigation, error)

NewRootNavigation creates navigation for a predefined root directory entry. It starts the blocking traversal immediately rather than in interactive mode. Therefore, a root with a wide subdirectory structure might cause a delay.

func (n *Navigation) Delete(path string) error

Delete deletes the file or directory, including all internal content, from the file system by the provided base path value. The entry lookup will be done within the current active *Entry instance, limiting the deletion scope.

If the entry was not found in the current active *Entry instance no error will be returned.

TODO: add soft delete

func (n *Navigation) Down(path string, cursor int, ocl OnChangeLevel) (chan struct{}, chan error)

Down changes the current tree level down to the provided path. The path value is a directory relative path within the currently active tree node.

It handles two scenarios. The first is changing the level from drives to dirs, and the second is traversing between directories. In the first case, the function will not block execution but instead returns channels for "done" and "errors" that occurred during the drive scan. The client is responsible for listening to the channels and handling the state of scanning. The navigation will be locked until the "done" channel is closed. In the second case, both channels will be returned as nil values, since the scanning is already done.

func (n *Navigation) DrivesList() *drive.List

DrivesList returns the list of drives available on the system. Depending on the specific operating system, some volumes may be filtered. Refer to the corresponding drive.List implementation for details.

func (n *Navigation) Entry() *structure.Entry

Entry returns the current active *structure.Entry instance. It never returns an instance of a file, but only a directory.

func (n *Navigation) Explore(path string) error
func (n *Navigation) OnDrives() bool

OnDrives checks whether the current navigation state is Drives or not.

func (n *Navigation) ParentSize() int64
func (n *Navigation) RefreshDrives()

RefreshDrives refreshes the list of the available drives and their memory usage data.

func (n *Navigation) RefreshEntry() (chan struct{}, chan error, error)

RefreshEntry refreshes the current *Entry root by scanning its structure and updating the navigation state. The function will check the case when the current root has been deleted and tries to fall back to the previous *Entry in the stack. If all entries in the stack do not exist anymore, the navigation will fall back to the drives list.

The navigation will be locked until the scanning is complete and the "done" channel is closed.

func (n *Navigation) SetCursor(cursor int)

SetCursor preserves the current position of the table's cursor. The cursor position should be updated on each action and used during rendering.

func (n *Navigation) Up(ocl OnChangeLevel)

Up changes the current tree level up to the previous one. It doesn't accept the target level but instead takes it from navigation history. The Up function will change the level only if the current state is Dirs and will do nothing in case of the Drives state.

If the navigation is currently locked, the function will do nothing and return immediately without an error.

type OnChangeLevel added in v0.1.1

type OnChangeLevel func(e *structure.Entry, s State)

OnChangeLevel defines a custom type for a function being called on changing the current tree level. It accepts the current active entry instance and the navigation's state: Drives or Dirs.

type RawChartSector added in v0.1.3

type RawChartSector struct {
	Label string
	Size  int64
}

type ScanFinished added in v0.1.1

type ScanFinished struct{}

type SortState

type SortState struct {
	Key  drive.SortKey
	Desc bool
}

type State

type State int

State defines a custom type representing the current GUI state. The application's behavior depends on the current state value.

const (
	// Drives defines an application state while selecting the target drive.
	Drives State = iota

	// Dirs defines an application state while traversing a specific drive for
	// its files and directories.
	Dirs
)

type StatusBarColors added in v0.2.0

type StatusBarColors struct {
	Text      string                `json:"text"`
	BlockText string                `json:"blockText"`
	BG        string                `json:"background"`
	VersionBG string                `json:"versionBackground"`
	Drives    DrivesStatusBarColors `json:"drives"`
	Dirs      DirsStatusBarColors   `json:"dirs"`
}

type Style added in v0.2.0

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

func InitStyle added in v0.2.0

func InitStyle(cs ColorSchema) *Style

func (*Style) ActiveButton added in v0.2.0

func (s *Style) ActiveButton() *lipgloss.Style

func (*Style) BarBlock added in v0.2.0

func (s *Style) BarBlock(bgColor lipgloss.Color) lipgloss.Style

func (*Style) BindKey added in v0.2.0

func (s *Style) BindKey() *lipgloss.Style

func (*Style) CS added in v0.2.0

func (s *Style) CS() *ColorSchema

func (*Style) ChartBox added in v0.2.0

func (s *Style) ChartBox() *lipgloss.Style

func (*Style) ChartColors added in v0.2.0

func (s *Style) ChartColors() []lipgloss.Color

func (*Style) ConfirmButton added in v0.2.0

func (s *Style) ConfirmButton() *lipgloss.Style

func (*Style) DialogBox added in v0.2.0

func (s *Style) DialogBox() *lipgloss.Style

func (*Style) Help added in v0.2.0

func (s *Style) Help() *lipgloss.Style

func (*Style) SelectedRow added in v0.2.0

func (s *Style) SelectedRow() *lipgloss.Style

func (*Style) StatusBar added in v0.2.0

func (s *Style) StatusBar() *lipgloss.Style

func (*Style) TableHeader added in v0.2.0

func (s *Style) TableHeader() *lipgloss.Style

func (*Style) TopFiles added in v0.2.0

func (s *Style) TopFiles() *lipgloss.Style

func (*Style) TopTableHeader added in v0.2.0

func (s *Style) TopTableHeader() *lipgloss.Style

type UpdateDirState added in v0.1.1

type UpdateDirState struct{}

type ViewModel

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

func NewViewModel

func NewViewModel(n *Navigation, driveModel *DriveModel, dirMode *DirModel) *ViewModel

func (*ViewModel) Init

func (vm *ViewModel) Init() tea.Cmd

func (*ViewModel) Update

func (vm *ViewModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*ViewModel) View

func (vm *ViewModel) View() string

Jump to

Keyboard shortcuts

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