diff --git a/kittens/choose_files/results.go b/kittens/choose_files/results.go index 80011abdc..89f3dcd3a 100644 --- a/kittens/choose_files/results.go +++ b/kittens/choose_files/results.go @@ -102,14 +102,14 @@ func (h *Handler) render_match_with_positions(text string, add_ellipsis bool, po var icon_cache map[string]string -func icon_for(path string, x os.DirEntry) string { +func icon_for(path string, x os.FileMode) string { if icon_cache == nil { icon_cache = make(map[string]string, 512) } if ans := icon_cache[path]; ans != "" { return ans } - ans := icons.IconForFileWithMode(path, x.Type(), true) + ans := icons.IconForFileWithMode(path, x, true) if wcswidth.Stringwidth(ans) == 1 { ans += " " } @@ -121,7 +121,7 @@ func (h *Handler) draw_column_of_matches(matches []*ResultItem, current_idx int, for i, m := range matches { h.lp.QueueWriteString("\r") h.lp.MoveCursorHorizontally(x) - icon := icon_for(m.abspath, m.dir_entry) + icon := icon_for(m.abspath, m.ftype) text := m.text add_ellipsis := false if wcswidth.Stringwidth(text) > available_width-3 { diff --git a/kittens/choose_files/scan.go b/kittens/choose_files/scan.go index f3dc2f0f0..40629c8e8 100644 --- a/kittens/choose_files/scan.go +++ b/kittens/choose_files/scan.go @@ -3,6 +3,7 @@ package choose_files import ( "cmp" "fmt" + "io/fs" "os" "path/filepath" "regexp" @@ -20,14 +21,14 @@ var _ = fmt.Print type ResultItem struct { text, abspath string - dir_entry os.DirEntry + ftype fs.FileMode positions []int // may be nil score float64 positions_sorted bool } func (r ResultItem) String() string { - return fmt.Sprintf("{text: %#v, abspath: %#v, is_dir: %v, positions: %#v}", r.text, r.abspath, r.dir_entry.IsDir(), r.positions) + return fmt.Sprintf("{text: %#v, abspath: %#v, is_dir: %v, positions: %#v}", r.text, r.abspath, r.ftype.IsDir(), r.positions) } func (r *ResultItem) sorted_positions() []int { @@ -83,7 +84,7 @@ func sort_items_without_search_text(items []*ResultItem) (ans []*ResultItem) { } hidden_pat := regexp.MustCompile(`(^|/)\.[^/]+(/|$)`) d := utils.Map(func(x *ResultItem) s { - return s{strings.ToLower(x.text), strings.Count(x.text, "/"), x.dir_entry.IsDir(), hidden_pat.MatchString(x.abspath), x} + return s{strings.ToLower(x.text), strings.Count(x.text, "/"), x.ftype.IsDir(), hidden_pat.MatchString(x.abspath), x} }, items) sort.SliceStable(d, func(i, j int) bool { a, b := d[i], d[j] @@ -178,7 +179,7 @@ func (sc *ScanCache) scan_dir(abspath string, patterns []string, positions []pos if pattern == "" || scores[i].Score > 0 { npos[len(positions)] = pos_in_name{name: n, positions: scores[i].Positions} if is_last { - r := &ResultItem{score: score + scores[i].Score, dir_entry: entries[i], abspath: child_abspath} + r := &ResultItem{score: score + scores[i].Score, ftype: entries[i].Type(), abspath: child_abspath} r.finalize(npos) ans = append(ans, r) } else if e.IsDir() {