Add visual indication of --toggle-sort

Close #194
pull/165/merge
Junegunn Choi 9 years ago
parent d08542ce5d
commit d1d59272a2

@ -8,6 +8,7 @@ CHANGELOG
- Added `--tiebreak` option (#191) - Added `--tiebreak` option (#191)
- Added `--no-hscroll` option (#193) - Added `--no-hscroll` option (#193)
- Visual indication of `--toggle-sort` (#194)
0.9.8 0.9.8
----- -----

@ -195,8 +195,9 @@ func Run(options *Options) {
matcher.Reset(snapshot, terminal.Input(), false, !reading, sort) matcher.Reset(snapshot, terminal.Input(), false, !reading, sort)
case EvtSearchNew: case EvtSearchNew:
if value.(bool) { switch val := value.(type) {
sort = !sort case bool:
sort = val
} }
snapshot, _ := chunkList.Snapshot() snapshot, _ := chunkList.Snapshot()
matcher.Reset(snapshot, terminal.Input(), true, !reading, sort) matcher.Reset(snapshot, terminal.Input(), true, !reading, sort)

@ -29,6 +29,7 @@ type Terminal struct {
yanked []rune yanked []rune
input []rune input []rune
multi bool multi bool
sort bool
toggleSort int toggleSort int
expect []int expect []int
pressed int pressed int
@ -96,6 +97,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
yanked: []rune{}, yanked: []rune{},
input: input, input: input,
multi: opts.Multi, multi: opts.Multi,
sort: opts.Sort > 0,
toggleSort: opts.ToggleSort, toggleSort: opts.ToggleSort,
expect: opts.Expect, expect: opts.Expect,
pressed: 0, pressed: 0,
@ -241,6 +243,13 @@ func (t *Terminal) printInfo() {
t.move(1, 2, false) t.move(1, 2, false)
output := fmt.Sprintf("%d/%d", t.merger.Length(), t.count) 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 { if t.multi && len(t.selected) > 0 {
output += fmt.Sprintf(" (%d)", len(t.selected)) output += fmt.Sprintf(" (%d)", len(t.selected))
} }
@ -579,7 +588,8 @@ func (t *Terminal) Loop() {
} }
if t.toggleSort > 0 { if t.toggleSort > 0 {
if keyMatch(t.toggleSort, event) { if keyMatch(t.toggleSort, event) {
t.eventBox.Set(EvtSearchNew, true) t.sort = !t.sort
t.eventBox.Set(EvtSearchNew, t.sort)
t.mutex.Unlock() t.mutex.Unlock()
continue continue
} }

Loading…
Cancel
Save