diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2024-11-07 11:25:14 +0100 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2024-11-09 17:20:19 +0100 |
commit | 0454e2acdb8eabe836fd1c9e717f1f727647061a (patch) | |
tree | f53cc63e12a1d79e7dc216e122aac32cae2e452c /xA | |
parent | fd7bb18be98d26b82a60230b7b4676895b51f7d7 (diff) | |
download | xK-0454e2acdb8eabe836fd1c9e717f1f727647061a.tar.gz xK-0454e2acdb8eabe836fd1c9e717f1f727647061a.tar.xz xK-0454e2acdb8eabe836fd1c9e717f1f727647061a.zip |
WIP: xA: update for new lxdrgen-go
Diffstat (limited to 'xA')
-rw-r--r-- | xA/xA.go | 79 |
1 files changed, 33 insertions, 46 deletions
@@ -171,13 +171,13 @@ var ( // Connection state: commandSeq uint32 - commandCallbacks map[uint32]callback + commandCallbacks = make(map[uint32]callback) buffers []buffer bufferCurrent string bufferLast string - servers map[string]*server + servers = make(map[string]*server) // Widgets: @@ -269,10 +269,10 @@ func relayMakeReceiver( return p } -func relayWriteMessage(conn net.Conn, commandData any) bool { +func relayWriteMessage(conn net.Conn, data RelayCommandData) bool { m := RelayCommandMessage{ CommandSeq: commandSeq, - Data: RelayCommandData{commandData}, + Data: data, } commandSeq++ @@ -325,22 +325,21 @@ func bufferByName(name string) *buffer { } func relayProcessMessage(m *RelayEventMessage) { - switch data := m.Data.Interface.(type) { - case RelayEventDataError: + switch data := m.Data.Variant.(type) { + case *RelayEventDataError: relayProcessCallbacks(data.CommandSeq, data.Error, nil) - case RelayEventDataResponse: + case *RelayEventDataResponse: relayProcessCallbacks(data.CommandSeq, "", &data.Data) - case RelayEventDataPing: + case *RelayEventDataPing: // TODO(p): Send the command. - _ = RelayCommandDataPingResponse{ - Command: RelayCommandPingResponse, - EventSeq: m.EventSeq, + _ = RelayCommandData{ + Variant: &RelayCommandDataPingResponse{EventSeq: m.EventSeq}, } - case RelayEventDataBufferLine: + case *RelayEventDataBufferLine: // TODO(p): Process all remaining message kinds. - case RelayEventDataBufferUpdate: + case *RelayEventDataBufferUpdate: b := bufferByName(data.BufferName) if b == nil { buffers = append(buffers, buffer{}) @@ -350,19 +349,17 @@ func relayProcessMessage(m *RelayEventMessage) { hidingToggled := b.hideUnimportant != data.HideUnimportant b.hideUnimportant = data.HideUnimportant - // TODO(p): Change the generator to add a Kind method, - // so that it always has a proper value. - //b.kind = data.Context.Kind + b.kind = data.Context.Variant.Kind() b.serverName = "" - switch context := data.Context.Interface.(type) { - case RelayBufferContextServer: + switch context := data.Context.Variant.(type) { + case *RelayBufferContextServer: b.serverName = context.ServerName - case RelayBufferContextChannel: + case *RelayBufferContextChannel: b.serverName = context.ServerName b.modes = context.Modes // TODO(p): Convert the items. b.topic = nil - case RelayBufferContextPrivateMessage: + case *RelayBufferContextPrivateMessage: b.serverName = context.ServerName } @@ -375,7 +372,7 @@ func relayProcessMessage(m *RelayEventMessage) { refreshBuffer(b) } } - case RelayEventDataBufferStats: + case *RelayEventDataBufferStats: b := bufferByName(data.BufferName) if b == nil { return @@ -386,7 +383,7 @@ func relayProcessMessage(m *RelayEventMessage) { b.highlighted = data.Highlighted refreshIcon() - case RelayEventDataBufferRename: + case *RelayEventDataBufferRename: b := bufferByName(data.BufferName) if b == nil { return @@ -402,16 +399,16 @@ func relayProcessMessage(m *RelayEventMessage) { if data.BufferName == bufferLast { bufferLast = data.New } - case RelayEventDataBufferRemove: + case *RelayEventDataBufferRemove: buffers = slices.DeleteFunc(buffers, func(b buffer) bool { return b.bufferName == data.BufferName }) refreshBufferList() refreshIcon() - case RelayEventDataBufferActivate: + case *RelayEventDataBufferActivate: // TODO(p): Process all remaining message kinds. - case RelayEventDataBufferInput: + case *RelayEventDataBufferInput: b := bufferByName(data.BufferName) if b == nil { return @@ -421,7 +418,7 @@ func relayProcessMessage(m *RelayEventMessage) { b.historyAt++ } b.history = append(b.history, data.Text) - case RelayEventDataBufferClear: + case *RelayEventDataBufferClear: b := bufferByName(data.BufferName) if b == nil { return @@ -432,37 +429,28 @@ func relayProcessMessage(m *RelayEventMessage) { refreshBuffer(b) } - case RelayEventDataServerUpdate: + case *RelayEventDataServerUpdate: s, existed := servers[data.ServerName] if !existed { s = &server{} servers[data.ServerName] = s } - // TODO(p): Change the generator to add a State method, - // so that it always has a proper value. - s.user = "" - s.userModes = "" - switch state := data.Data.Interface.(type) { - case *RelayServerDataDisconnected: - s.state = state.State - case *RelayServerDataConnecting: - s.state = state.State - case *RelayServerDataConnected: - s.state = state.State + s.state = data.Data.Variant.State() + switch state := data.Data.Variant.(type) { case *RelayServerDataRegistered: - s.state = state.State s.user = state.User s.userModes = state.UserModes - case *RelayServerDataDisconnecting: - s.state = state.State + default: + s.user = "" + s.userModes = "" } refreshPrompt() - case RelayEventDataServerRename: + case *RelayEventDataServerRename: servers[data.New] = servers[data.ServerName] delete(servers, data.ServerName) - case RelayEventDataServerRemove: + case *RelayEventDataServerRemove: delete(servers, data.ServerName) } } @@ -489,9 +477,8 @@ func relayRun() { // - Or maybe use a channel just for the signalling. // - Sending (semi-)synchronously is also an option, perhaps. // TODO(p): Handle any errors here. - _ = relayWriteMessage(conn, &RelayCommandDataHello{ - Command: RelayCommandHello, - Version: RelayVersion, + _ = relayWriteMessage(conn, RelayCommandData{ + Variant: &RelayCommandDataHello{Version: RelayVersion}, }) relayMessages := relayMakeReceiver(backendContext, conn) |