listing prints plainly if in non-interative terminal

This commit is contained in:
Lilian Jónsdóttir 2024-08-14 15:48:06 -07:00
parent 34eef6a228
commit 6c3abd8d98
2 changed files with 32 additions and 0 deletions

View file

@ -3,6 +3,7 @@ package files
import (
"cmp"
"fmt"
"io/fs"
"path/filepath"
"strconv"
@ -22,6 +23,16 @@ type File interface {
type Files []File
func (fls Files) String() string {
var out = strings.Builder{}
for _, file := range fls {
out.WriteString(fmt.Sprintf("%s\t%s\t%s\n",
file.Date().Format(time.RFC3339), file.Name(), file.Path(),
))
}
return out.String()
}
func SortByModified(a, b File) int {
if a.Date().Before(b.Date()) {
return 1