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
}
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())

13
main.go
View file

@ -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
}