From 69c7483528ce39dbfbdca582740ce3cab049ff6d Mon Sep 17 00:00:00 2001 From: Albertin Loic Date: Wed, 21 May 2025 17:28:53 +0200 Subject: [PATCH 1/2] feat: add an optional modtime section to the filepicker To make the filepicker looks like a bit more `ls -l`, allow to optionally display file modification time. For backward compatibility this is disabled by default. The default modification time layout format is similar to the one in `ls -l`. This is configurable using standard time.Format() supported layouts. Fixes Add modification time to the filepicker #780 --- filepicker/filepicker.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/filepicker/filepicker.go b/filepicker/filepicker.go index 3898742c8..3a9aaa477 100644 --- a/filepicker/filepicker.go +++ b/filepicker/filepicker.go @@ -17,6 +17,9 @@ import ( "github.com/dustin/go-humanize" ) +// DefaultModTimeLayout is the default layout used to format modification time for a given file. +const DefaultModTimeLayout = "Jan _2 15:04" + var lastID int64 func nextID() int { @@ -34,6 +37,7 @@ func New() Model { ShowPermissions: true, ShowSize: true, ShowHidden: false, + ModTimeLayout: DefaultModTimeLayout, DirAllowed: false, FileAllowed: true, AutoHeight: true, @@ -103,6 +107,7 @@ type Styles struct { Selected lipgloss.Style DisabledSelected lipgloss.Style FileSize lipgloss.Style + ModTime lipgloss.Style EmptyDirectory lipgloss.Style } @@ -125,6 +130,7 @@ func DefaultStylesWithRenderer(r *lipgloss.Renderer) Styles { Permission: r.NewStyle().Foreground(lipgloss.Color("244")), Selected: r.NewStyle().Foreground(lipgloss.Color("212")).Bold(true), FileSize: r.NewStyle().Foreground(lipgloss.Color("240")).Width(fileSizeWidth).Align(lipgloss.Right), + ModTime: r.NewStyle().Foreground(lipgloss.Color("240")), EmptyDirectory: r.NewStyle().Foreground(lipgloss.Color("240")).PaddingLeft(paddingLeft).SetString("Bummer. No Files Found."), } } @@ -147,6 +153,8 @@ type Model struct { files []os.DirEntry ShowPermissions bool ShowSize bool + ShowModTime bool + ModTimeLayout string ShowHidden bool DirAllowed bool FileAllowed bool @@ -400,6 +408,9 @@ func (m Model) View() string { if m.ShowSize { selected += fmt.Sprintf("%"+strconv.Itoa(m.Styles.FileSize.GetWidth())+"s", size) } + if m.ShowModTime { + selected += " " + info.ModTime().Format(m.ModTimeLayout) + } selected += " " + name if isSymlink { selected += " → " + symlinkPath @@ -433,6 +444,9 @@ func (m Model) View() string { if m.ShowSize { s.WriteString(m.Styles.FileSize.Render(size)) } + if m.ShowModTime { + s.WriteString(" " + m.Styles.ModTime.Render(info.ModTime().Format(m.ModTimeLayout))) + } s.WriteString(" " + fileName) s.WriteRune('\n') } From d8cd4419f3db8e2f2008aeebd9be46fb23a76810 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Albertin?= Date: Mon, 30 Jun 2025 22:03:29 +0200 Subject: [PATCH 2/2] Update filepicker/filepicker.go fix fmt --- filepicker/filepicker.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/filepicker/filepicker.go b/filepicker/filepicker.go index a1f5d886c..66bd7c92f 100644 --- a/filepicker/filepicker.go +++ b/filepicker/filepicker.go @@ -124,7 +124,7 @@ func DefaultStyles() Styles { Permission: lipgloss.NewStyle().Foreground(lipgloss.Color("244")), Selected: lipgloss.NewStyle().Foreground(lipgloss.Color("212")).Bold(true), FileSize: lipgloss.NewStyle().Foreground(lipgloss.Color("240")).Width(fileSizeWidth).Align(lipgloss.Right), - ModTime: lipgloss.NewStyle().Foreground(lipgloss.Color("240")), + ModTime: lipgloss.NewStyle().Foreground(lipgloss.Color("240")), EmptyDirectory: lipgloss.NewStyle().Foreground(lipgloss.Color("240")).PaddingLeft(paddingLeft).SetString("Bummer. No Files Found."), } }