Documentation
¶
Index ¶
- func CommandSortFuncDynamic[ElementType resource.Identifiable, FieldType string](getState func() *State[ElementType, FieldType]) func(i, j ElementType) int
- func CompareID[ElementType resource.Identifiable](i, j ElementType) int
- func CompareInt(i, j int) int
- func CompareTime(t1, t2 time.Time) int
- func UpdateBindings[ElementType resource.Identifiable, FieldType string](k *KeyMap, state *State[ElementType, FieldType])
- type CompareBySortFieldFunc
- type Direction
- type EditorSortStylesInterface
- type Field
- type KeyMap
- type Msg
- type MsgSortEditModeChanged
- type Option
- type SelectedField
- type State
- func (state *State[ElementType, FieldType]) FixDuplicateSortKey()
- func (state *State[ElementType, FieldType]) Init() tea.Cmd
- func (state *State[ElementType, FieldType]) Update(msg tea.Msg) (cmd tea.Cmd, forward bool)
- func (state *State[ElementType, FieldType]) UpdateDirectionField(option *Option[FieldType], direction Direction)
- func (state *State[ElementType, FieldType]) UpdateSortField(option *Option[FieldType], direction Direction)
- func (state *State[ElementType, FieldType]) View() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CommandSortFuncDynamic ¶
func CommandSortFuncDynamic[ElementType resource.Identifiable, FieldType string]( getState func() *State[ElementType, FieldType], ) func(i, j ElementType) int
CommandSortFuncDynamic returns a sort function that dynamically gets the sort state from a getter function whenever sorting is performed. This ensures the sort always uses the current sort state rather than a cached state.
func CompareID ¶
func CompareID[ElementType resource.Identifiable](i, j ElementType) int
func CompareInt ¶
func UpdateBindings ¶
func UpdateBindings[ElementType resource.Identifiable, FieldType string]( k *KeyMap, state *State[ElementType, FieldType], )
Types ¶
type CompareBySortFieldFunc ¶
type CompareBySortFieldFunc[ElementType resource.Identifiable, FieldType string] func( i, j ElementType, field FieldType, ) int
type Direction ¶
type Direction string
Direction represents the direction of sorting
func GetDirectionOptions ¶
func GetDirectionOptions() []Direction
GetDirectionOptions returns the available sort direction options
type KeyMap ¶
type KeyMap struct {
Sort *key.Binding
Apply *key.Binding
Cancel *key.Binding
NextField *key.Binding
PreviousField *key.Binding
NextComboValue *key.Binding
PreviousComboValue *key.Binding
}
KeyMap contains keybindings for sort mode
func GetDefaultKeyMap ¶
func GetDefaultKeyMap() *KeyMap
GetDefaultKeyMap returns the default sort key mapping
type Msg ¶
type Msg[ElementType resource.Identifiable, FieldType string] struct { State *State[ElementType, FieldType] InfoMsg *tui.InfoMsg }
Msg is sent when sorting is applied
type MsgSortEditModeChanged ¶
type MsgSortEditModeChanged[ElementType resource.Identifiable, FieldType string] struct { State *State[ElementType, FieldType] }
type SelectedField ¶
type SelectedField int
const ( SelectedFieldPrimaryField SelectedField = iota // Primary sort field SelectedFieldPrimaryDirection // Primary sort direction SelectedFieldSecondaryField // Secondary sort field SelectedFieldSecondaryDirection // Secondary sort direction )
type State ¶
type State[ElementType resource.Identifiable, FieldType string] struct { EditorSortStyles EditorSortStylesInterface IDField FieldType PrimarySort *Option[FieldType] SecondarySort *Option[FieldType] CompareBySortField CompareBySortFieldFunc[ElementType, FieldType] KeyMap *KeyMap Fields []FieldType SelectedField SelectedField // Currently selected field IsEditActive bool // Whether sort edit mode is active }
State contains the current sort configuration
func NewDefaultState ¶
func NewDefaultState[ElementType resource.Identifiable, FieldType string]( editorStyles EditorSortStylesInterface, idField FieldType, fields []FieldType, keyMap *KeyMap, compareBySortFieldFunc CompareBySortFieldFunc[ElementType, FieldType], ) *State[ElementType, FieldType]
NewDefaultState creates a new default sort state
func (*State[ElementType, FieldType]) FixDuplicateSortKey ¶
func (state *State[ElementType, FieldType]) FixDuplicateSortKey()
func (*State[ElementType, FieldType]) UpdateDirectionField ¶
func (*State[ElementType, FieldType]) UpdateSortField ¶
Click to show internal directories.
Click to hide internal directories.