summaryrefslogtreecommitdiff
path: root/internal/client
diff options
context:
space:
mode:
authorKyren223 <Kyren223@proton.me>2024-11-28 18:36:13 +0200
committerKyren223 <Kyren223@proton.me>2024-11-28 18:36:13 +0200
commit561ae1940e49c8cd36b7a62d854a3c9838902389 (patch)
treeeea064911173a535ab6e72083825f642b90668a5 /internal/client
parentd0356edef4dc0a14304b8890e8152911740ff87a (diff)
Added focus to network list
Diffstat (limited to 'internal/client')
-rw-r--r--internal/client/ui/core/core.go42
-rw-r--r--internal/client/ui/core/networklist/networklist.go19
2 files changed, 51 insertions, 10 deletions
diff --git a/internal/client/ui/core/core.go b/internal/client/ui/core/core.go
index 98158b3..140d5f3 100644
--- a/internal/client/ui/core/core.go
+++ b/internal/client/ui/core/core.go
@@ -18,6 +18,7 @@ import (
"github.com/kyren223/eko/internal/client/ui/core/state"
"github.com/kyren223/eko/internal/client/ui/loadscreen"
"github.com/kyren223/eko/internal/packet"
+ "github.com/kyren223/eko/pkg/assert"
"github.com/kyren223/eko/pkg/snowflake"
)
@@ -29,23 +30,31 @@ var (
timerInterval = 50 * time.Millisecond
)
+const (
+ FocusNetworkList = iota
+ FocusFrequencies
+ FocusChat
+ FocusUsers
+ FocusMax
+)
+
type Model struct {
name string
privKey ed25519.PrivateKey
+ id snowflake.ID
- networkList networklist.Model
- loading loadscreen.Model
- timer timer.Model
- timeout time.Duration
- connected bool
-
- id snowflake.ID
+ loading loadscreen.Model
+ timer timer.Model
+ timeout time.Duration
+ connected bool
networkCreationPopup *networkcreation.Model
+ networkList networklist.Model
+ focus int
}
func New(privKey ed25519.PrivateKey, name string) Model {
- return Model{
+ m := Model{
name: name,
privKey: privKey,
networkList: networklist.New(),
@@ -53,7 +62,11 @@ func New(privKey ed25519.PrivateKey, name string) Model {
timer: newTimer(initialTimeout),
timeout: initialTimeout,
connected: false,
+ focus: FocusNetworkList,
}
+ m.move(0) // Update focus
+
+ return m
}
func (m Model) Init() tea.Cmd {
@@ -202,3 +215,16 @@ func (m *Model) updateLoadScreenContent() {
func newTimer(timeout time.Duration) timer.Model {
return timer.NewWithInterval(timeout.Truncate(time.Second)+(time.Second/2), timerInterval)
}
+
+func (m *Model) move(direction int) {
+ focus := m.focus + direction
+ m.focus = max(0, min(FocusMax-1, focus))
+
+ m.networkList.Blur()
+ switch m.focus {
+ case FocusNetworkList:
+ m.networkList.Focus()
+ default:
+ assert.Never("missing switch statement field in move", "focus", m.focus)
+ }
+}
diff --git a/internal/client/ui/core/networklist/networklist.go b/internal/client/ui/core/networklist/networklist.go
index 7b191e8..92c0094 100644
--- a/internal/client/ui/core/networklist/networklist.go
+++ b/internal/client/ui/core/networklist/networklist.go
@@ -23,10 +23,14 @@ func IconStyle(fg, bg lipgloss.Color) lipgloss.Style {
return partialIconStyle.Foreground(fg).Background(bg)
}
-type Model struct{}
+type Model struct{
+ focus bool
+}
func New() Model {
- return Model{}
+ return Model{
+ focus: false,
+ }
}
func (m Model) Init() tea.Cmd {
@@ -53,6 +57,9 @@ func (m Model) View() string {
result := builder.String()
sep := lipgloss.NewStyle().Border(lipgloss.ThickBorder(), false, true, false, false).Height(ui.Height).Width(0)
+ if m.focus {
+ sep = sep.BorderForeground(colors.Focus)
+ }
result = lipgloss.JoinHorizontal(lipgloss.Top, result, sep.Render(""))
return result
@@ -61,3 +68,11 @@ func (m Model) View() string {
func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
return m, nil
}
+
+func (m *Model) Focus() {
+ m.focus = true
+}
+
+func (m *Model) Blur() {
+ m.focus = false
+}