Add visual indication of --toggle-sort

Close #194
This commit is contained in:
Junegunn Choi 2015-04-16 14:44:41 +09:00
parent d08542ce5d
commit d1d59272a2
3 changed files with 15 additions and 3 deletions

View File

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

View File

@ -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)

View File

@ -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
}