diff --git a/src/items.go b/src/items.go index 096d2d9..ea8e5b2 100644 --- a/src/items.go +++ b/src/items.go @@ -96,13 +96,18 @@ func (item *Item) RunCommand() (string, string) { return RunCommand(item.match) } -func (list *ItemList) Filter() error { +func (list *ItemList) NumMatches() int { count := 0 for _, item := range list.items { if item.HasMatch() { count++ } } + return count +} + +func (list *ItemList) Filter() error { + count := list.NumMatches() if count == 0 { return errors.New("Empty list") @@ -136,7 +141,7 @@ func (list *ItemList) Sort() { } func (list *ItemList) Get(index int) *Item { - return &list.items[index] + return &list.items[index] } func (list *ItemList) Print() { diff --git a/src/items_test.go b/src/items_test.go index 63865a8..0286c2f 100644 --- a/src/items_test.go +++ b/src/items_test.go @@ -24,6 +24,9 @@ func TestProcessNoRegexp(t *testing.T) { if items.items[0].match != "" || items.items[1].match != "" { t.Error("Incorrect matches") } + if items.NumMatches() != 0 { + t.Error("Incorrect number of matches") + } } func TestProcessRegexp(t *testing.T) { @@ -42,6 +45,9 @@ func TestProcessRegexp(t *testing.T) { if items.items[2].display != "the [::r]match[::-], the mbtch, the mctch" { t.Error("Incorrect processed line with multiple submatches highlighting the first") } + if items.NumMatches() != 3 { + t.Error("Incorrect number of matches") + } config.pattern = regexp.MustCompile("m[a-c]tch") items = NewItemList(lines) @@ -52,6 +58,9 @@ func TestProcessRegexp(t *testing.T) { if items.items[1].display != "no [::r]match[::-], but the match here and not the match again" { t.Error("Incorrect processed line with multiple matches highlighting the first") } + if items.NumMatches() != 3 { + t.Error("Incorrect number of matches") + } config.pattern = regexp.MustCompile("m[b-c]t(c)h") items = NewItemList(lines) @@ -65,6 +74,9 @@ func TestProcessRegexp(t *testing.T) { if items.items[2].display != "the match, the mbt[::r]c[::-]h, the mctch" { t.Error("Incorrect processed line with multiple submatches highlighting the first") } + if items.NumMatches() != 1 { + t.Error("Incorrect number of matches") + } config.pattern = regexp.MustCompile("m(at)(c(h))") items = NewItemList(lines) diff --git a/src/main.go b/src/main.go index ae25df1..9cfc90b 100644 --- a/src/main.go +++ b/src/main.go @@ -76,7 +76,7 @@ func PrintHelp() { fmt.Println("\nOther keyword OPTIONS:") fmt.Println("\n --show-output Show the output (both stdout and stderr) of COMMAND") fmt.Println(" --filter Hide lines without a match") - fmt.Println(" --sort Sort all lines by their matches") + fmt.Println(" --sort Sort lines by their matches") fmt.Println(" --help Display this help") fmt.Println("\nExamples:") fmt.Println("\n git log --oneline | " + os.Args[0] + " \"\\b[0-9a-z]{7,40}\\b\" git show") @@ -265,7 +265,14 @@ func (pageList *PageList) setStatus(programExecuted string) { space := " " if config.pattern != nil { - info += fmt.Sprintf("%s%s", config.pattern, space) + numMatches := pageList.itemList.NumMatches() + if numMatches > 1 { + info += fmt.Sprintf("%d matches with %s%s", numMatches, config.pattern, space) + } else if numMatches == 1 { + info += fmt.Sprintf("1 match with %s%s", config.pattern, space) + } else { + info += fmt.Sprintf("No match with %s%s", config.pattern, space) + } } index := pageList.list.GetCurrentItem()