@@ -1091,12 +1091,23 @@ contains |
| 1091 | 1091 | ! Assign to result variable at the very end |
| 1092 | 1092 | success = mode_ok |
| 1093 | 1093 | |
| 1094 | | - ! Enable bracketed paste mode (if raw mode succeeded) |
| 1094 | + ! Enable bracketed paste mode (if raw mode succeeded). |
| 1095 | + ! FORTSH_NO_BRACKETED_PASTE=1 disables the emit — a kill switch for |
| 1096 | + ! bug triage on terminals that mishandle the mode (pattern #20). |
| 1095 | 1097 | if (success) then |
| 1096 | | - ! ESC[?2004h = Enable bracketed paste |
| 1097 | | - ! Terminal will wrap pasted text in ESC[200~ ... ESC[201~ |
| 1098 | | - write(output_unit, '(A)', advance='no') char(27) // '[?2004h' |
| 1099 | | - flush(output_unit) |
| 1098 | + block |
| 1099 | + character(len=8) :: no_bp_env |
| 1100 | + integer :: bp_stat |
| 1101 | + logical :: bp_disabled |
| 1102 | + call get_environment_variable('FORTSH_NO_BRACKETED_PASTE', no_bp_env, status=bp_stat) |
| 1103 | + bp_disabled = (bp_stat == 0 .and. trim(no_bp_env) == '1') |
| 1104 | + if (.not. bp_disabled) then |
| 1105 | + ! ESC[?2004h = Enable bracketed paste |
| 1106 | + ! Terminal will wrap pasted text in ESC[200~ ... ESC[201~ |
| 1107 | + write(output_unit, '(A)', advance='no') char(27) // '[?2004h' |
| 1108 | + flush(output_unit) |
| 1109 | + end if |
| 1110 | + end block |
| 1100 | 1111 | |
| 1101 | 1112 | ! Debug: Check if FORTSH_DEBUG_PASTE is set |
| 1102 | 1113 | block |
@@ -1120,11 +1131,19 @@ contains |
| 1120 | 1131 | type(termios_t), intent(in) :: original_termios |
| 1121 | 1132 | logical :: success |
| 1122 | 1133 | integer :: ret |
| 1123 | | - |
| 1124 | | - ! Disable bracketed paste mode before restoring terminal |
| 1125 | | - ! ESC[?2004l = Disable bracketed paste |
| 1126 | | - write(output_unit, '(A)', advance='no') char(27) // '[?2004l' |
| 1127 | | - flush(output_unit) |
| 1134 | + character(len=8) :: no_bp_env |
| 1135 | + integer :: bp_stat |
| 1136 | + logical :: bp_disabled |
| 1137 | + |
| 1138 | + ! Disable bracketed paste mode before restoring terminal, |
| 1139 | + ! unless FORTSH_NO_BRACKETED_PASTE=1 (we never enabled it). |
| 1140 | + call get_environment_variable('FORTSH_NO_BRACKETED_PASTE', no_bp_env, status=bp_stat) |
| 1141 | + bp_disabled = (bp_stat == 0 .and. trim(no_bp_env) == '1') |
| 1142 | + if (.not. bp_disabled) then |
| 1143 | + ! ESC[?2004l = Disable bracketed paste |
| 1144 | + write(output_unit, '(A)', advance='no') char(27) // '[?2004l' |
| 1145 | + flush(output_unit) |
| 1146 | + end if |
| 1128 | 1147 | |
| 1129 | 1148 | ret = c_tcsetattr(STDIN_FD, TCSANOW, original_termios) |
| 1130 | 1149 | success = (ret == 0) |