mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-15 13:04:38 +02:00
New API to suspend a loop
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user