/src/mosh/src/terminal/terminaluserinput.cc
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | Mosh: the mobile shell |
3 | | Copyright 2012 Keith Winstein |
4 | | |
5 | | This program is free software: you can redistribute it and/or modify |
6 | | it under the terms of the GNU General Public License as published by |
7 | | the Free Software Foundation, either version 3 of the License, or |
8 | | (at your option) any later version. |
9 | | |
10 | | This program is distributed in the hope that it will be useful, |
11 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | | GNU General Public License for more details. |
14 | | |
15 | | You should have received a copy of the GNU General Public License |
16 | | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | | |
18 | | In addition, as a special exception, the copyright holders give |
19 | | permission to link the code of portions of this program with the |
20 | | OpenSSL library under certain conditions as described in each |
21 | | individual source file, and distribute linked combinations including |
22 | | the two. |
23 | | |
24 | | You must obey the GNU General Public License in all respects for all |
25 | | of the code used other than OpenSSL. If you modify file(s) with this |
26 | | exception, you may extend this exception to your version of the |
27 | | file(s), but you are not obligated to do so. If you do not wish to do |
28 | | so, delete this exception statement from your version. If you delete |
29 | | this exception statement from all source files in the program, then |
30 | | also delete it here. |
31 | | */ |
32 | | |
33 | | #include <assert.h> |
34 | | #include "terminaluserinput.h" |
35 | | |
36 | | using namespace Terminal; |
37 | | using std::string; |
38 | | |
39 | | string UserInput::input( const Parser::UserByte *act, |
40 | | bool application_mode_cursor_keys ) |
41 | 4.19M | { |
42 | | /* The user will always be in application mode. If stm is not in |
43 | | application mode, convert user's cursor control function to an |
44 | | ANSI cursor control sequence */ |
45 | | |
46 | | /* We need to look ahead one byte in the SS3 state to see if |
47 | | the next byte will be A, B, C, or D (cursor control keys). */ |
48 | | |
49 | | /* This doesn't handle the 8-bit SS3 C1 control, which would be |
50 | | two octets in UTF-8. Fortunately nobody seems to send this. */ |
51 | | |
52 | 4.19M | switch ( state ) { |
53 | 4.05M | case Ground: |
54 | 4.05M | if ( act->c == 0x1b ) { /* ESC */ |
55 | 90.4k | state = ESC; |
56 | 90.4k | } |
57 | 4.05M | return string( &act->c, 1 ); |
58 | | |
59 | 90.4k | case ESC: |
60 | 90.4k | if ( act->c == 'O' ) { /* ESC O = 7-bit SS3 */ |
61 | 53.7k | state = SS3; |
62 | 53.7k | return string(); |
63 | 53.7k | } |
64 | 36.7k | state = Ground; |
65 | 36.7k | return string( &act->c, 1 ); |
66 | | |
67 | 53.6k | case SS3: |
68 | 53.6k | state = Ground; |
69 | 53.6k | if ( (!application_mode_cursor_keys) |
70 | 53.6k | && (act->c >= 'A') |
71 | 53.6k | && (act->c <= 'D') ) { |
72 | 18.4k | char translated_cursor[ 2 ] = { '[', act->c }; |
73 | 18.4k | return string( translated_cursor, 2 ); |
74 | 35.2k | } else { |
75 | 35.2k | char original_cursor[ 2 ] = { 'O', act->c }; |
76 | 35.2k | return string( original_cursor, 2 ); |
77 | 35.2k | } |
78 | | |
79 | 0 | default: |
80 | 0 | assert( !"unexpected state" ); |
81 | 0 | state = Ground; |
82 | 0 | return string(); |
83 | 4.19M | } |
84 | 4.19M | } |