From 3fc226c1365af73ca8be71db18040469c593622f Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Wed, 23 Oct 2024 16:41:07 -0400 Subject: [PATCH] feat(filepicker): make symlink symbol customizable --- filepicker/filepicker.go | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/filepicker/filepicker.go b/filepicker/filepicker.go index 1176da1..37c2a90 100644 --- a/filepicker/filepicker.go +++ b/filepicker/filepicker.go @@ -42,6 +42,10 @@ func New() Model { maxStack: newStack(), KeyMap: DefaultKeyMap(), Styles: DefaultStyles(), + + Cursor: ">", + DisabledCursor: ">", + Symlink: "→", } } @@ -106,8 +110,8 @@ type Styles struct { // DefaultStyles defines the default styling for the file picker. func DefaultStyles() Styles { return Styles{ - DisabledCursor: lipgloss.NewStyle().Foreground(lipgloss.Color("247")).SetString(">"), - Cursor: lipgloss.NewStyle().Foreground(lipgloss.Color("212")).SetString(">"), + Cursor: lipgloss.NewStyle().Foreground(lipgloss.Color("212")), + DisabledCursor: lipgloss.NewStyle().Foreground(lipgloss.Color("247")), Symlink: lipgloss.NewStyle().Foreground(lipgloss.Color("36")), Directory: lipgloss.NewStyle().Foreground(lipgloss.Color("99")), File: lipgloss.NewStyle(), @@ -134,6 +138,11 @@ type Model struct { // If empty the user may select any file. AllowedTypes []string + // Various characters used in rendering the UI. + Cursor string + DisabledCursor string + Symlink string + KeyMap KeyMap files []os.DirEntry ShowPermissions bool @@ -371,6 +380,11 @@ func (m Model) View() string { disabled := !m.canSelect(name) && !f.IsDir() + cursor := m.Styles.Cursor.Render(m.Cursor) + if disabled { + cursor = m.Styles.DisabledCursor.Render(m.DisabledCursor) + } + if m.selected == i { selected := "" if m.ShowPermissions { @@ -381,12 +395,12 @@ func (m Model) View() string { } selected += " " + name if isSymlink { - selected += " → " + symlinkPath + selected += fmt.Sprintf(" %s %s", m.Symlink, symlinkPath) } if disabled { - s.WriteString(m.Styles.DisabledCursor.String() + m.Styles.DisabledSelected.Render(selected)) + s.WriteString(cursor + m.Styles.DisabledSelected.Render(selected)) } else { - s.WriteString(m.Styles.Cursor.String() + m.Styles.Selected.Render(selected)) + s.WriteString(cursor + m.Styles.Selected.Render(selected)) } s.WriteRune('\n') continue @@ -404,7 +418,6 @@ func (m Model) View() string { fileName := style.Render(name) // Replace the cursor with an empty space. - cursor := m.Styles.Cursor.String() gap := strings.Repeat(" ", lipgloss.Width(cursor)) s.WriteString(gap)