Skip to content
Myr

fix: reset cursor position on renderer exit (#1058)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

We need to reset the cursor position to the beginning of the line when the program stops or exit.

authored by Ayman Bagabas · committed by GitHub · parent 72760ee · Browse files · 3 files+14 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Related: https://github.com/charmbracelet/gum/issues/607

Diff stats

3 files+14 added−10 removed

  • other:+14 added−10 removed

3 files+14 added−10 removed

modified:examples/simple/testdata/TestApp.golden+1 added-1 removed
1[?25l[?2004h Hi. This program will exit in 10 seconds.23To quit sooner press ctrl-c, or press ctrl-z to suspend...4Hi. This program will exit in 9 seconds.5[?2004l[?25h[?1002l[?1003l[?1006l5 [?2004l[?25h[?1002l[?1003l[?1006l
modified:screen_test.go+9 added-9 removed
12 unmodified lines
13 }{14 {15 name: "clear_screen",16 cmds: []Cmd{ClearScreen},17 expected: "\x1b[?25l\x1b[?2004h\x1b[2J\x1b[1;1H\rsuccess\r\n\x1b[D\x1b[2K\x1b[?2004l\x1b[?25h\x1b[?1002l\x1b[?1003l\x1b[?1006l",17 expected: "\x1b[?25l\x1b[?2004h\x1b[2J\x1b[1;1H\rsuccess\r\n\x1b[D\x1b[2K\r\x1b[?2004l\x1b[?25h\x1b[?1002l\x1b[?1003l\x1b[?1006l",18 },19 {20 name: "altscreen",21 cmds: []Cmd{EnterAltScreen, ExitAltScreen},22 expected: "\x1b[?25l\x1b[?2004h\x1b[?1049h\x1b[2J\x1b[1;1H\x1b[?25l\x1b[?1049l\x1b[?25l\rsuccess\r\n\x1b[D\x1b[2K\x1b[?2004l\x1b[?25h\x1b[?1002l\x1b[?1003l\x1b[?1006l",22 expected: "\x1b[?25l\x1b[?2004h\x1b[?1049h\x1b[2J\x1b[1;1H\x1b[?25l\x1b[?1049l\x1b[?25l\rsuccess\r\n\x1b[D\x1b[2K\r\x1b[?2004l\x1b[?25h\x1b[?1002l\x1b[?1003l\x1b[?1006l",23 },24 {25 name: "altscreen_autoexit",26 cmds: []Cmd{EnterAltScreen},27 expected: "\x1b[?25l\x1b[?2004h\x1b[?1049h\x1b[2J\x1b[1;1H\x1b[?25l\rsuccess\r\n\x1b[2;0H\x1b[2K\x1b[?2004l\x1b[?25h\x1b[?1002l\x1b[?1003l\x1b[?1006l\x1b[?1049l\x1b[?25h",27 expected: "\x1b[?25l\x1b[?2004h\x1b[?1049h\x1b[2J\x1b[1;1H\x1b[?25l\rsuccess\r\n\x1b[2;0H\x1b[2K\r\x1b[?2004l\x1b[?25h\x1b[?1002l\x1b[?1003l\x1b[?1006l\x1b[?1049l\x1b[?25h",28 },29 {30 name: "mouse_cellmotion",31 cmds: []Cmd{EnableMouseCellMotion},32 expected: "\x1b[?25l\x1b[?2004h\x1b[?1002h\x1b[?1006h\rsuccess\r\n\x1b[D\x1b[2K\x1b[?2004l\x1b[?25h\x1b[?1002l\x1b[?1003l\x1b[?1006l",32 expected: "\x1b[?25l\x1b[?2004h\x1b[?1002h\x1b[?1006h\rsuccess\r\n\x1b[D\x1b[2K\r\x1b[?2004l\x1b[?25h\x1b[?1002l\x1b[?1003l\x1b[?1006l",33 },34 {35 name: "mouse_allmotion",36 cmds: []Cmd{EnableMouseAllMotion},37 expected: "\x1b[?25l\x1b[?2004h\x1b[?1003h\x1b[?1006h\rsuccess\r\n\x1b[D\x1b[2K\x1b[?2004l\x1b[?25h\x1b[?1002l\x1b[?1003l\x1b[?1006l",37 expected: "\x1b[?25l\x1b[?2004h\x1b[?1003h\x1b[?1006h\rsuccess\r\n\x1b[D\x1b[2K\r\x1b[?2004l\x1b[?25h\x1b[?1002l\x1b[?1003l\x1b[?1006l",38 },39 {40 name: "mouse_disable",41 cmds: []Cmd{EnableMouseAllMotion, DisableMouse},42 expected: "\x1b[?25l\x1b[?2004h\x1b[?1003h\x1b[?1006h\x1b[?1002l\x1b[?1003l\x1b[?1006l\rsuccess\r\n\x1b[D\x1b[2K\x1b[?2004l\x1b[?25h\x1b[?1002l\x1b[?1003l\x1b[?1006l",42 expected: "\x1b[?25l\x1b[?2004h\x1b[?1003h\x1b[?1006h\x1b[?1002l\x1b[?1003l\x1b[?1006l\rsuccess\r\n\x1b[D\x1b[2K\r\x1b[?2004l\x1b[?25h\x1b[?1002l\x1b[?1003l\x1b[?1006l",43 },44 {45 name: "cursor_hide",46 cmds: []Cmd{HideCursor},47 expected: "\x1b[?25l\x1b[?2004h\x1b[?25l\rsuccess\r\n\x1b[D\x1b[2K\x1b[?2004l\x1b[?25h\x1b[?1002l\x1b[?1003l\x1b[?1006l",47 expected: "\x1b[?25l\x1b[?2004h\x1b[?25l\rsuccess\r\n\x1b[D\x1b[2K\r\x1b[?2004l\x1b[?25h\x1b[?1002l\x1b[?1003l\x1b[?1006l",48 },49 {50 name: "cursor_hideshow",51 cmds: []Cmd{HideCursor, ShowCursor},52 expected: "\x1b[?25l\x1b[?2004h\x1b[?25l\x1b[?25h\rsuccess\r\n\x1b[D\x1b[2K\x1b[?2004l\x1b[?25h\x1b[?1002l\x1b[?1003l\x1b[?1006l",52 expected: "\x1b[?25l\x1b[?2004h\x1b[?25l\x1b[?25h\rsuccess\r\n\x1b[D\x1b[2K\r\x1b[?2004l\x1b[?25h\x1b[?1002l\x1b[?1003l\x1b[?1006l",53 },54 {55 name: "bp_stop_start",56 cmds: []Cmd{DisableBracketedPaste, EnableBracketedPaste},57 expected: "\x1b[?25l\x1b[?2004h\x1b[?2004l\x1b[?2004h\rsuccess\r\n\x1b[D\x1b[2K\x1b[?2004l\x1b[?25h\x1b[?1002l\x1b[?1003l\x1b[?1006l",57 expected: "\x1b[?25l\x1b[?2004h\x1b[?2004l\x1b[?2004h\rsuccess\r\n\x1b[D\x1b[2K\r\x1b[?2004l\x1b[?25h\x1b[?1002l\x1b[?1003l\x1b[?1006l",58 },59 }6061 for _, test := range tests {
20 unmodified lines
modified:standard_renderer.go+4 added
106 unmodified lines
107 r.mtx.Lock()108 defer r.mtx.Unlock()109110 r.execute(ansi.EraseEntireLine)111 // Move the cursor back to the beginning of the line112 r.execute("\r")113114 if r.useANSICompressor {115 if w, ok := r.out.(io.WriteCloser); ok {116 _ = w.Close()
16 unmodified lines
133 r.mtx.Lock()134 defer r.mtx.Unlock()135136 r.execute(ansi.EraseEntireLine)137 // Move the cursor back to the beginning of the line138 r.execute("\r")139}140141// listen waits for ticks on the ticker, or a signal to stop the renderer.142func (r *standardRenderer) listen() {
587 unmodified lines