Skip to content

Commit

Permalink
feat(filepicker): optional file permissions and file size
Browse files Browse the repository at this point in the history
  • Loading branch information
maaslalani committed Jan 29, 2024
1 parent 034ee85 commit 07e7bd4
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions filepicker/filepicker.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"path/filepath"
"sort"
"strconv"
"strings"
"sync"

Expand Down Expand Up @@ -35,6 +36,8 @@ func New() Model {
Cursor: ">",
AllowedTypes: []string{},
selected: 0,
ShowPermissions: true,
ShowSize: true,
ShowHidden: false,
DirAllowed: false,
FileAllowed: true,
Expand Down Expand Up @@ -145,11 +148,13 @@ type Model struct {
// If empty the user may select any file.
AllowedTypes []string

KeyMap KeyMap
files []os.DirEntry
ShowHidden bool
DirAllowed bool
FileAllowed bool
KeyMap KeyMap
files []os.DirEntry
ShowPermissions bool
ShowSize bool
ShowHidden bool
DirAllowed bool
FileAllowed bool

FileSelected string
selected int
Expand Down Expand Up @@ -382,9 +387,16 @@ func (m Model) View() string {
disabled := !m.canSelect(name) && !f.IsDir()

if m.selected == i {
selected := fmt.Sprintf(" %s %"+fmt.Sprint(m.Styles.FileSize.GetWidth())+"s %s", info.Mode().String(), size, name)
selected := ""
if m.ShowPermissions {
selected += " " + info.Mode().String()
}
if m.ShowSize {
selected += " " + fmt.Sprintf("%"+strconv.Itoa(m.Styles.FileSize.GetWidth())+"s", size)
}
selected += " " + name
if isSymlink {
selected = fmt.Sprintf("%s%s", selected, symlinkPath)
selected += "" + symlinkPath
}
if disabled {
s.WriteString(m.Styles.DisabledSelected.Render(m.Cursor) + m.Styles.DisabledSelected.Render(selected))
Expand All @@ -405,10 +417,17 @@ func (m Model) View() string {
}

fileName := style.Render(name)
s.WriteString(m.Styles.Cursor.Render(" "))
if isSymlink {
fileName = fmt.Sprintf("%s → %s", fileName, symlinkPath)
fileName += " → " + symlinkPath
}
if m.ShowPermissions {
s.WriteString(" " + m.Styles.Permission.Render(info.Mode().String()))
}
if m.ShowSize {
s.WriteString(" " + m.Styles.FileSize.Render(size))
}
s.WriteString(fmt.Sprintf(" %s %s %s", m.Styles.Permission.Render(info.Mode().String()), m.Styles.FileSize.Render(size), fileName))
s.WriteString(" " + fileName)
s.WriteRune('\n')
}

Expand Down

0 comments on commit 07e7bd4

Please sign in to comment.