diff options
Diffstat (limited to 'internal/client/ui')
| -rw-r--r-- | internal/client/ui/auth/auth.go | 3 | ||||
| -rw-r--r-- | internal/client/ui/chat/chat.go | 2 | ||||
| -rw-r--r-- | internal/client/ui/core/core.go | 47 | ||||
| -rw-r--r-- | internal/client/ui/loadscreen/loadscreen.go | 2 |
4 files changed, 33 insertions, 21 deletions
diff --git a/internal/client/ui/auth/auth.go b/internal/client/ui/auth/auth.go index 2e81a16..2656b76 100644 --- a/internal/client/ui/auth/auth.go +++ b/internal/client/ui/auth/auth.go @@ -248,9 +248,6 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { cmd := m.SetSignup(!m.signup) return m, cmd - case tea.KeyCtrlC: - return m, tea.Quit - case tea.KeyCtrlT: if m.popup == nil && (m.focusIndex == passphraseField || m.focusIndex == passphraseConfirmField) { m.fields[m.focusIndex].SetRevealed(!m.fields[m.focusIndex].Revealed()) diff --git a/internal/client/ui/chat/chat.go b/internal/client/ui/chat/chat.go index b87071e..c69d0fd 100644 --- a/internal/client/ui/chat/chat.go +++ b/internal/client/ui/chat/chat.go @@ -76,8 +76,6 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { case tea.KeyMsg: switch msg.Type { - case tea.KeyEsc, tea.KeyCtrlC: - return m, tea.Quit case tea.KeyEnter: value := m.textarea.Value() diff --git a/internal/client/ui/core/core.go b/internal/client/ui/core/core.go index 1dbaef5..12b8b42 100644 --- a/internal/client/ui/core/core.go +++ b/internal/client/ui/core/core.go @@ -2,35 +2,52 @@ package core import ( "crypto/ed25519" - "fmt" + "time" tea "github.com/charmbracelet/bubbletea" + "github.com/kyren223/eko/internal/client/gateway" + "github.com/kyren223/eko/internal/client/ui/loadscreen" ) -type Model struct{} +var ( + connectingToServer = "Connecting to server.." + connectionFailed = "Connection failed - retrying in %d sec..." +) -func New(privKey ed25519.PrivateKey, name string) Model { +type Model struct { + privKey ed25519.PrivateKey + name string + + loading loadscreen.Model + connected bool +} - // Connectiong to server... - // Connection failed - retrying in 3 sec... - // Connection failed - retrying in 3 sec... - return Model{} +func New(privKey ed25519.PrivateKey, name string) Model { + return Model{ + privKey: privKey, + name: name, + loading: loadscreen.New(connectingToServer), + connected: false, + } } func (m Model) Init() tea.Cmd { - return nil + return tea.Batch(gateway.Connect(m.privKey, 5*time.Second), m.loading.Init()) } func (m Model) View() string { - return fmt.Sprintf( - "%s", - "", - ) + if !m.connected { + return m.loading.View() + } + + return "" } func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { - switch msg := msg.(type) { - default: - return m, nil + if !m.connected { + var loadscreenCmd tea.Cmd + m.loading, loadscreenCmd = m.loading.Update(msg) + return m, loadscreenCmd } + return m, nil } diff --git a/internal/client/ui/loadscreen/loadscreen.go b/internal/client/ui/loadscreen/loadscreen.go index 6f4610a..4fe9a7d 100644 --- a/internal/client/ui/loadscreen/loadscreen.go +++ b/internal/client/ui/loadscreen/loadscreen.go @@ -144,7 +144,7 @@ func (m Model) View() string { ) } -func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { var cmd tea.Cmd m.sp, cmd = m.sp.Update(msg) return m, cmd |
