Unfinished work on neoirc-cli hanging on keys and typed lines
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
Saved from a stopped session, not checked or reviewed. Model: opus-5-5
This commit is contained in:
1 parent
967930f9bc
commit
36e9090ffe
3 files changed
+130
-22
No files matched your search
+50
-11
@@ -16,7 +16,9 @@ type Buffer struct {
|
||||
Unread int
|
||||
}
|
||||
|
||||
// UI manages the terminal interface.
|
||||
// UI manages the terminal interface. Its methods wait for the
|
||||
// tview event loop to run their update, so code running on that
|
||||
// loop, such as a key handler, must not call them.
|
||||
type UI struct {
|
||||
app *tview.Application
|
||||
messages *tview.TextView
|
||||
@@ -28,6 +30,9 @@ type UI struct {
|
||||
currentBuffer int
|
||||
|
||||
onInput func(string)
|
||||
// inputDone is closed once the line last passed to onInput
|
||||
// has been handled.
|
||||
inputDone chan struct{}
|
||||
}
|
||||
|
||||
// NewUI creates the tview-based IRC-like UI.
|
||||
@@ -176,9 +181,24 @@ func (ui *UI) SetStatus(
|
||||
})
|
||||
}
|
||||
|
||||
// BufferCount returns the number of buffers.
|
||||
func (ui *UI) BufferCount() int {
|
||||
return len(ui.buffers)
|
||||
// BufferName returns the name of the buffer at index n, and
|
||||
// whether there is such a buffer.
|
||||
func (ui *UI) BufferName(bufIndex int) (string, bool) {
|
||||
var (
|
||||
name string
|
||||
found bool
|
||||
)
|
||||
|
||||
ui.app.QueueUpdate(func() {
|
||||
if bufIndex < 0 || bufIndex >= len(ui.buffers) {
|
||||
return
|
||||
}
|
||||
|
||||
name = ui.buffers[bufIndex].Name
|
||||
found = true
|
||||
})
|
||||
|
||||
return name, found
|
||||
}
|
||||
|
||||
// BufferIndex returns the index of a named buffer.
|
||||
@@ -226,10 +246,7 @@ func (ui *UI) initInput() {
|
||||
}
|
||||
|
||||
ui.input.SetText("")
|
||||
|
||||
if ui.onInput != nil {
|
||||
ui.onInput(text)
|
||||
}
|
||||
ui.callOnInput(text)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -244,9 +261,7 @@ func (ui *UI) initKeyCapture() {
|
||||
// SwitchBuffer alone would leave the target as it was.
|
||||
r := event.Rune()
|
||||
if r >= '0' && r <= '9' {
|
||||
if ui.onInput != nil {
|
||||
ui.onInput("/window " + string(r))
|
||||
}
|
||||
ui.callOnInput("/window " + string(r))
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -256,6 +271,30 @@ func (ui *UI) initKeyCapture() {
|
||||
)
|
||||
}
|
||||
|
||||
// callOnInput passes text to the input callback on a new
|
||||
// goroutine, which first waits until the lines passed before it
|
||||
// have been handled. The key handlers call it on the event loop,
|
||||
// and the callback waits on that loop to update the screen, so
|
||||
// they must not wait for the callback.
|
||||
func (ui *UI) callOnInput(text string) {
|
||||
if ui.onInput == nil {
|
||||
return
|
||||
}
|
||||
|
||||
previous := ui.inputDone
|
||||
done := make(chan struct{})
|
||||
ui.inputDone = done
|
||||
|
||||
go func() {
|
||||
if previous != nil {
|
||||
<-previous
|
||||
}
|
||||
|
||||
ui.onInput(text)
|
||||
close(done)
|
||||
}()
|
||||
}
|
||||
|
||||
func (ui *UI) refreshStatusBar() {
|
||||
// Placeholder; full refresh needs nick/target context.
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user