interactive

package
v0.0.0-debug-20260702 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionHandler

type ActionHandler interface {
	OnSelect(rowIdx int) tea.Cmd                // Enter key
	OnBack() tea.Cmd                            // ESC/b key
	OnCustomKey(key string) tea.Cmd             // Other keys
	MatchRow(row []string, query string) bool   // For search
	FilterRow(row []string, filter string) bool // For filter
}

ActionHandler handles page actions (行为接口) 实现这个接口就可以定制页面行为

type BaseRenderer

type BaseRenderer struct {
	// Data
	Headers []string
	Rows    [][]string
	RowNums []string // Custom row numbers (optional, e.g., "(0-0)")

	// Basic options
	ShowBorder    bool
	ShowRowNumber bool
	RowNumLabel   string
	MaxColWidth   int

	// Pagination (which rows to show)
	StartRow int
	EndRow   int // 0 means all

	// Row number offset (for display, e.g., showing rows 10-20 as "10, 11, 12...")
	RowNumOffset int

	// Horizontal scroll - column-based (which columns to show)
	HScrollOffset  int // Starting column index
	MaxVisibleCols int // Max columns to display (0 = all)

	// Decorators - add features without modifying base
	RowDecorators []RowDecorator

	// Selected row (for decorators to use)
	SelectedRow int
	// contains filtered or unexported fields
}

BaseRenderer is the lowest level table renderer It only knows how to draw a table with borders All features (cursor, search, filter) are added via decorators and options

func NewBaseRenderer

func NewBaseRenderer() *BaseRenderer

NewBaseRenderer creates a minimal renderer

func (*BaseRenderer) Render

func (r *BaseRenderer) Render() string

Render renders the table

type DataProvider

type DataProvider interface {
	GetRows() [][]string
	GetRowNums() []string // Optional custom row numbers (nil = auto)
	GetOverview() string  // Dynamic overview line
}

DataProvider provides data for a page (数据源接口) 实现这个接口就可以接入任何数据源

type DefaultHandler

type DefaultHandler struct {
	OnSelectFunc    func(rowIdx int) tea.Cmd
	OnBackFunc      func() tea.Cmd
	OnCustomKeyFunc func(key string) tea.Cmd
}

DefaultHandler provides default implementations for common behaviors 大多数页面可以嵌入这个,只覆盖需要定制的方法

func (*DefaultHandler) FilterRow

func (h *DefaultHandler) FilterRow(row []string, filter string) bool

FilterRow default: same as MatchRow

func (*DefaultHandler) MatchRow

func (h *DefaultHandler) MatchRow(row []string, query string) bool

MatchRow default: case-insensitive substring match on all columns

func (*DefaultHandler) OnBack

func (h *DefaultHandler) OnBack() tea.Cmd

func (*DefaultHandler) OnCustomKey

func (h *DefaultHandler) OnCustomKey(key string) tea.Cmd

func (*DefaultHandler) OnSelect

func (h *DefaultHandler) OnSelect(rowIdx int) tea.Cmd

type GenericList

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

GenericList wraps BaseRenderer with cursor, scroll, search, filter This is the "building block" layer on top of BaseRenderer

func NewGenericList

func NewGenericList(opts ListOptions) *GenericList

NewGenericList creates a GenericList with options

func (*GenericList) ClearFilter

func (v *GenericList) ClearFilter()

func (*GenericList) ClearSearch

func (v *GenericList) ClearSearch()

func (*GenericList) GetCursor

func (v *GenericList) GetCursor() int

func (*GenericList) GetHScroll

func (v *GenericList) GetHScroll() int

func (*GenericList) GetLastSearch

func (v *GenericList) GetLastSearch() string

GetLastSearch returns last search query

func (*GenericList) GetSearchHistory

func (v *GenericList) GetSearchHistory() []string

GetSearchHistory returns search history

func (*GenericList) GetStatus

func (v *GenericList) GetStatus() string

GetStatus returns status line info

func (*GenericList) GoBottom

func (v *GenericList) GoBottom()

func (*GenericList) GoTop

func (v *GenericList) GoTop()

func (*GenericList) HistoryDown

func (v *GenericList) HistoryDown() string

HistoryDown moves to next history entry

func (*GenericList) HistoryReset

func (v *GenericList) HistoryReset()

HistoryReset resets history index

func (*GenericList) HistoryUp

func (v *GenericList) HistoryUp() string

HistoryUp moves to previous history entry

func (*GenericList) IsFiltered

func (v *GenericList) IsFiltered() bool

func (*GenericList) MatchCount

func (v *GenericList) MatchCount() int

func (*GenericList) MoveDown

func (v *GenericList) MoveDown()

func (*GenericList) MoveUp

func (v *GenericList) MoveUp()

func (*GenericList) NextMatch

func (v *GenericList) NextMatch()

func (*GenericList) PageDown

func (v *GenericList) PageDown()

func (*GenericList) PageUp

func (v *GenericList) PageUp()

func (*GenericList) PrevMatch

func (v *GenericList) PrevMatch()

func (*GenericList) Render

func (v *GenericList) Render() string

func (*GenericList) ScrollLeft

func (v *GenericList) ScrollLeft()

func (*GenericList) ScrollRight

func (v *GenericList) ScrollRight()

func (*GenericList) Search

func (v *GenericList) Search(query string, matchFn func(row []string, query string) bool)

func (*GenericList) SetCursor

func (v *GenericList) SetCursor(pos int)

func (*GenericList) SetData

func (v *GenericList) SetData(rows [][]string)

SetData sets the data rows

func (*GenericList) SetDataWithRowNums

func (v *GenericList) SetDataWithRowNums(rows [][]string, rowNums []string)

SetDataWithRowNums sets data with custom row numbers

func (*GenericList) SetFilter

func (v *GenericList) SetFilter(filterFn func(row []string) bool, info string)

func (*GenericList) SetHScroll

func (v *GenericList) SetHScroll(offset int)

func (*GenericList) SetScreenHeight

func (v *GenericList) SetScreenHeight(h int)

SetScreenHeight sets available screen height

func (*GenericList) SetScreenWidth

func (v *GenericList) SetScreenWidth(w int)

SetScreenWidth sets available screen width

func (*GenericList) TotalRows

func (v *GenericList) TotalRows() int

TotalRows returns total row count

type GenericPage

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

GenericPage is the highest level component All pages use this: just provide config + data + handler

Example

=== Example: How checkpoint list would use this ===

// This is how checkpoint list would be implemented:
//
// config := PageConfig{
//     Title:         "═══ Checkpoint Viewer ═══",
//     Headers:       []string{"Type", "Start", "End", "State", "Version", "LSN"},
//     Overview:      fmt.Sprintf("Dir: %s │ Total: %d entries", dir, count),
//     ShowRowNumber: true,
//     EnableCursor:  true,
//     EnableSearch:  false,  // Checkpoints don't need search
//     EnableBack:    false,  // This is the root page
// }
//
// provider := &CheckpointDataProvider{reader: reader}
// handler := &CheckpointActionHandler{onSelect: func(idx int) { ... }}
//
// page := NewGenericPage(config, provider, handler)

fmt.Println("See TestGenericPageUsage for working example")
Output:
See TestGenericPageUsage for working example

func NewGenericPage

func NewGenericPage(config PageConfig, provider DataProvider, handler ActionHandler) *GenericPage

NewGenericPage creates a page with config

func (*GenericPage) GetCursor

func (p *GenericPage) GetCursor() int

GetCursor returns current cursor position

func (*GenericPage) GetSelectedRow

func (p *GenericPage) GetSelectedRow() []string

GetSelectedRow returns the row at cursor

func (*GenericPage) GetVisibleRows

func (p *GenericPage) GetVisibleRows() [][]string

GetVisibleRows returns all visible rows

func (*GenericPage) Init

func (p *GenericPage) Init() tea.Cmd

func (*GenericPage) Refresh

func (p *GenericPage) Refresh()

Refresh reloads data from provider

func (*GenericPage) SetSize

func (p *GenericPage) SetSize(w, h int)

SetSize sets terminal size

func (*GenericPage) Update

func (p *GenericPage) Update(msg tea.Msg) (*GenericPage, tea.Cmd)

func (*GenericPage) View

func (p *GenericPage) View() string

type HistoryManager

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

HistoryManager manages command/search history

func NewHistoryManager

func NewHistoryManager(maxSize int) *HistoryManager

NewHistoryManager creates a new history manager

func (*HistoryManager) Add

func (h *HistoryManager) Add(entry string)

Add adds an entry to history

func (*HistoryManager) Down

func (h *HistoryManager) Down() string

Down moves to next history entry

func (*HistoryManager) GetAll

func (h *HistoryManager) GetAll() []string

GetAll returns all history entries

func (*HistoryManager) LoadFromFile

func (h *HistoryManager) LoadFromFile(filename string) error

LoadFromFile loads history from a file

func (*HistoryManager) Reset

func (h *HistoryManager) Reset()

Reset resets the index to the end

func (*HistoryManager) SaveToFile

func (h *HistoryManager) SaveToFile(filename string) error

SaveToFile saves history to a file

func (*HistoryManager) Up

func (h *HistoryManager) Up() string

Up moves to previous history entry

type ListOptions

type ListOptions struct {
	// Display
	Headers       []string
	ShowRowNumber bool
	MaxColWidth   int

	// Features (enable/disable)
	EnableCursor bool
	EnableSearch bool
	EnableFilter bool

	// Pagination
	PageSize int
}

ListOptions configures GenericList behavior (搭积木)

type PageConfig

type PageConfig struct {
	// Content
	Title   string   // Page title
	Headers []string // Table headers

	// Features (enable/disable)
	ShowRowNumber bool
	RowNumLabel   string // Row number column label (default: "#")
	EnableCursor  bool
	EnableSearch  bool
	EnableFilter  bool
	EnableBack    bool // Show back hint
	EnableHScroll bool // Horizontal scroll

	// Display
	MaxColWidth int

	// Hints (auto-generated if empty)
	CustomHints string
}

PageConfig defines what features a page has (搭积木配置)

type RowDecorator

type RowDecorator func(rowIdx int, isSelected bool) (prefix, suffix string)

RowDecorator adds prefix/suffix to rows (cursor, search highlight, etc.)

func CurrentMatchHighlightDecorator

func CurrentMatchHighlightDecorator(currentMatchRow int) RowDecorator

CurrentMatchHighlightDecorator highlights the current match row with color

func CursorDecorator

func CursorDecorator() RowDecorator

CursorDecorator adds "▶" prefix to selected row

func SearchHighlightDecorator

func SearchHighlightDecorator(matches map[int]bool) RowDecorator

SearchHighlightDecorator adds "*" to matching rows

Jump to

Keyboard shortcuts

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