mirror of
https://github.com/ddworken/hishtory.git
synced 2025-01-23 06:38:52 +01:00
Fix #82 by ensuring that the results list also filters out duplicates
This commit is contained in:
parent
0b13a9705d
commit
c0e56eff0d
@ -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) {
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user