diff options
| author | Kyren223 <Kyren223@proton.me> | 2024-11-05 13:59:35 +0200 |
|---|---|---|
| committer | Kyren223 <Kyren223@proton.me> | 2024-11-05 13:59:35 +0200 |
| commit | bdf7d2c2d2ee578edc3b6ecacbb9b0236e591b57 (patch) | |
| tree | 5b0c649d1dfd2a6dc42c88cf881d50bbd177b35c /internal/client/ui/auth/field | |
| parent | 547acbb554e1f0e75b4200c1e5e6e404feebc58d (diff) | |
feat: working on the client UI
Diffstat (limited to 'internal/client/ui/auth/field')
| -rw-r--r-- | internal/client/ui/auth/field/field.go | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/internal/client/ui/auth/field/field.go b/internal/client/ui/auth/field/field.go new file mode 100644 index 0000000..afc55b1 --- /dev/null +++ b/internal/client/ui/auth/field/field.go @@ -0,0 +1,67 @@ +package field + +import ( + "strings" + + "github.com/charmbracelet/bubbles/textinput" + tea "github.com/charmbracelet/bubbletea" + "github.com/charmbracelet/lipgloss" +) + + +type Model struct { + Input textinput.Model + Style lipgloss.Style + FocusedStyle lipgloss.Style + BlurredStyle lipgloss.Style + ErrorStyle lipgloss.Style +} + +func New(width int) Model { + t := textinput.New() + t.Width = width + t.CharLimit = width + t.Prompt = "" + + m := Model{ + Input: t, + } + + m.Blur() + + return m +} + +func (m Model) Init() tea.Cmd { + return nil +} + +func (m Model) View() string { + var builder strings.Builder + + builder.WriteString(m.Style.Render(m.Input.View())) + builder.WriteRune('\n') + if m.Input.Err != nil { + builder.WriteString(m.ErrorStyle.Render(m.Input.Err.Error())) + } + + return builder.String() +} + +func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { + var cmd tea.Cmd + m.Input, cmd = m.Input.Update(msg) + return m, cmd +} + +func (m *Model) Focus() tea.Cmd { + m.Input.PromptStyle = m.FocusedStyle + m.Input.TextStyle = m.FocusedStyle + return m.Input.Focus() +} + +func (m *Model) Blur() { + m.Input.Blur() + m.Input.PromptStyle = m.BlurredStyle + m.Input.TextStyle = m.BlurredStyle +} |
