Use the ESC [6n escape sequence to query the horizontal cursor position * and return it. On error -1 is returned, on success the position of the * cursor. */
| 654 | } |
| 655 | |
| 656 | static void disableRawMode(int fd) { |
| 657 | /* Test mode: nothing to restore. */ |
| 658 | if (getenv("LINENOISE_ASSUME_TTY")) { |
| 659 | rawmode = 0; |
| 660 | return; |
| 661 | } |
| 662 | /* Don't even check the return value as it's too late. */ |
| 663 | if (rawmode && tcsetattr(fd,TCSAFLUSH,&orig_termios) != -1) { |
| 664 | /* Leave bracketed paste mode when leaving raw mode. */ |
| 665 | if (write(rawmode_output, "\x1b[?2004l", 8) == -1) {} |
| 666 | rawmode = 0; |
| 667 | } |
| 668 | } |
| 669 | |
| 670 | /* Re-enable raw mode if a child process changed the terminal state. This is |
| 671 | * useful when the application spawns external processes that may reset the |
| 672 | * terminal to cooked mode. This is deliberately conservative: while an editor |
| 673 | * is active, orig_termios must remain the cooked-mode state used by |
| 674 | * disableRawMode(), so never replace it with the current terminal attributes. |
| 675 | * TCSANOW avoids discarding bytes the user typed while the child was running. */ |
| 676 | void linenoiseRestoreRawMode(void) { |
| 677 | if (getenv("LINENOISE_ASSUME_TTY")) return; |
| 678 | if (!rawmode) return; |
| 679 | if (!isatty(STDIN_FILENO)) return; |