mirror of
https://github.com/ddworken/hishtory.git
synced 2024-12-27 09:18:55 +01:00
add forceComapctMode config entry (#237)
This commit is contained in:
parent
9b8baa8274
commit
ad8775c334
@ -210,6 +210,18 @@ var setColorSchemeBorderColor = &cobra.Command{
|
||||
},
|
||||
}
|
||||
|
||||
var toggleCompactMode = &cobra.Command{
|
||||
Use: "toggle-compact-mode",
|
||||
Short: "Toggle compact mode switching it on or off",
|
||||
Args: cobra.ExactArgs(0),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
ctx := hctx.MakeContext()
|
||||
config := hctx.GetConf(ctx)
|
||||
config.ForceCompactMode = !config.ForceCompactMode
|
||||
lib.CheckFatalError(hctx.SetConfig(config))
|
||||
},
|
||||
}
|
||||
|
||||
func validateColor(color string) error {
|
||||
if !strings.HasPrefix(color, "#") || len(color) != 7 {
|
||||
return fmt.Errorf("color %q is invalid, it should be a hexadecimal color like #663399", color)
|
||||
@ -242,6 +254,7 @@ func init() {
|
||||
configSetCmd.AddCommand(setColorSchemeCmd)
|
||||
configSetCmd.AddCommand(setDefaultFilterCommand)
|
||||
configSetCmd.AddCommand(setAiCompletionEndpoint)
|
||||
configSetCmd.AddCommand(toggleCompactMode)
|
||||
setColorSchemeCmd.AddCommand(setColorSchemeSelectedText)
|
||||
setColorSchemeCmd.AddCommand(setColorSchemeSelectedBackground)
|
||||
setColorSchemeCmd.AddCommand(setColorSchemeBorderColor)
|
||||
|
@ -189,6 +189,8 @@ type ClientConfig struct {
|
||||
// Custom columns
|
||||
CustomColumns []CustomColumnDefinition `json:"custom_columns"`
|
||||
// Whether this is an offline instance of hishtory with no syncing
|
||||
ForceCompactMode bool `json:"force_compact_mode"`
|
||||
// Whether this is an offline instance of hishtory with no syncing
|
||||
IsOffline bool `json:"is_offline"`
|
||||
// Whether duplicate commands should be displayed
|
||||
FilterDuplicateCommands bool `json:"filter_duplicate_commands"`
|
||||
|
@ -94,6 +94,9 @@ type model struct {
|
||||
|
||||
// The currently executing shell. Defaults to bash if not specified. Used for more precise AI suggestions.
|
||||
shellName string
|
||||
|
||||
// Compacting TUI config
|
||||
compactTUIflag bool
|
||||
}
|
||||
|
||||
type doneDownloadingMsg struct{}
|
||||
@ -122,7 +125,8 @@ func initialModel(ctx context.Context, shellName, initialQuery string) model {
|
||||
s.Spinner = spinner.Dot
|
||||
s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("205"))
|
||||
queryInput := textinput.New()
|
||||
defaultFilter := hctx.GetConf(ctx).DefaultFilter
|
||||
cfg := hctx.GetConf(ctx)
|
||||
defaultFilter := cfg.DefaultFilter
|
||||
if defaultFilter != "" {
|
||||
queryInput.Prompt = "[" + defaultFilter + "] "
|
||||
}
|
||||
@ -143,7 +147,7 @@ func initialModel(ctx context.Context, shellName, initialQuery string) model {
|
||||
queryInput.SetValue(initialQuery)
|
||||
}
|
||||
CURRENT_QUERY_FOR_HIGHLIGHTING = initialQuery
|
||||
return model{ctx: ctx, spinner: s, isLoading: true, table: nil, tableEntries: []*data.HistoryEntry{}, runQuery: &initialQuery, queryInput: queryInput, help: help.New(), shellName: shellName}
|
||||
return model{ctx: ctx, spinner: s, isLoading: true, table: nil, tableEntries: []*data.HistoryEntry{}, runQuery: &initialQuery, queryInput: queryInput, help: help.New(), shellName: shellName, compactTUIflag: cfg.ForceCompactMode}
|
||||
}
|
||||
|
||||
func (m model) Init() tea.Cmd {
|
||||
@ -395,15 +399,15 @@ func (m model) View() string {
|
||||
additionalMessages = append(additionalMessages, fmt.Sprintf("%s Executing search query...", m.spinner.View()))
|
||||
}
|
||||
additionalMessagesStr := strings.Join(additionalMessages, "\n") + "\n"
|
||||
if isExtraCompactHeightMode() {
|
||||
if isExtraCompactHeightMode() || m.compactTUIflag {
|
||||
additionalMessagesStr = "\n"
|
||||
}
|
||||
helpView := m.help.View(loadedKeyBindings)
|
||||
if isExtraCompactHeightMode() {
|
||||
if isExtraCompactHeightMode() || m.compactTUIflag {
|
||||
helpView = ""
|
||||
}
|
||||
additionalSpacing := "\n"
|
||||
if isCompactHeightMode() {
|
||||
if isCompactHeightMode() || m.compactTUIflag {
|
||||
additionalSpacing = ""
|
||||
}
|
||||
return fmt.Sprintf("%s%s%s%sSearch Query: %s\n%s%s\n", additionalSpacing, additionalMessagesStr, m.banner, additionalSpacing, m.queryInput.View(), additionalSpacing, renderNullableTable(m, helpView)) + helpView
|
||||
|
Loading…
Reference in New Issue
Block a user