summaryrefslogtreecommitdiff
path: root/internal/client/ui/core
diff options
context:
space:
mode:
Diffstat (limited to 'internal/client/ui/core')
-rw-r--r--internal/client/ui/core/core.go42
-rw-r--r--internal/client/ui/core/networkcreation/networkcreation.go81
-rw-r--r--internal/client/ui/core/networks/networks.go91
3 files changed, 207 insertions, 7 deletions
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/core/networks/networks.go b/internal/client/ui/core/networks/networks.go
new file mode 100644
index 0000000..05f8b27
--- /dev/null
+++ b/internal/client/ui/core/networks/networks.go
@@ -0,0 +1,91 @@
+package networks
+
+import (
+ "strings"
+
+ tea "github.com/charmbracelet/bubbletea"
+ "github.com/charmbracelet/lipgloss"
+ "github.com/kyren223/eko/internal/client/ui"
+ "github.com/kyren223/eko/internal/data"
+)
+
+var (
+ style = lipgloss.NewStyle().Border(lipgloss.ThickBorder(), true, false)
+ networkStyle = lipgloss.NewStyle().Width(6).Height(3).PaddingTop(1).Margin(0, 1, 1).
+ Align(lipgloss.Center).
+ Foreground(lipgloss.Color("#ffbf00")).Background(lipgloss.Color("#4a3d5c")).
+ Border(lipgloss.ThickBorder(), false, false)
+ networks = []string{
+ "󰜈 ",
+ " ",
+ "Kr",
+ " ",
+ // "Test",
+ // "██████\n██████\n██████",
+ // " ▄▄▄▄ \n █ █ \n ▀▀▀▀ ",
+ // " \n 󰜈 \n ",
+ // "Hmm",
+ // "Another",
+ }
+
+ reverse = lipgloss.NewStyle().Foreground(lipgloss.Color("#20999D"))
+ // Render("")
+
+ label1 = lipgloss.NewStyle().
+ Background(lipgloss.Color("#20999D")).Foreground(lipgloss.Color("#000000")).
+ Padding(0, 1).
+ Bold(true).
+ Render("󰜈")
+ label2 = reverse.Render("") + label1 + reverse.Render("")
+ label3 = ""
+ label4 = lipgloss.NewStyle().
+ Foreground(lipgloss.Color("#20999D")).
+ Bold(true).
+ Render("󰜈")
+
+ name = lipgloss.NewStyle().
+ Bold(true).
+ Render("Kyren223")
+ user = lipgloss.JoinHorizontal(lipgloss.Center, label4, " ", name)
+)
+
+type Model struct {
+ networks []string
+ a data.Network
+}
+
+func New() Model {
+ return Model{
+ networks: networks,
+ }
+}
+
+func (m Model) Init() tea.Cmd {
+ return nil
+}
+
+func (m Model) View() string {
+ // border := lipgloss.ThickBorder()
+ var builder strings.Builder
+
+ // top := strings.Repeat(border.Top, 6)
+ // builder.WriteString(fmt.Sprintf("%s%s%s\n", border.TopLeft, top, border.TopRight))
+ builder.WriteString("\n")
+ for _, network := range m.networks {
+ builder.WriteString(networkStyle.Render(network) + "\n")
+
+ }
+ // bottom := strings.Repeat(border.Bottom, 6)
+ // builder.WriteString(fmt.Sprintf("\n%s%s%s", border.BottomLeft, bottom, border.BottomRight))
+
+ result := builder.String()
+
+ sep := lipgloss.NewStyle().Border(lipgloss.ThickBorder(), false, true, false, false).Height(ui.Height).Width(0)
+ result = lipgloss.JoinHorizontal(lipgloss.Top, result, sep.Render(""))
+
+ return result + user
+}
+
+func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
+ return m, nil
+}