diff --git a/pkg/terminal/input.go b/pkg/terminal/input.go index fe06144..eb382fd 100644 --- a/pkg/terminal/input.go +++ b/pkg/terminal/input.go @@ -1,8 +1,6 @@ package terminal import ( - "github.com/charmbracelet/bubbles/textarea" - "github.com/charmbracelet/bubbles/textinput" tea "github.com/charmbracelet/bubbletea" ) @@ -18,103 +16,3 @@ type Input interface { // We need to have a wrapper for our bubbles as they don't currently implement the tea.Model interface // textinput, textarea - -type shortAnswerField struct { - textinput textinput.Model -} - -func NewShortAnswerField(p string) *shortAnswerField { - a := shortAnswerField{} - if p == "" { - p = "Your Answer here" - } - model := textinput.New() - model.Placeholder = p - model.Focus() - - a.textinput = model - return &a -} - -func (a *shortAnswerField) Blink() tea.Msg { - return textinput.Blink() -} - -func (a *shortAnswerField) Init() tea.Cmd { - return nil -} - -func (a *shortAnswerField) Update(msg tea.Msg) (Input, tea.Cmd) { - var cmd tea.Cmd - a.textinput, cmd = a.textinput.Update(msg) - return a, cmd -} - -func (a *shortAnswerField) View() string { - return a.textinput.View() -} - -func (a *shortAnswerField) Focus() tea.Cmd { - return a.textinput.Focus() -} - -func (a *shortAnswerField) SetValue(s string) { - a.textinput.SetValue(s) -} - -func (a *shortAnswerField) Blur() tea.Msg { - return a.textinput.Blur -} - -func (a *shortAnswerField) Value() string { - return a.textinput.Value() -} - -type longAnswerField struct { - textarea textarea.Model -} - -func NewLongAnswerField() *longAnswerField { - a := longAnswerField{} - - model := textarea.New() - model.Placeholder = "Your Answer here" - model.Focus() - - a.textarea = model - return &a -} - -func (a *longAnswerField) Blink() tea.Msg { - return textarea.Blink() -} - -func (a *longAnswerField) Init() tea.Cmd { - return nil -} - -func (a *longAnswerField) Update(msg tea.Msg) (Input, tea.Cmd) { - var cmd tea.Cmd - a.textarea, cmd = a.textarea.Update(msg) - return a, cmd -} - -func (a *longAnswerField) View() string { - return a.textarea.View() -} - -func (a *longAnswerField) Focus() tea.Cmd { - return a.textarea.Focus() -} - -func (a *longAnswerField) SetValue(s string) { - a.textarea.SetValue(s) -} - -func (a *longAnswerField) Blur() tea.Msg { - return a.textarea.Blur -} - -func (a *longAnswerField) Value() string { - return a.textarea.Value() -} diff --git a/pkg/terminal/long_answer_field.go b/pkg/terminal/long_answer_field.go new file mode 100644 index 0000000..641cfe8 --- /dev/null +++ b/pkg/terminal/long_answer_field.go @@ -0,0 +1,55 @@ +package terminal + +import ( + "github.com/charmbracelet/bubbles/textarea" + tea "github.com/charmbracelet/bubbletea" +) + +type longAnswerField struct { + textarea textarea.Model +} + +func NewLongAnswerField() *longAnswerField { + a := longAnswerField{} + + model := textarea.New() + model.Placeholder = "Your Answer here" + model.Focus() + + a.textarea = model + return &a +} + +func (a *longAnswerField) Blink() tea.Msg { + return textarea.Blink() +} + +func (a *longAnswerField) Init() tea.Cmd { + return nil +} + +func (a *longAnswerField) Update(msg tea.Msg) (Input, tea.Cmd) { + var cmd tea.Cmd + a.textarea, cmd = a.textarea.Update(msg) + return a, cmd +} + +func (a *longAnswerField) View() string { + return a.textarea.View() +} + +func (a *longAnswerField) Focus() tea.Cmd { + return a.textarea.Focus() +} + +func (a *longAnswerField) SetValue(s string) { + a.textarea.SetValue(s) +} + +func (a *longAnswerField) Blur() tea.Msg { + return a.textarea.Blur +} + +func (a *longAnswerField) Value() string { + return a.textarea.Value() +} diff --git a/pkg/terminal/short_answer_field.go b/pkg/terminal/short_answer_field.go new file mode 100644 index 0000000..810fcd5 --- /dev/null +++ b/pkg/terminal/short_answer_field.go @@ -0,0 +1,57 @@ +package terminal + +import ( + "github.com/charmbracelet/bubbles/textinput" + tea "github.com/charmbracelet/bubbletea" +) + +type shortAnswerField struct { + textinput textinput.Model +} + +func NewShortAnswerField(p string) *shortAnswerField { + a := shortAnswerField{} + if p == "" { + p = "Your Answer here" + } + model := textinput.New() + model.Placeholder = p + model.Focus() + + a.textinput = model + return &a +} + +func (a *shortAnswerField) Blink() tea.Msg { + return textinput.Blink() +} + +func (a *shortAnswerField) Init() tea.Cmd { + return nil +} + +func (a *shortAnswerField) Update(msg tea.Msg) (Input, tea.Cmd) { + var cmd tea.Cmd + a.textinput, cmd = a.textinput.Update(msg) + return a, cmd +} + +func (a *shortAnswerField) View() string { + return a.textinput.View() +} + +func (a *shortAnswerField) Focus() tea.Cmd { + return a.textinput.Focus() +} + +func (a *shortAnswerField) SetValue(s string) { + a.textinput.SetValue(s) +} + +func (a *shortAnswerField) Blur() tea.Msg { + return a.textinput.Blur +} + +func (a *shortAnswerField) Value() string { + return a.textinput.Value() +}