mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-15 03:37:52 +08:00
edit: Remove the need to sort []styled.
This commit is contained in:
parent
50b8f8b7b8
commit
a82e4014de
|
@ -4,6 +4,7 @@ import (
|
|||
"errors"
|
||||
"os"
|
||||
"path"
|
||||
"sort"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
|
@ -307,19 +308,20 @@ func (n *navigation) loaddir(dir string) ([]styled, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
infos, err := f.Readdir(0)
|
||||
names, err := f.Readdirnames(-1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sort.Strings(names)
|
||||
|
||||
var all []styled
|
||||
lsColor := getLsColor()
|
||||
for _, info := range infos {
|
||||
if n.showHidden || info.Name()[0] != '.' {
|
||||
name := info.Name()
|
||||
all = append(all, styled{name, stylesFromString(lsColor.getStyle(path.Join(dir, name)))})
|
||||
for _, name := range names {
|
||||
if n.showHidden || name[0] != '.' {
|
||||
all = append(all, styled{name,
|
||||
stylesFromString(lsColor.getStyle(path.Join(dir, name)))})
|
||||
}
|
||||
}
|
||||
sortStyleds(all)
|
||||
|
||||
return all, nil
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package edit
|
||||
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"github.com/elves/elvish/eval"
|
||||
"github.com/elves/elvish/parse"
|
||||
)
|
||||
|
@ -38,15 +36,3 @@ func styledBuiltin(ec *eval.EvalCtx, args []eval.Value, opts map[string]eval.Val
|
|||
out := ec.OutputChan()
|
||||
out <- &styled{text, stylesFromString(style)}
|
||||
}
|
||||
|
||||
// Boilerplates for sorting.
|
||||
|
||||
type styleds []styled
|
||||
|
||||
func (s styleds) Len() int { return len(s) }
|
||||
func (s styleds) Less(i, j int) bool { return s[i].text < s[j].text }
|
||||
func (s styleds) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
|
||||
func sortStyleds(s []styled) {
|
||||
sort.Sort(styleds(s))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user