feat: BIG changes

* use commands constants
* use a separate goroutine to read from connection
* refactor connection reading and ui updating
* add sidepanel for users in channel
* other cleanups
This commit is contained in:
2022-01-09 04:30:22 +02:00
parent 1168a2a4dd
commit 8a7e1568ae
11 changed files with 280 additions and 97 deletions
+17 -15
View File
@@ -18,27 +18,29 @@ package mainscreen
import (
"log"
"strings"
tea "github.com/charmbracelet/bubbletea"
"github.com/illusionman1212/gorc/parser"
)
type InitialReadMsg struct{}
func (s *State) ReadLoop() {
for {
select {
case <-s.Client.Quit:
return
default:
msg, err := s.ConnReader.ReadString('\n')
if err != nil {
log.Fatal(err)
}
func InitialRead() tea.Msg {
return InitialReadMsg{}
}
type ReceivedIRCCommandMsg struct {
Msg string
}
func (s State) readFromServer() tea.Msg {
msg, err := s.Reader.ReadString('\n')
if err != nil {
log.Print(err)
msg = strings.Replace(msg, "\r\n", "", 1)
if ircMessage, valid := parser.ParseIRCMessage(msg); valid {
s.HandleCommand(ircMessage)
}
}
}
return ReceivedIRCCommandMsg{Msg: msg}
}
type SendPrivMsg struct {