From a4c42b5791981e61432648c46ceb3224274c134f Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Thu, 10 Jul 2025 12:19:07 -0400 Subject: [PATCH] feat(textarea): add focus status to setPromptFunc (#797) * fix!(textarea): send focus status to promptFunc * feat(filepicker): add highlighted file path * chore: rename and add docs * fix(filepicker): disabled cursor style * feat(textarea): promptFunc receives a PromptInfo type with metadata --------- Co-authored-by: Kujtim Hoxha --- filepicker/filepicker.go | 10 +++++++++- textarea/textarea.go | 16 +++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/filepicker/filepicker.go b/filepicker/filepicker.go index b749684..90e79d6 100644 --- a/filepicker/filepicker.go +++ b/filepicker/filepicker.go @@ -401,7 +401,7 @@ func (m Model) View() string { selected += " → " + symlinkPath } if disabled { - s.WriteString(m.Styles.DisabledSelected.Render(m.Cursor) + m.Styles.DisabledSelected.Render(selected)) + s.WriteString(m.Styles.DisabledCursor.Render(m.Cursor) + m.Styles.DisabledSelected.Render(selected)) } else { s.WriteString(m.Styles.Cursor.Render(m.Cursor) + m.Styles.Selected.Render(selected)) } @@ -516,3 +516,11 @@ func (m Model) canSelect(file string) bool { } return false } + +// HighlightedPath returns the path of the currently highlighted file or directory. +func (M Model) HighlightedPath() string { + if len(M.files) == 0 || M.selected < 0 || M.selected >= len(M.files) { + return "" + } + return filepath.Join(M.CurrentDirectory, M.files[M.selected].Name()) +} diff --git a/textarea/textarea.go b/textarea/textarea.go index f4e0fb3..f68db02 100644 --- a/textarea/textarea.go +++ b/textarea/textarea.go @@ -133,6 +133,13 @@ type LineInfo struct { CharOffset int } +// PromptInfo is a struct that can be used to store information about the +// prompt. +type PromptInfo struct { + LineNumber int + Focused bool +} + // CursorStyle is the style for real and virtual cursors. type CursorStyle struct { // Style styles the cursor block. @@ -287,7 +294,7 @@ type Model struct { // If promptFunc is set, it replaces Prompt as a generator for // prompt strings at the beginning of each line. - promptFunc func(line int) string + promptFunc func(PromptInfo) string // promptWidth is the width of the prompt. promptWidth int @@ -1052,7 +1059,7 @@ func (m *Model) SetWidth(w int) { // promptWidth, it will be padded to the left. If it returns a prompt that is // longer, display artifacts may occur; the caller is responsible for computing // an adequate promptWidth. -func (m *Model) SetPromptFunc(promptWidth int, fn func(lineIndex int) string) { +func (m *Model) SetPromptFunc(promptWidth int, fn func(PromptInfo) string) { m.promptFunc = fn m.promptWidth = promptWidth } @@ -1320,7 +1327,10 @@ func (m Model) promptView(displayLine int) (prompt string) { if m.promptFunc == nil { return prompt } - prompt = m.promptFunc(displayLine) + prompt = m.promptFunc(PromptInfo{ + LineNumber: displayLine, + Focused: m.focus, + }) width := lipgloss.Width(prompt) if width < m.promptWidth { prompt = fmt.Sprintf("%*s%s", m.promptWidth-width, "", prompt)