From d1d59272a2e148e936daff9cefb23cfcaf408848 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Thu, 16 Apr 2015 14:44:41 +0900 Subject: [PATCH] Add visual indication of --toggle-sort Close #194 --- CHANGELOG.md | 1 + src/core.go | 5 +++-- src/terminal.go | 12 +++++++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3399fd..e3c58dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ CHANGELOG - Added `--tiebreak` option (#191) - Added `--no-hscroll` option (#193) +- Visual indication of `--toggle-sort` (#194) 0.9.8 ----- diff --git a/src/core.go b/src/core.go index 4a83424..b56fbf6 100644 --- a/src/core.go +++ b/src/core.go @@ -195,8 +195,9 @@ func Run(options *Options) { matcher.Reset(snapshot, terminal.Input(), false, !reading, sort) case EvtSearchNew: - if value.(bool) { - sort = !sort + switch val := value.(type) { + case bool: + sort = val } snapshot, _ := chunkList.Snapshot() matcher.Reset(snapshot, terminal.Input(), true, !reading, sort) diff --git a/src/terminal.go b/src/terminal.go index b16daec..790ccc1 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -29,6 +29,7 @@ type Terminal struct { yanked []rune input []rune multi bool + sort bool toggleSort int expect []int pressed int @@ -96,6 +97,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal { yanked: []rune{}, input: input, multi: opts.Multi, + sort: opts.Sort > 0, toggleSort: opts.ToggleSort, expect: opts.Expect, pressed: 0, @@ -241,6 +243,13 @@ func (t *Terminal) printInfo() { t.move(1, 2, false) output := fmt.Sprintf("%d/%d", t.merger.Length(), t.count) + if t.toggleSort > 0 { + if t.sort { + output += "/S" + } else { + output += " " + } + } if t.multi && len(t.selected) > 0 { output += fmt.Sprintf(" (%d)", len(t.selected)) } @@ -579,7 +588,8 @@ func (t *Terminal) Loop() { } if t.toggleSort > 0 { if keyMatch(t.toggleSort, event) { - t.eventBox.Set(EvtSearchNew, true) + t.sort = !t.sort + t.eventBox.Set(EvtSearchNew, t.sort) t.mutex.Unlock() continue }