@@ -297,10 +297,7 @@ func (self *Loop) DebugPrintln(args ...any) {
297297 const limit = 2048
298298 msg := fmt .Sprintln (args ... )
299299 for i := 0 ; i < len (msg ); i += limit {
300- end := i + limit
301- if end > len (msg ) {
302- end = len (msg )
303- }
300+ end := min (i + limit , len (msg ))
304301 self .QueueWriteString ("\x1b P@kitty-print|" )
305302 self .QueueWriteString (base64 .StdEncoding .EncodeToString ([]byte (msg [i :end ])))
306303 self .QueueWriteString ("\x1b \\ " )
@@ -311,11 +308,12 @@ func (self *Loop) DebugPrintln(args ...any) {
311308func (self * Loop ) Run () (err error ) {
312309 defer func () {
313310 if r := recover (); r != nil {
314- pcs := make ([]uintptr , 256 )
311+ pcs := make ([]uintptr , 512 )
315312 n := runtime .Callers (2 , pcs )
313+ lines := []string {}
316314 frames := runtime .CallersFrames (pcs [:n ])
317315 err = fmt .Errorf ("Panicked: %s" , r )
318- fmt . Fprintf ( os . Stderr , "\r \n Panicked with error: %s\r \n Stacktrace (most recent call first):\r \n " , r )
316+ lines = append ( lines , fmt . Sprintf ( "\r \n Panicked with error: %s\r \n Stacktrace (most recent call first):\r \n " , r ) )
319317 found_first_frame := false
320318 for frame , more := frames .Next (); more ; frame , more = frames .Next () {
321319 if ! found_first_frame {
@@ -324,8 +322,11 @@ func (self *Loop) Run() (err error) {
324322 }
325323 found_first_frame = true
326324 }
327- fmt . Fprintf ( os . Stderr , "%s\r \n \t %s:%d\r \n " , frame .Function , frame .File , frame .Line )
325+ lines = append ( lines , fmt . Sprintf ( "%s\r \n \t %s:%d\r \n " , frame .Function , frame .File , frame .Line ) )
328326 }
327+ text := strings .Join (lines , "" )
328+ os .Stderr .WriteString (text )
329+ tty .DebugPrintln (strings .TrimSpace (text ))
329330 if self .terminal_options .Alternate_screen {
330331 term , err := tty .OpenControllingTerm (tty .SetRaw )
331332 if err == nil {
0 commit comments