Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): ability to prompt a confirmation before an action is performed
- Loading branch information
1 parent
21a4668
commit 144d589
Showing
6 changed files
with
243 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package prompt | ||
|
||
import ( | ||
"github.com/charmbracelet/bubbles/textinput" | ||
tea "github.com/charmbracelet/bubbletea" | ||
"github.com/dlvhdr/gh-dash/ui/context" | ||
) | ||
|
||
type Model struct { | ||
ctx *context.ProgramContext | ||
prompt textinput.Model | ||
} | ||
|
||
func NewModel(ctx *context.ProgramContext) Model { | ||
ti := textinput.New() | ||
ti.Focus() | ||
ti.Blur() | ||
ti.CursorStart() | ||
|
||
return Model{ | ||
ctx: ctx, | ||
prompt: ti, | ||
} | ||
} | ||
|
||
func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { | ||
var cmd tea.Cmd | ||
m.prompt, cmd = m.prompt.Update(msg) | ||
return m, cmd | ||
} | ||
|
||
func (m Model) View() string { | ||
return m.prompt.View() | ||
} | ||
|
||
func (m Model) Init() tea.Cmd { | ||
return textinput.Blink | ||
} | ||
|
||
func (m *Model) Blur() { | ||
m.prompt.Blur() | ||
} | ||
|
||
func (m *Model) Focus() tea.Cmd { | ||
return m.prompt.Focus() | ||
} | ||
|
||
func (m *Model) SetValue(value string) { | ||
m.prompt.SetValue(value) | ||
} | ||
|
||
func (m *Model) Value() string { | ||
return m.prompt.Value() | ||
} | ||
|
||
func (m *Model) SetPrompt(prompt string) { | ||
m.prompt.Prompt = prompt | ||
} | ||
|
||
func (m *Model) Reset() { | ||
m.prompt.Reset() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.