remove preselection of items

just hit 'a' if you want to select all
This commit is contained in:
Lilian Jónsdóttir 2024-07-30 13:12:00 -07:00
parent 0fd14c1949
commit 11b22887f4
2 changed files with 15 additions and 22 deletions

View file

@ -73,7 +73,7 @@ type model struct {
files files.Files files files.Files
} }
func newModel(fls []files.File, width, height int, readonly, preselected, once bool, workdir string, mode modes.Mode) model { func newModel(fls []files.File, width, height int, readonly, once bool, workdir string, mode modes.Mode) model {
var ( var (
fwidth = int(math.Round(float64(width-woffset) * filenameColumn)) fwidth = int(math.Round(float64(width-woffset) * filenameColumn))
owidth = int(math.Round(float64(width-woffset) * pathColumn)) owidth = int(math.Round(float64(width-woffset) * pathColumn))
@ -99,7 +99,7 @@ func newModel(fls []files.File, width, height int, readonly, preselected, once b
mdl.workdir = filepath.Clean(workdir) mdl.workdir = filepath.Clean(workdir)
} }
rows := mdl.freshRows(preselected) rows := mdl.freshRows()
var datecolumn string var datecolumn string
switch mdl.mode { switch mdl.mode {
@ -352,16 +352,12 @@ func (m model) selectedFiles() (outfile files.Files) {
return false return false
} */ } */
func (m *model) freshRows(preselected bool) (rows []table.Row) { func (m *model) freshRows() (rows []table.Row) {
for _, file := range m.files { for _, file := range m.files {
row := newRow(file, m.workdir) row := newRow(file, m.workdir)
if !m.readonly { if !m.readonly {
row = append(row, getCheck(preselected)) row = append(row, getCheck(false))
}
if preselected {
m.selected[file.String()] = true
m.selectsize += file.Filesize()
} }
rows = append(rows, row) rows = append(rows, row)
} }
@ -511,8 +507,8 @@ func (m *model) sort() {
m.table.SetRows(rows) m.table.SetRows(rows)
} }
func Select(fls files.Files, width, height int, readonly, preselected, once bool, workdir string, mode modes.Mode) (files.Files, modes.Mode, error) { func Select(fls files.Files, width, height int, readonly, once bool, workdir string, mode modes.Mode) (files.Files, modes.Mode, error) {
mdl := newModel(fls, width, height, readonly, preselected, once, workdir, mode) mdl := newModel(fls, width, height, readonly, once, workdir, mode)
endmodel, err := tea.NewProgram(mdl).Run() endmodel, err := tea.NewProgram(mdl).Run()
if err != nil { if err != nil {
return fls, 0, err return fls, 0, err
@ -562,16 +558,16 @@ func createTable(columns []table.Column, rows []table.Row, height int) table.Mod
} }
func fixTableKeymap() table.KeyMap { func fixTableKeymap() table.KeyMap {
tbl := table.DefaultKeyMap() keys := table.DefaultKeyMap()
// remove spacebar from default page down keybind, but keep the rest // remove spacebar from default page down keybind, but keep the rest
tbl.PageDown.SetKeys( keys.PageDown.SetKeys(
slices.DeleteFunc(tbl.PageDown.Keys(), func(s string) bool { slices.DeleteFunc(keys.PageDown.Keys(), func(s string) bool {
return s == space return s == space
})..., })...,
) )
return tbl return keys
} }
func makeStyle() table.Styles { func makeStyle() table.Styles {

13
main.go
View file

@ -126,7 +126,7 @@ var (
fmt.Fprintln(os.Stdout, msg) fmt.Fprintln(os.Stdout, msg)
return nil return nil
} }
selected, mode, err = interactive.Select(infiles, termwidth, termheight, false, false, false, workdir, modes.Interactive) selected, mode, err = interactive.Select(infiles, termwidth, termheight, false, false, workdir, modes.Interactive)
if err != nil { if err != nil {
return err return err
} }
@ -202,7 +202,6 @@ var (
Before: beforeTrash, Before: beforeTrash,
Action: func(ctx *cli.Context) error { Action: func(ctx *cli.Context) error {
var filesToTrash files.Files var filesToTrash files.Files
var selectall bool
for _, arg := range ctx.Args().Slice() { for _, arg := range ctx.Args().Slice() {
file, e := files.NewDisk(arg) file, e := files.NewDisk(arg)
if e != nil || workdir != "" { if e != nil || workdir != "" {
@ -211,7 +210,6 @@ var (
continue continue
} }
filesToTrash = append(filesToTrash, file) filesToTrash = append(filesToTrash, file)
selectall = true
} }
// if none of the args were files, then process find files based on filter // if none of the args were files, then process find files based on filter
@ -225,10 +223,9 @@ var (
return nil return nil
} }
filesToTrash = append(filesToTrash, fls...) filesToTrash = append(filesToTrash, fls...)
selectall = !fltr.Blank()
} }
selected, _, err := interactive.Select(filesToTrash, termwidth, termheight, false, selectall, false, workdir, modes.Trashing) selected, _, err := interactive.Select(filesToTrash, termwidth, termheight, false, false, workdir, modes.Trashing)
if err != nil { if err != nil {
return err return err
} }
@ -269,7 +266,7 @@ var (
} }
// display them // display them
_, _, err = interactive.Select(fls, termwidth, termheight, true, false, noInterArg, workdir, modes.Listing) _, _, err = interactive.Select(fls, termwidth, termheight, true, noInterArg, workdir, modes.Listing)
return err return err
}, },
@ -293,7 +290,7 @@ var (
return err return err
} }
selected, _, err := interactive.Select(fls, termwidth, termheight, false, all, all, workdir, modes.Restoring) selected, _, err := interactive.Select(fls, termwidth, termheight, false, all, workdir, modes.Restoring)
if err != nil { if err != nil {
return err return err
} }
@ -321,7 +318,7 @@ var (
return err return err
} }
selected, _, err := interactive.Select(fls, termwidth, termheight, false, all, all, workdir, modes.Cleaning) selected, _, err := interactive.Select(fls, termwidth, termheight, false, all, workdir, modes.Cleaning)
if err != nil { if err != nil {
return err return err
} }