Skip to content

Commit

Permalink
feat: move custom filed in own file
Browse files Browse the repository at this point in the history
  • Loading branch information
mukezhz committed Jan 7, 2024
1 parent 18244b9 commit a0107cb
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 102 deletions.
102 changes: 0 additions & 102 deletions pkg/terminal/input.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package terminal

import (
"github.com/charmbracelet/bubbles/textarea"
"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
)

Expand All @@ -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()
}
55 changes: 55 additions & 0 deletions pkg/terminal/long_answer_field.go
Original file line number Diff line number Diff line change
@@ -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()
}
57 changes: 57 additions & 0 deletions pkg/terminal/short_answer_field.go
Original file line number Diff line number Diff line change
@@ -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()
}

0 comments on commit a0107cb

Please sign in to comment.