mirror of
https://github.com/ddworken/hishtory.git
synced 2025-06-21 04:17:45 +02:00
Bold matches for search queries in TUI for #112. This was previously available behind the beta-mode flag, but will now be enabled by default
This commit is contained in:
parent
d5b896e4f2
commit
253ad7f6b6
@ -1692,7 +1692,6 @@ func testTui_scroll(t testing.TB) {
|
|||||||
|
|
||||||
// Assert there are no leaked connections
|
// Assert there are no leaked connections
|
||||||
assertNoLeakedConnections(t)
|
assertNoLeakedConnections(t)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testTui_color(t testing.TB) {
|
func testTui_color(t testing.TB) {
|
||||||
@ -1705,6 +1704,7 @@ func testTui_color(t testing.TB) {
|
|||||||
// Setup
|
// Setup
|
||||||
defer testutils.BackupAndRestore(t)()
|
defer testutils.BackupAndRestore(t)()
|
||||||
tester, _, _ := setupTestTui(t)
|
tester, _, _ := setupTestTui(t)
|
||||||
|
tester.RunInteractiveShell(t, ` hishtory config-set highlight-matches false`)
|
||||||
|
|
||||||
// Capture the TUI with full colored output, note that this golden will be harder to undersand
|
// Capture the TUI with full colored output, note that this golden will be harder to undersand
|
||||||
// from inspection and primarily servers to detect unintended changes in hishtory's output.
|
// from inspection and primarily servers to detect unintended changes in hishtory's output.
|
||||||
@ -1717,9 +1717,9 @@ func testTui_color(t testing.TB) {
|
|||||||
out = strings.TrimSpace(strings.Split(out, "hishtory tquery")[1])
|
out = strings.TrimSpace(strings.Split(out, "hishtory tquery")[1])
|
||||||
testutils.CompareGoldens(t, out, "TestTui-ColoredOutputWithSearch")
|
testutils.CompareGoldens(t, out, "TestTui-ColoredOutputWithSearch")
|
||||||
|
|
||||||
// And one more time with beta-mode for highlighting matches
|
// And one more time with highlight-matches
|
||||||
tester.RunInteractiveShell(t, ` hishtory config-set beta-mode true`)
|
tester.RunInteractiveShell(t, ` hishtory config-set highlight-matches true`)
|
||||||
require.Equal(t, "true", strings.TrimSpace(tester.RunInteractiveShell(t, `hishtory config-get beta-mode`)))
|
require.Equal(t, "true", strings.TrimSpace(tester.RunInteractiveShell(t, `hishtory config-get highlight-matches`)))
|
||||||
out = captureTerminalOutputComplex(t, TmuxCaptureConfig{tester: tester, complexCommands: []TmuxCommand{{Keys: "hishtory SPACE tquery ENTER"}, {Keys: "ech"}}, includeEscapeSequences: true})
|
out = captureTerminalOutputComplex(t, TmuxCaptureConfig{tester: tester, complexCommands: []TmuxCommand{{Keys: "hishtory SPACE tquery ENTER"}, {Keys: "ech"}}, includeEscapeSequences: true})
|
||||||
out = strings.TrimSpace(strings.Split(out, "hishtory tquery")[1])
|
out = strings.TrimSpace(strings.Split(out, "hishtory tquery")[1])
|
||||||
testutils.CompareGoldens(t, out, "TestTui-ColoredOutputWithSearch-BetaMode")
|
testutils.CompareGoldens(t, out, "TestTui-ColoredOutputWithSearch-BetaMode")
|
||||||
|
@ -30,6 +30,16 @@ var getEnableControlRCmd = &cobra.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var getHighlightMatchesCmd = &cobra.Command{
|
||||||
|
Use: "highlight-matches",
|
||||||
|
Short: "Whether hishtory highlights matches in the search results",
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
ctx := hctx.MakeContext()
|
||||||
|
config := hctx.GetConf(ctx)
|
||||||
|
fmt.Println(config.HighlightMatches)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
var getFilterDuplicateCommandsCmd = &cobra.Command{
|
var getFilterDuplicateCommandsCmd = &cobra.Command{
|
||||||
Use: "filter-duplicate-commands",
|
Use: "filter-duplicate-commands",
|
||||||
Short: "Whether hishtory filters out duplicate commands when displaying your history",
|
Short: "Whether hishtory filters out duplicate commands when displaying your history",
|
||||||
@ -98,4 +108,5 @@ func init() {
|
|||||||
configGetCmd.AddCommand(getTimestampFormatCmd)
|
configGetCmd.AddCommand(getTimestampFormatCmd)
|
||||||
configGetCmd.AddCommand(getCustomColumnsCmd)
|
configGetCmd.AddCommand(getCustomColumnsCmd)
|
||||||
configGetCmd.AddCommand(getBetaModeCmd)
|
configGetCmd.AddCommand(getBetaModeCmd)
|
||||||
|
configGetCmd.AddCommand(getHighlightMatchesCmd)
|
||||||
}
|
}
|
||||||
|
@ -70,6 +70,23 @@ var setBetaModeCommand = &cobra.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var setHighlightMatchesCmd = &cobra.Command{
|
||||||
|
Use: "highlight-matches",
|
||||||
|
Short: "Enable highlight-matches to enable highlighting of matches in the search results",
|
||||||
|
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
|
||||||
|
ValidArgs: []string{"true", "false"},
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
val := args[0]
|
||||||
|
if val != "true" && val != "false" {
|
||||||
|
log.Fatalf("Unexpected config value %s, must be one of: true, false", val)
|
||||||
|
}
|
||||||
|
ctx := hctx.MakeContext()
|
||||||
|
config := hctx.GetConf(ctx)
|
||||||
|
config.HighlightMatches = (val == "true")
|
||||||
|
lib.CheckFatalError(hctx.SetConfig(config))
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
var setDisplayedColumnsCmd = &cobra.Command{
|
var setDisplayedColumnsCmd = &cobra.Command{
|
||||||
Use: "displayed-columns",
|
Use: "displayed-columns",
|
||||||
Short: "The list of columns that hishtory displays",
|
Short: "The list of columns that hishtory displays",
|
||||||
@ -101,4 +118,5 @@ func init() {
|
|||||||
configSetCmd.AddCommand(setDisplayedColumnsCmd)
|
configSetCmd.AddCommand(setDisplayedColumnsCmd)
|
||||||
configSetCmd.AddCommand(setTimestampFormatCmd)
|
configSetCmd.AddCommand(setTimestampFormatCmd)
|
||||||
configSetCmd.AddCommand(setBetaModeCommand)
|
configSetCmd.AddCommand(setBetaModeCommand)
|
||||||
|
configSetCmd.AddCommand(setHighlightMatchesCmd)
|
||||||
}
|
}
|
||||||
|
@ -185,24 +185,27 @@ func handleDbUpgrades(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handles people running `hishtory update` from an old version of hishtory that
|
// Handles people running `hishtory update` from an old version of hishtory that
|
||||||
// doesn't support the control-r integration, so that they'll get control-r enabled
|
// doesn't support certain config options that we now default to true. This ensures
|
||||||
// but someone who has it explicitly disabled will keep it that way.
|
// that upgrades get them enabled by default, but if someone has it explicitly disabled,
|
||||||
|
// we keep it that way.
|
||||||
func handleUpgradedFeatures() error {
|
func handleUpgradedFeatures() error {
|
||||||
configContents, err := hctx.GetConfigContents()
|
configContents, err := hctx.GetConfigContents()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// No config, so this is a new install and thus there is nothing to do
|
// No config, so this is a new install and thus there is nothing to do
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if strings.Contains(string(configContents), "enable_control_r_search") {
|
|
||||||
// control-r search is already configured, so there is nothing to do
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
// Enable control-r search
|
|
||||||
config, err := hctx.GetConfig()
|
config, err := hctx.GetConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
config.ControlRSearchEnabled = true
|
if !strings.Contains(string(configContents), "enable_control_r_search") {
|
||||||
|
// control-r search is not yet configured, so enable it
|
||||||
|
config.ControlRSearchEnabled = true
|
||||||
|
}
|
||||||
|
if !strings.Contains(string(configContents), "highlight_matches") {
|
||||||
|
// highlighting is not yet configured, so enable it
|
||||||
|
config.HighlightMatches = true
|
||||||
|
}
|
||||||
return hctx.SetConfig(&config)
|
return hctx.SetConfig(&config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,6 +195,8 @@ type ClientConfig struct {
|
|||||||
// Beta mode, enables unspecified additional beta features
|
// Beta mode, enables unspecified additional beta features
|
||||||
// Currently: This enables pre-saving of history entries to better handle long-running commands
|
// Currently: This enables pre-saving of history entries to better handle long-running commands
|
||||||
BetaMode bool `json:"beta_mode"`
|
BetaMode bool `json:"beta_mode"`
|
||||||
|
// Whether to highlight matches in search results
|
||||||
|
HighlightMatches bool `json:"highlight_matches"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CustomColumnDefinition struct {
|
type CustomColumnDefinition struct {
|
||||||
|
@ -583,7 +583,7 @@ func makeTable(ctx context.Context, rows []table.Row) (table.Model, error) {
|
|||||||
Foreground(lipgloss.Color("229")).
|
Foreground(lipgloss.Color("229")).
|
||||||
Background(lipgloss.Color("57")).
|
Background(lipgloss.Color("57")).
|
||||||
Bold(false)
|
Bold(false)
|
||||||
if config.BetaMode {
|
if config.HighlightMatches {
|
||||||
MATCH_NOTHING_REGEXP := regexp.MustCompile("a^")
|
MATCH_NOTHING_REGEXP := regexp.MustCompile("a^")
|
||||||
s.RenderCell = func(model table.Model, value string, position table.CellPosition) string {
|
s.RenderCell = func(model table.Model, value string, position table.CellPosition) string {
|
||||||
var re *regexp.Regexp
|
var re *regexp.Regexp
|
||||||
|
Loading…
x
Reference in New Issue
Block a user