File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed
Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,11 @@ static editor_ctx_t *signal_context = NULL;
3232void terminal_disable_raw_mode (editor_ctx_t * ctx , int fd ) {
3333 /* Don't even check the return value as it's too late. */
3434 if (ctx && ctx -> rawmode ) {
35+ /* Exit alternate screen buffer (restores original terminal content)
36+ * Only if stdout is a terminal (not a pipe or file) */
37+ if (isatty (STDOUT_FILENO )) {
38+ (void )write (STDOUT_FILENO , "\x1b[?1049l" , 8 );
39+ }
3540 tcsetattr (fd , TCSAFLUSH , & orig_termios );
3641 ctx -> rawmode = 0 ;
3742 }
@@ -65,6 +70,12 @@ int terminal_enable_raw_mode(editor_ctx_t *ctx, int fd) {
6570 if (tcsetattr (fd , TCSAFLUSH , & raw ) < 0 ) goto fatal ;
6671 ctx -> rawmode = 1 ;
6772
73+ /* Enter alternate screen buffer (saves current screen, gives clean slate)
74+ * Only if stdout is a terminal (not a pipe or file) */
75+ if (isatty (STDOUT_FILENO )) {
76+ (void )write (STDOUT_FILENO , "\x1b[?1049h" , 8 );
77+ }
78+
6879 /* Register this context for signal handling */
6980 signal_context = ctx ;
7081
You can’t perform that action at this time.
0 commit comments