mirror of
https://github.com/zoriya/bubbles.git
synced 2026-08-05 04:36:07 +00:00
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 <kujtimii.h@gmail.com>
This commit is contained in:
co-authored by
Kujtim Hoxha
parent
696244a1d0
commit
a4c42b5791
@@ -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())
|
||||
}
|
||||
|
||||
+13
-3
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user