Add a write completed callback

This commit is contained in:
Kovid Goyal 2022-08-25 08:01:40 +05:30
parent ab66b3f4c0
commit 6a2393299b
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -83,6 +83,9 @@ type Loop struct {
// Called when the terminal is resize
OnResize func(loop *Loop, old_size ScreenSize, new_size ScreenSize) error
// Called when writing is done
OnWriteComplete func(loop *Loop) error
}
func (self *Loop) update_screen_size() error {
@ -370,6 +373,12 @@ func (self *Loop) Run() (err error) {
if err != nil {
return err
}
if self.OnWriteComplete != nil && len(self.write_buf) == 0 {
err = self.OnWriteComplete(self)
if err != nil {
return err
}
}
}
if selector.IsReadyToRead(tty_fd) {
read_buf = read_buf[:cap(read_buf)]