Documentation
¶
Index ¶
- type ActionHandler
- type BaseRenderer
- type DataProvider
- type DefaultHandler
- type GenericList
- func (v *GenericList) ClearFilter()
- func (v *GenericList) ClearSearch()
- func (v *GenericList) GetCursor() int
- func (v *GenericList) GetHScroll() int
- func (v *GenericList) GetLastSearch() string
- func (v *GenericList) GetSearchHistory() []string
- func (v *GenericList) GetStatus() string
- func (v *GenericList) GoBottom()
- func (v *GenericList) GoTop()
- func (v *GenericList) HistoryDown() string
- func (v *GenericList) HistoryReset()
- func (v *GenericList) HistoryUp() string
- func (v *GenericList) IsFiltered() bool
- func (v *GenericList) MatchCount() int
- func (v *GenericList) MoveDown()
- func (v *GenericList) MoveUp()
- func (v *GenericList) NextMatch()
- func (v *GenericList) PageDown()
- func (v *GenericList) PageUp()
- func (v *GenericList) PrevMatch()
- func (v *GenericList) Render() string
- func (v *GenericList) ScrollLeft()
- func (v *GenericList) ScrollRight()
- func (v *GenericList) Search(query string, matchFn func(row []string, query string) bool)
- func (v *GenericList) SetCursor(pos int)
- func (v *GenericList) SetData(rows [][]string)
- func (v *GenericList) SetDataWithRowNums(rows [][]string, rowNums []string)
- func (v *GenericList) SetFilter(filterFn func(row []string) bool, info string)
- func (v *GenericList) SetHScroll(offset int)
- func (v *GenericList) SetScreenHeight(h int)
- func (v *GenericList) SetScreenWidth(w int)
- func (v *GenericList) TotalRows() int
- type GenericPage
- func (p *GenericPage) GetCursor() int
- func (p *GenericPage) GetSelectedRow() []string
- func (p *GenericPage) GetVisibleRows() [][]string
- func (p *GenericPage) Init() tea.Cmd
- func (p *GenericPage) Refresh()
- func (p *GenericPage) SetSize(w, h int)
- func (p *GenericPage) Update(msg tea.Msg) (*GenericPage, tea.Cmd)
- func (p *GenericPage) View() string
- type HistoryManager
- func (h *HistoryManager) Add(entry string)
- func (h *HistoryManager) Down() string
- func (h *HistoryManager) GetAll() []string
- func (h *HistoryManager) LoadFromFile(filename string) error
- func (h *HistoryManager) Reset()
- func (h *HistoryManager) SaveToFile(filename string) error
- func (h *HistoryManager) Up() string
- type ListOptions
- type PageConfig
- type RowDecorator
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
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
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) 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) SaveToFile ¶
func (h *HistoryManager) SaveToFile(filename string) error
SaveToFile saves history to a file
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 ¶
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