New API to suspend a loop

This commit is contained in:
Kovid Goyal
2023-02-14 22:27:41 +05:30
parent 9aaca33f15
commit 67436a48cd
3 changed files with 41 additions and 7 deletions

View File

@@ -58,7 +58,8 @@ type Loop struct {
pending_writes []*write_msg
on_SIGTSTP func() error
// Send strings to this channel to queue writes in a thread safe way
// Suspend the loop restoring terminal state. Call the return resume function to restore the loop
Suspend func() (func() error, error)
// Callbacks

View File

@@ -290,6 +290,29 @@ func (self *Loop) run() (err error) {
}
}
self.Suspend = func() (func() error, error) {
write_id := self.QueueWriteString(self.terminal_options.ResetStateEscapeCodes())
needs_reset_escape_codes = false
err := self.wait_for_write_to_complete(write_id, tty_write_channel, write_done_channel, 2*time.Second)
if err != nil {
return nil, err
}
resume, err := controlling_term.Suspend()
if err != nil {
return nil, err
}
return func() (err error) {
err = resume()
if err != nil {
return
}
write_id = self.QueueWriteString(self.terminal_options.SetStateEscapeCodes())
needs_reset_escape_codes = true
return self.wait_for_write_to_complete(write_id, tty_write_channel, write_done_channel, 2*time.Second)
}, nil
}
self.on_SIGTSTP = func() error {
write_id := self.QueueWriteString(self.terminal_options.ResetStateEscapeCodes())
needs_reset_escape_codes = false