Fix #82 by ensuring that the results list also filters out duplicates

This commit is contained in:
David Dworken 2023-05-16 17:12:52 -07:00
parent 0b13a9705d
commit c0e56eff0d
No known key found for this signature in database
2 changed files with 7 additions and 4 deletions

View File

@ -1790,6 +1790,7 @@ func TestFish(t *testing.T) {
testutils.CompareGoldens(t, out, "TestFish-table")
}
// TODO(ddworken):Add better tests for filtering out entries
// TODO(ddworken): Run TestTui in online and offline mode
func TestTui(t *testing.T) {

View File

@ -307,15 +307,16 @@ func (m model) View() string {
func getRows(ctx *context.Context, columnNames []string, query string, numEntries int) ([]table.Row, []*data.HistoryEntry, error) {
db := hctx.GetDb(ctx)
config := hctx.GetConf(ctx)
data, err := Search(ctx, db, query, numEntries)
searchResults, err := Search(ctx, db, query, numEntries)
if err != nil {
return nil, nil, err
}
var rows []table.Row
var filteredData []*data.HistoryEntry
lastCommand := ""
for i := 0; i < numEntries; i++ {
if i < len(data) {
entry := data[i]
if i < len(searchResults) {
entry := searchResults[i]
if strings.TrimSpace(entry.Command) == strings.TrimSpace(lastCommand) && config.FilterDuplicateCommands {
continue
}
@ -325,12 +326,13 @@ func getRows(ctx *context.Context, columnNames []string, query string, numEntrie
return nil, nil, fmt.Errorf("failed to build row for entry=%#v: %v", entry, err)
}
rows = append(rows, row)
filteredData = append(filteredData, entry)
lastCommand = entry.Command
} else {
rows = append(rows, table.Row{})
}
}
return rows, data, nil
return rows, filteredData, nil
}
func calculateColumnWidths(rows []table.Row, numColumns int) []int {