summaryrefslogtreecommitdiff
path: root/internal/client/ui/core/core.go
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/ui/core/core.go
parentd0356edef4dc0a14304b8890e8152911740ff87a (diff)
Added focus to network list
Diffstat (limited to 'internal/client/ui/core/core.go')
-rw-r--r--internal/client/ui/core/core.go42
1 files changed, 34 insertions, 8 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)
+ }
+}