diff --git a/internal/tables/tables.go b/internal/tables/tables.go index b97826c..4243681 100644 --- a/internal/tables/tables.go +++ b/internal/tables/tables.go @@ -54,6 +54,7 @@ type model struct { keys keyMap selected map[string]bool readonly bool + once bool termheight int mode modes.Mode sorting sorting.Sorting @@ -61,7 +62,7 @@ type model struct { files files.Files } -func newModel(fs []files.File, width, height int, readonly, preselected bool, workdir string, mode modes.Mode) model { +func newModel(fs []files.File, width, height int, readonly, preselected, once bool, workdir string, mode modes.Mode) model { var ( fwidth int = int(math.Round(float64(width-woffset) * 0.4)) owidth int = int(math.Round(float64(width-woffset) * 0.2)) @@ -73,6 +74,7 @@ func newModel(fs []files.File, width, height int, readonly, preselected bool, wo m = model{ keys: defaultKeyMap(), readonly: readonly, + once: once, termheight: height, mode: mode, selected: map[string]bool{}, @@ -162,12 +164,21 @@ func defaultKeyMap() keyMap { } func (m model) Init() tea.Cmd { + /* if m.onePage() { + m.table.SetStyles(makeUnselectedStyle()) + m.unselectAll() + return tea.Quit + } */ return nil } func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var cmd tea.Cmd + if m.once { + return m.quit(true) + } + switch msg := msg.(type) { case tea.KeyMsg: switch { @@ -299,6 +310,15 @@ func (m model) selectedFiles() (outfile files.Files) { return } +/* func (m model) onePage() bool { + x := m.termheight + y := len(m.table.Rows()) + hoffset + if x > y && m.readonly { + return true + } + return false +} */ + func newRow(file files.File, workdir string) table.Row { var t, b string t = humanize.Time(file.Date()) diff --git a/main.go b/main.go index 643a71c..4b98f11 100644 --- a/main.go +++ b/main.go @@ -34,7 +34,7 @@ var ( o, b, a, g, p string sm, lg string ung, unp string - fo, do, sh bool + fo, do, sh, ni bool askconfirm bool workdir, ogdir cli.Path recursive bool @@ -184,7 +184,7 @@ var ( Name: "list", Aliases: []string{"ls"}, Usage: "List trashed files", - Flags: slices.Concat(alreadyintrashFlags, filterFlags), + Flags: slices.Concat(listFlags, alreadyintrashFlags, filterFlags), Before: beforeCommands, Action: func(ctx *cli.Context) error { log.Debugf("searching in directory %s for files", trashDir) @@ -394,6 +394,15 @@ var ( Destination: &ogdir, }, } + + listFlags = []cli.Flag{ + &cli.BoolFlag{ + Name: "non-interactive", + Usage: "list files and quit", + Aliases: []string{"n"}, + Destination: &ni, + }, + } ) func main() {