refactor: move some of client network logic into mainscreen

This commit is contained in:
2021-11-29 23:07:21 +02:00
parent 57ad235db7
commit 35ab2cf927
3 changed files with 20 additions and 42 deletions
+9
View File
@@ -22,12 +22,14 @@ import (
"strings"
tea "github.com/charmbracelet/bubbletea"
"github.com/illusionman1212/gorc/client"
"github.com/illusionman1212/gorc/parser"
)
type State struct {
content string
Reader *bufio.Reader
Client *client.Client
}
func (s State) Update(msg tea.Msg) (State, tea.Cmd) {
@@ -39,6 +41,13 @@ func (s State) Update(msg tea.Msg) (State, tea.Cmd) {
fullMsg := fmt.Sprintf("%s %s %s", message.Source, message.Command, strings.Join(message.Parameters, " "))
s.content += fullMsg
// TODO: handle different commands
switch message.Command {
case "PING":
s.Client.SendCommand("PONG")
break
}
return s, s.readFromServer
}