add selectall back

because I'm dumb
This commit is contained in:
Lilian Jónsdóttir 2024-07-30 19:42:59 -07:00
parent 48844886a9
commit 0d952302d6
2 changed files with 19 additions and 12 deletions

View file

@ -84,7 +84,7 @@ type model struct {
fltrfiles files.Files 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 ( var (
fwidth = int(math.Round(float64(width-woffset) * filenameColumnW)) fwidth = int(math.Round(float64(width-woffset) * filenameColumnW))
owidth = int(math.Round(float64(width-woffset) * pathColumnW)) 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.sorting = sorting.Name
mdl.sort() mdl.sort()
if selectall {
mdl.selectAll()
}
return mdl 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) { 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, readonly, once, workdir, mode) mdl := newModel(fls, width, height, selectall, false, 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
@ -627,6 +631,14 @@ func Select(fls files.Files, width, height int, readonly, once bool, workdir str
return m.selectedFiles(), m.mode, nil 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 { func newRow(file files.File, workdir string) table.Row {
var time, size string var time, size string
time = humanize.Time(file.Date()) time = humanize.Time(file.Date())

13
main.go
View file

@ -220,7 +220,7 @@ var (
filesToTrash = append(filesToTrash, file) 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 { if len(filesToTrash) == 0 {
fls, err := files.FindDisk(workdir, recursive, fltr) fls, err := files.FindDisk(workdir, recursive, fltr)
if err != nil { if err != nil {
@ -255,7 +255,6 @@ var (
Action: func(_ *cli.Context) error { Action: func(_ *cli.Context) error {
log.Debugf("searching in directory %s for files", trashDir) log.Debugf("searching in directory %s for files", trashDir)
// look for files
fls, err := files.FindTrash(trashDir, ogdir, fltr) fls, err := files.FindTrash(trashDir, ogdir, fltr)
var msg string var msg string
@ -273,10 +272,7 @@ var (
return err return err
} }
// display them return interactive.Show(fls, termwidth, termheight, noInterArg, workdir)
_, _, err = interactive.Select(fls, termwidth, termheight, true, noInterArg, workdir, modes.Listing)
return err
}, },
} }
@ -290,7 +286,6 @@ var (
Action: func(_ *cli.Context) error { Action: func(_ *cli.Context) error {
log.Debugf("searching in directory %s for files", trashDir) log.Debugf("searching in directory %s for files", trashDir)
// look for files
fls, err := files.FindTrash(trashDir, ogdir, fltr) fls, err := files.FindTrash(trashDir, ogdir, fltr)
if len(fls) == 0 { if len(fls) == 0 {
fmt.Fprintln(os.Stdout, "no files to restore") fmt.Fprintln(os.Stdout, "no files to restore")
@ -299,7 +294,7 @@ var (
return err 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 { if err != nil {
return err return err
} }
@ -328,7 +323,7 @@ var (
return err 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 { if err != nil {
return err return err
} }