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
+6 -9
View File
@@ -92,21 +92,18 @@ func (s State) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
tlsEnabled := s.UI.Login.TLS
s.UI.CurrentScreen = MainScreen
s.UI.MainScreen.CurrentChannel = channel
// create new client with the provided host and port
(*s.Client) = client.NewClient(host, port, tlsEnabled)
s.Client.Register(nickname, password, channel)
if tlsEnabled {
r := bufio.NewReaderSize(s.Client.TlsConn, 512)
s.UI.MainScreen.Reader = r
} else {
r := bufio.NewReaderSize(s.Client.TcpConn, 512)
s.UI.MainScreen.Reader = r
}
// 512 bytes as a base + 8192 additional bytes for tags
r := bufio.NewReaderSize(s.Client.TcpConn, 8192+512)
s.UI.MainScreen.ConnReader = r
return s, mainscreen.InitialRead
go s.UI.MainScreen.ReadLoop()
return s, textinput.Blink
}
// switch between which screen is currently active and update its state
+3 -3
View File
@@ -19,10 +19,10 @@ package app
import tea "github.com/charmbracelet/bubbletea"
func (s *State) Quit() tea.Msg {
if s.Client.TlsConn != nil {
s.Client.SendCommand("QUIT")
s.Client.TlsConn.Close()
if s.Client.Quit != nil {
close(s.Client.Quit)
}
if s.Client.TcpConn != nil {
s.Client.SendCommand("QUIT")
s.Client.TcpConn.Close()