From 0d952302d6bf2078e3bdf600392f54e1ffe225ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lilian=20J=C3=B3nsd=C3=B3ttir?= Date: Tue, 30 Jul 2024 19:42:59 -0700 Subject: [PATCH] add selectall back because I'm dumb --- internal/interactive/interactive.go | 18 +++++++++++++++--- main.go | 13 ++++--------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/internal/interactive/interactive.go b/internal/interactive/interactive.go index b4950a3..3d18361 100644 --- a/internal/interactive/interactive.go +++ b/internal/interactive/interactive.go @@ -84,7 +84,7 @@ type model struct { fltrfiles files.Files } -func newModel(fls []files.File, width, height int, readonly, once bool, workdir string, mode modes.Mode) model { +func newModel(fls []files.File, width, height int, selectall, readonly, once bool, workdir string, mode modes.Mode) model { var ( fwidth = int(math.Round(float64(width-woffset) * filenameColumnW)) owidth = int(math.Round(float64(width-woffset) * pathColumnW)) @@ -137,6 +137,10 @@ func newModel(fls []files.File, width, height int, readonly, once bool, workdir mdl.sorting = sorting.Name mdl.sort() + if selectall { + mdl.selectAll() + } + return mdl } @@ -614,8 +618,8 @@ func (m *model) updateTableHeight() { } } -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, once, workdir, mode) +func Select(fls files.Files, width, height int, selectall, once bool, workdir string, mode modes.Mode) (files.Files, modes.Mode, error) { + mdl := newModel(fls, width, height, selectall, false, once, workdir, mode) endmodel, err := tea.NewProgram(mdl).Run() if err != nil { return fls, 0, err @@ -627,6 +631,14 @@ func Select(fls files.Files, width, height int, readonly, once bool, workdir str return m.selectedFiles(), m.mode, nil } +func Show(fls files.Files, width, height int, once bool, workdir string) error { + mdl := newModel(fls, width, height, false, true, once, workdir, modes.Listing) + if _, err := tea.NewProgram(mdl).Run(); err != nil { + return err + } + return nil +} + func newRow(file files.File, workdir string) table.Row { var time, size string time = humanize.Time(file.Date()) diff --git a/main.go b/main.go index 0884b2c..95e083d 100644 --- a/main.go +++ b/main.go @@ -220,7 +220,7 @@ var ( filesToTrash = append(filesToTrash, file) } - // if none of the args were files, then process find files based on filter + // if none of the args were files, then find files based on filter if len(filesToTrash) == 0 { fls, err := files.FindDisk(workdir, recursive, fltr) if err != nil { @@ -255,7 +255,6 @@ var ( Action: func(_ *cli.Context) error { log.Debugf("searching in directory %s for files", trashDir) - // look for files fls, err := files.FindTrash(trashDir, ogdir, fltr) var msg string @@ -273,10 +272,7 @@ var ( return err } - // display them - _, _, err = interactive.Select(fls, termwidth, termheight, true, noInterArg, workdir, modes.Listing) - - return err + return interactive.Show(fls, termwidth, termheight, noInterArg, workdir) }, } @@ -290,7 +286,6 @@ var ( Action: func(_ *cli.Context) error { log.Debugf("searching in directory %s for files", trashDir) - // look for files fls, err := files.FindTrash(trashDir, ogdir, fltr) if len(fls) == 0 { fmt.Fprintln(os.Stdout, "no files to restore") @@ -299,7 +294,7 @@ var ( return err } - selected, _, err := interactive.Select(fls, termwidth, termheight, false, all, workdir, modes.Restoring) + selected, _, err := interactive.Select(fls, termwidth, termheight, all, all, workdir, modes.Restoring) if err != nil { return err } @@ -328,7 +323,7 @@ var ( return err } - selected, _, err := interactive.Select(fls, termwidth, termheight, false, all, workdir, modes.Cleaning) + selected, _, err := interactive.Select(fls, termwidth, termheight, all, all, workdir, modes.Cleaning) if err != nil { return err }