diff options
author | Hubert Hirtz <hubert@hirtz.pm> | 2021-05-18 21:26:03 +0200 |
---|---|---|
committer | Hubert Hirtz <hubert@hirtz.pm> | 2021-05-20 22:45:48 +0200 |
commit | 7835d39dda5f7a1dde3056de3dd8a84913b94c14 (patch) | |
tree | cb989997170121baee7d227b7e909a624c2bdbf2 /window.go | |
parent | Add /mode command (diff) |
Fix races conditions
Refactor:
- Split out reads/writes from irc.Session to irc.ChanInOut,
- Message handling is now manual, messages must be passed to
irc.Session.HandleMessage for its state to change,
- Remove data-race-prone App.addLineNow (called from both the main
eventLoop and irc loops) and add App.addStatusLine (to be called from
the main event loop) and App.queueStatusLine (to be called from other
goroutines). These two functions now write to both the current buffer
and the home buffer,
- add a irc.Typings.List function that locks the list of typings before
accessing it.
Changes as I went through the whole code...
- CAP handling is fixed (especially CAP DEL and CAP ACK),
- irc.Session now handles PREFIX,
- unhandled messages are now shown, except for some rare cases where
it's completely useless to show them.
Diffstat (limited to 'window.go')
-rw-r--r-- | window.go | 23 |
1 files changed, 15 insertions, 8 deletions
@@ -22,28 +22,35 @@ var homeMessages = []string{ func (app *App) initWindow() { hmIdx := rand.Intn(len(homeMessages)) app.win.AddBuffer(Home) - app.addLineNow("", ui.Line{ + app.win.AddLine(Home, false, ui.Line{ Head: "--", Body: homeMessages[hmIdx], + At: time.Now(), }) } -func (app *App) addLineNow(buffer string, line ui.Line) { +func (app *App) queueStatusLine(line ui.Line) { if line.At.IsZero() { line.At = time.Now() } - app.win.AddLine(buffer, false, line) - app.draw() + app.events <- event{ + src: uiEvent, + content: line, + } } -func (app *App) draw() { - if app.s != nil { - app.setStatus() +func (app *App) addStatusLine(line ui.Line) { + buffer := app.win.CurrentBuffer() + if buffer != Home { + app.win.AddLine(Home, false, line) } - app.win.Draw() + app.win.AddLine(buffer, false, line) } func (app *App) setStatus() { + if app.s == nil { + return + } ts := app.s.Typings(app.win.CurrentBuffer()) status := "" if 3 < len(ts) { |