diff options
| author | Kyren223 <Kyren223@proton.me> | 2024-11-24 00:16:23 +0200 |
|---|---|---|
| committer | Kyren223 <Kyren223@proton.me> | 2024-11-24 00:16:23 +0200 |
| commit | 54564f397db03e7e10db764947dd05b533e0d87b (patch) | |
| tree | d62d0736832e6a63a389eecfb4d9618ecb587d53 /internal/client/ui/auth | |
| parent | c17319d6fd23a0c85668ec55ee2a3cea9995b6fe (diff) | |
Started working on netwrok creation popup
Diffstat (limited to 'internal/client/ui/auth')
| -rw-r--r-- | internal/client/ui/auth/auth.go | 4 | ||||
| -rw-r--r-- | internal/client/ui/auth/field/field.go | 148 |
2 files changed, 1 insertions, 151 deletions
diff --git a/internal/client/ui/auth/auth.go b/internal/client/ui/auth/auth.go index 2656b76..903bb2a 100644 --- a/internal/client/ui/auth/auth.go +++ b/internal/client/ui/auth/auth.go @@ -18,7 +18,7 @@ import ( "github.com/kyren223/eko/internal/client/config" "github.com/kyren223/eko/internal/client/ui" - authfield "github.com/kyren223/eko/internal/client/ui/auth/field" + authfield "github.com/kyren223/eko/internal/client/ui/field" "github.com/kyren223/eko/internal/client/ui/choicepopup" "github.com/kyren223/eko/internal/client/ui/core" "github.com/kyren223/eko/pkg/assert" @@ -471,7 +471,6 @@ func (m *Model) Signup() tea.Cmd { return nil } - return ui.Transition(core.New(privKey, username)) } @@ -577,4 +576,3 @@ func expandPath(path string) string { } return path } - diff --git a/internal/client/ui/auth/field/field.go b/internal/client/ui/auth/field/field.go deleted file mode 100644 index dca4203..0000000 --- a/internal/client/ui/auth/field/field.go +++ /dev/null @@ -1,148 +0,0 @@ -package field - -import ( - "github.com/charmbracelet/bubbles/textinput" - tea "github.com/charmbracelet/bubbletea" - "github.com/charmbracelet/lipgloss" - - "github.com/kyren223/eko/internal/client/ui" -) - -type Model struct { - Input textinput.Model - Header string - Visisble bool - width int - - reveal bool - revealIcon string - concealIcon string - icon string - - FocusedStyle lipgloss.Style - BlurredStyle lipgloss.Style - FocusedTextStyle lipgloss.Style - BlurredTextStyle lipgloss.Style - ErrorStyle lipgloss.Style - HeaderStyle lipgloss.Style -} - -func New(width int) Model { - input := textinput.New() - input.Prompt = "" - input.Width = width - - m := Model{ - width: width, - Visisble: true, - Input: input, - } - - m.Blur() - m.SetRevealed(true) - - return m -} - -func (m Model) Init() tea.Cmd { - return nil -} - -func (m Model) View() string { - if !m.Visisble { - return "" - } - - - style := m.BlurredStyle - if m.Input.Focused() { - style = m.FocusedStyle - } - - header := m.HeaderStyle.Render(m.Header) - if m.Input.Err != nil { - error := m.Input.Err.Error() - style = style.BorderForeground(m.ErrorStyle.GetForeground()) - header = lipgloss.NewStyle(). - MaxWidth(m.width). - Render(header + m.ErrorStyle.Render(" - "+error)) - } - - field := ui.AddBorderHeader(header, 1, style, m.Input.View()+m.icon) - return field -} - -func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { - if !m.Visisble { - return m, nil - } - - var cmd tea.Cmd - m.Input, cmd = m.Input.Update(msg) - return m, cmd -} - -func (m *Model) Focus() tea.Cmd { - m.Input.PromptStyle = m.FocusedTextStyle - m.Input.TextStyle = m.FocusedTextStyle - return m.Input.Focus() -} - -func (m *Model) Blur() { - m.Input.Blur() - m.Input.PromptStyle = m.BlurredTextStyle - m.Input.TextStyle = m.BlurredTextStyle -} - -func (m *Model) SetWidth(width int) { - m.width = width - m.recalculateWidth() -} - -func (m Model) Width() int { - return m.width -} - -func (m *Model) SetRevealed(revealed bool) { - m.reveal = revealed - if m.reveal { - m.Input.EchoMode = textinput.EchoNormal - m.icon = m.revealIcon - } else { - m.Input.EchoMode = textinput.EchoPassword - m.icon = m.concealIcon - } - m.recalculateWidth() -} - -func (m Model) Revealed() bool { - return m.reveal -} - -func (m *Model) SetRevealIcon(icon string) { - m.revealIcon = icon - if m.reveal { - m.icon = icon - } - m.recalculateWidth() -} - -func (m Model) RevealIcon() string { - return m.revealIcon -} - -func (m *Model) SetConcealIcon(icon string) { - m.concealIcon = icon - if !m.reveal { - m.icon = icon - } - m.recalculateWidth() -} - -func (m Model) ConcealIcon() string { - return m.concealIcon -} - -func (m *Model) recalculateWidth() { - m.Input.Width = m.width - lipgloss.Width(m.icon) -} |
