diff --git a/client/lib/lib.go b/client/lib/lib.go index 426dcd8..ebbb077 100644 --- a/client/lib/lib.go +++ b/client/lib/lib.go @@ -157,19 +157,25 @@ func DisplayResults(ctx context.Context, results []*data.HistoryEntry, numResult tbl := table.New(columns...) tbl.WithHeaderFormatter(headerFmt) - lastCommand := "" numRows := 0 + + var seenCommands = make(map[string]bool) + for _, entry := range results { - if entry != nil && strings.TrimSpace(entry.Command) == strings.TrimSpace(lastCommand) && config.FilterDuplicateCommands { - continue + if config.FilterDuplicateCommands && entry != nil { + cmd := strings.TrimSpace(entry.Command) + if seenCommands[cmd] { + continue + } + seenCommands[cmd] = true } + row, err := BuildTableRow(ctx, config.DisplayedColumns, *entry) if err != nil { return err } tbl.AddRow(stringArrayToAnyArray(row)...) numRows += 1 - lastCommand = entry.Command if numRows >= numResults { break } diff --git a/client/tui/tui.go b/client/tui/tui.go index 8b8f3a6..a498666 100644 --- a/client/tui/tui.go +++ b/client/tui/tui.go @@ -498,13 +498,20 @@ func getRows(ctx context.Context, columnNames []string, query string, numEntries } var rows []table.Row var filteredData []*data.HistoryEntry - lastCommand := "" + var seenCommands = make(map[string]bool) + for i := 0; i < numEntries; i++ { if i < len(searchResults) { entry := searchResults[i] - if strings.TrimSpace(entry.Command) == strings.TrimSpace(lastCommand) && config.FilterDuplicateCommands { - continue + + if config.FilterDuplicateCommands && entry != nil { + cmd := strings.TrimSpace(entry.Command) + if seenCommands[cmd] { + continue + } + seenCommands[cmd] = true } + entry.Command = strings.ReplaceAll(entry.Command, "\n", "\\n") row, err := lib.BuildTableRow(ctx, columnNames, *entry) if err != nil { @@ -512,7 +519,6 @@ func getRows(ctx context.Context, columnNames []string, query string, numEntries } rows = append(rows, row) filteredData = append(filteredData, entry) - lastCommand = entry.Command } else { rows = append(rows, table.Row{}) }