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 | |
| parent | c17319d6fd23a0c85668ec55ee2a3cea9995b6fe (diff) | |
Started working on netwrok creation popup
Diffstat (limited to 'internal/client/ui')
| -rw-r--r-- | internal/client/ui/auth/auth.go | 4 | ||||
| -rw-r--r-- | internal/client/ui/core/core.go | 42 | ||||
| -rw-r--r-- | internal/client/ui/core/networkcreation/networkcreation.go | 81 | ||||
| -rw-r--r-- | internal/client/ui/core/networks/networks.go (renamed from internal/client/ui/networks/networks.go) | 0 | ||||
| -rw-r--r-- | internal/client/ui/field/field.go (renamed from internal/client/ui/auth/field/field.go) | 0 |
5 files changed, 117 insertions, 10 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/core/core.go b/internal/client/ui/core/core.go index bbc8576..5fb8e7b 100644 --- a/internal/client/ui/core/core.go +++ b/internal/client/ui/core/core.go @@ -8,10 +8,12 @@ import ( "github.com/charmbracelet/bubbles/spinner" "github.com/charmbracelet/bubbles/timer" tea "github.com/charmbracelet/bubbletea" + "github.com/charmbracelet/lipgloss" "github.com/kyren223/eko/internal/client/gateway" "github.com/kyren223/eko/internal/client/ui" + "github.com/kyren223/eko/internal/client/ui/core/networkcreation" + "github.com/kyren223/eko/internal/client/ui/core/networks" "github.com/kyren223/eko/internal/client/ui/loadscreen" - "github.com/kyren223/eko/internal/client/ui/networks" "github.com/kyren223/eko/pkg/snowflake" ) @@ -27,25 +29,26 @@ type Model struct { name string privKey ed25519.PrivateKey + networks networks.Model loading loadscreen.Model - timeout time.Duration timer timer.Model + timeout time.Duration connected bool id snowflake.ID - networks networks.Model + networkCreationPopup *networkcreation.Model } func New(privKey ed25519.PrivateKey, name string) Model { return Model{ name: name, privKey: privKey, + networks: networks.New(), loading: loadscreen.New(connectingToServer), - timeout: initialTimeout, timer: newTimer(initialTimeout), + timeout: initialTimeout, connected: false, - networks: networks.New(), } } @@ -58,7 +61,22 @@ func (m Model) View() string { return m.loading.View() } - return m.networks.View() + result := m.networks.View() + + result = lipgloss.Place( + ui.Width, ui.Height, + lipgloss.Left, lipgloss.Top, + result, + ) + + if m.networkCreationPopup != nil { + popup := m.networkCreationPopup.View() + x := (ui.Width - lipgloss.Width(popup)) / 2 + y := (ui.Height - lipgloss.Height(popup)) / 2 + result = ui.PlaceOverlay(x, y, popup, result) + } + + return result } func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { @@ -101,7 +119,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } } - switch msg.(type) { + switch msg := msg.(type) { case gateway.ConnectionLost: m.connected = false m.timeout = initialTimeout @@ -109,6 +127,16 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case ui.QuitMsg: gateway.Disconnect() + + case tea.KeyMsg: + key := msg.Type + switch key { + case tea.KeyCtrlN: + if m.networkCreationPopup == nil { + popup := networkcreation.New() + m.networkCreationPopup = &popup + } + } } return m, nil diff --git a/internal/client/ui/core/networkcreation/networkcreation.go b/internal/client/ui/core/networkcreation/networkcreation.go new file mode 100644 index 0000000..d41c734 --- /dev/null +++ b/internal/client/ui/core/networkcreation/networkcreation.go @@ -0,0 +1,81 @@ +package networkcreation + +import ( + "github.com/charmbracelet/bubbles/textinput" + tea "github.com/charmbracelet/bubbletea" + "github.com/charmbracelet/lipgloss" + "github.com/kyren223/eko/internal/client/ui/field" +) + +var ( + style = lipgloss.NewStyle().Border(lipgloss.ThickBorder()) + + focusedStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#5874FF")) + + fieldBlurredStyle = lipgloss.NewStyle(). + PaddingLeft(1). + Border(lipgloss.RoundedBorder()). + BorderForeground(lipgloss.Color("#007E8A")) + fieldFocusedStyle = fieldBlurredStyle.BorderForeground(focusedStyle.GetForeground()).Border(lipgloss.ThickBorder()) + + headerStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#54D7A9")) + + iconStyle = lipgloss.NewStyle().Border(lipgloss.ThickBorder(), false, false, true, false) +) + +type Model struct { + Width int + Height int + + name field.Model + icon textinput.Model + color textinput.Model + + Style lipgloss.Style +} + +func New() Model { + name := field.New(30) + name.Header = "Network Name" + name.HeaderStyle = headerStyle + name.FocusedStyle = fieldFocusedStyle + name.BlurredStyle = fieldBlurredStyle + name.Focus() + + icon := textinput.New() + icon.Prompt = "" + icon.Placeholder = "ic" + + color := textinput.New() + color.Prompt = "" + color.Placeholder = "000000" + + return Model{ + Width: 50, + Height: 10, + name: name, + icon: icon, + color: color, + Style: style, + } +} + +func (m Model) Init() tea.Cmd { + return nil +} + +func (m Model) View() string { + name := m.name.View() + + iconText := lipgloss.JoinHorizontal(lipgloss.Top, "icon: ", iconStyle.Render(m.icon.View())) + iconColor := lipgloss.JoinHorizontal(lipgloss.Top, "# ", iconStyle.Render(m.color.View())) + icon := lipgloss.JoinHorizontal(lipgloss.Top, iconText, " ", iconColor) + + content := lipgloss.JoinVertical(lipgloss.Left, name, "\n", icon) + popup := lipgloss.NewStyle().Width(m.Width).Height(m.Height).Render(content) + return m.Style.Render(popup) +} + +func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { + return m, nil +} diff --git a/internal/client/ui/networks/networks.go b/internal/client/ui/core/networks/networks.go index 05f8b27..05f8b27 100644 --- a/internal/client/ui/networks/networks.go +++ b/internal/client/ui/core/networks/networks.go diff --git a/internal/client/ui/auth/field/field.go b/internal/client/ui/field/field.go index dca4203..dca4203 100644 --- a/internal/client/ui/auth/field/field.go +++ b/internal/client/ui/field/field.go |
