Nicer debug output of timers

This commit is contained in:
Kovid Goyal
2023-07-24 12:19:27 +05:30
parent ce35532aa5
commit f4b0183341
3 changed files with 24 additions and 6 deletions

View File

@@ -44,10 +44,6 @@ type timer struct {
callback TimerCallback
}
func (self *timer) update_deadline(now time.Time) {
self.deadline = now.Add(self.interval)
}
type Loop struct {
controlling_term *tty.Term
terminal_options TerminalStateOptions

View File

@@ -20,7 +20,7 @@ import (
var SIGNULL unix.Signal
func new_loop() *Loop {
l := Loop{controlling_term: nil, timers_temp: make([]*timer, 0, 8), timers: make([]*timer, 0, 8)}
l := Loop{controlling_term: nil}
l.terminal_options.alternate_screen = true
l.terminal_options.restore_colors = true
l.terminal_options.kitty_keyboard_mode = DISAMBIGUATE_KEYS | REPORT_ALTERNATE_KEYS | REPORT_ALL_KEYS_AS_ESCAPE_CODES | REPORT_TEXT_WITH_KEYS
@@ -280,7 +280,7 @@ func (self *Loop) run() (err error) {
self.escape_code_parser.Reset()
self.exit_code = 0
self.atomic_update_active = false
self.timers = make([]*timer, 0, 1)
self.timers, self.timers_temp = make([]*timer, 0, 8), make([]*timer, 0, 8)
no_timeout_channel := make(<-chan time.Time)
finalizer := ""

View File

@@ -4,11 +4,33 @@ package loop
import (
"fmt"
"reflect"
"runtime"
"time"
"golang.org/x/exp/slices"
"kitty/tools/tty"
)
var debugprintln = tty.DebugPrintln
func (self *timer) update_deadline(now time.Time) {
self.deadline = now.Add(self.interval)
}
func (self timer) String() string {
funcname := "<nil>"
if self.callback != nil {
p := reflect.ValueOf(self.callback).Pointer()
f := runtime.FuncForPC(p)
if f != nil {
funcname = f.Name()
}
}
return fmt.Sprintf("Timer(callback=%s, deadline=%s, repeats=%v)", funcname, self.deadline.Sub(time.Now()), self.repeats)
}
func (self *Loop) add_timer(interval time.Duration, repeats bool, callback TimerCallback) (IdType, error) {
if self.timers == nil {
return 0, fmt.Errorf("Cannot add timers before starting the run loop, add them in OnInitialize instead")