MCPcopy
hub / github.com/ddworken/hishtory / makeTable

Function makeTable

client/tui/tui.go:692–817  ·  view source on GitHub ↗
(ctx context.Context, shellName string, rows []table.Row)

Source from the content-addressed store, hash-verified

690}
691
692func makeTable(ctx context.Context, shellName string, rows []table.Row) (table.Model, error) {
693 config := hctx.GetConf(ctx)
694 columns, err := makeTableColumns(ctx, shellName, config.DisplayedColumns, rows)
695 if err != nil {
696 return table.Model{}, err
697 }
698 km := table.KeyMap{
699 LineUp: loadedKeyBindings.Up,
700 LineDown: loadedKeyBindings.Down,
701 PageUp: loadedKeyBindings.PageUp,
702 PageDown: loadedKeyBindings.PageDown,
703 GotoTop: key.NewBinding(
704 key.WithKeys("home"),
705 key.WithHelp("home", "go to start"),
706 ),
707 GotoBottom: key.NewBinding(
708 key.WithKeys("end"),
709 key.WithHelp("end", "go to end"),
710 ),
711 MoveLeft: loadedKeyBindings.TableLeft,
712 MoveRight: loadedKeyBindings.TableRight,
713 }
714 _, terminalHeight, err := getTerminalSize()
715 if err != nil {
716 return table.Model{}, err
717 }
718 tuiSize := 12
719 if isCompactHeightMode(ctx) {
720 tuiSize -= 2
721 }
722 if isExtraCompactHeightMode(ctx) {
723 tuiSize -= 3
724 }
725 tableHeight := min(getTableHeight(ctx), terminalHeight-tuiSize)
726 t := table.New(
727 table.WithColumns(columns),
728 table.WithRows(rows),
729 table.WithFocused(true),
730 table.WithHeight(tableHeight),
731 table.WithKeyMap(km),
732 )
733
734 s := table.DefaultStyles()
735 s.Header = s.Header.
736 BorderStyle(lipgloss.NormalBorder()).
737 BorderForeground(lipgloss.Color(config.ColorScheme.BorderColor)).
738 BorderBottom(true).
739 Bold(false)
740 s.Selected = s.Selected.
741 Foreground(lipgloss.Color(config.ColorScheme.SelectedText)).
742 Background(lipgloss.Color(config.ColorScheme.SelectedBackground)).
743 Bold(false)
744 if config.HighlightMatches {
745 MATCH_NOTHING_REGEXP := regexp.MustCompile("a^")
746 s.RenderCell = func(model table.Model, value string, position table.CellPosition) string {
747 var re *regexp.Regexp
748 CURRENT_QUERY_FOR_HIGHLIGHTING = strings.TrimSpace(CURRENT_QUERY_FOR_HIGHLIGHTING)
749 if CURRENT_QUERY_FOR_HIGHLIGHTING == "" {

Callers 1

updateTableFunction · 0.85

Calls 15

GetConfFunction · 0.92
NewFunction · 0.92
WithColumnsFunction · 0.92
WithRowsFunction · 0.92
WithFocusedFunction · 0.92
WithHeightFunction · 0.92
WithKeyMapFunction · 0.92
DefaultStylesFunction · 0.92
MakeRegexFromQueryFunction · 0.92
GetLoggerFunction · 0.92
makeTableColumnsFunction · 0.85
getTerminalSizeFunction · 0.85

Tested by

no test coverage detected