@@ -20,40 +20,38 @@ def add_to_char_sequences(func):
2020 return func
2121 return add_to_char_sequences
2222
23- @on ('[D' )
24- @on ('' )
25- @on (chr (2 ))
23+ @on ('\x1b [D' )
24+ @on ('\x02 ' )
2625@on ('KEY_LEFT' )
2726def left_arrow (cursor_offset , line ):
2827 return max (0 , cursor_offset - 1 ), line
2928
30- @on ('[C' )
31- @on ('' )
32- @on (chr (6 ))
29+ @on ('\x1b [C' )
30+ @on ('\x06 ' )
3331@on ('KEY_RIGHT' )
3432def right_arrow (cursor_offset , line ):
3533 return min (len (line ), cursor_offset + 1 ), line
3634
37- @on ('' )
35+ @on ('\x01 ' )
3836@on ('KEY_HOME' )
3937def beginning_of_line (cursor_offset , line ):
4038 return 0 , line
4139
42- @on ('' )
40+ @on ('\x05 ' )
4341@on ('KEY_END' )
4442def end_of_line (cursor_offset , line ):
4543 return len (line ), line
4644
47- @on ('f ' )
48- @on ('l ' )
45+ @on ('\x1b f ' )
46+ @on ('\x1b l ' )
4947@on ('\x1b OC' )
5048def forward_word (cursor_offset , line ):
5149 patt = r"\S\s"
5250 match = re .search (patt , line [cursor_offset :]+ ' ' )
5351 delta = match .end () - 1 if match else 0
5452 return (cursor_offset + delta , line )
5553
56- @on ('b ' )
54+ @on ('\x1b b ' )
5755@on ('\x1b OD' )
5856@on ('\x1b B' )
5957def back_word (cursor_offset , line ):
@@ -66,14 +64,14 @@ def last_word_pos(string):
6664 index = match and len (string ) - match .end () + 1
6765 return index or 0
6866
69- @on ('[3~' )
67+ @on ('\x1b [3~' )
7068@on ('KEY_DC' )
7169def delete (cursor_offset , line ):
7270 return (cursor_offset ,
7371 line [:cursor_offset ] + line [cursor_offset + 1 :])
7472
75- @on ('' )
76- @on (' ' )
73+ @on ('\x08 ' )
74+ @on ('\x7f ' )
7775@on ('KEY_BACKSPACE' )
7876def backspace (cursor_offset , line ):
7977 if cursor_offset == 0 :
@@ -85,54 +83,54 @@ def backspace(cursor_offset, line):
8583 return (cursor_offset - 1 ,
8684 line [:cursor_offset - 1 ] + line [cursor_offset :])
8785
88- @on ('' )
86+ @on ('\x15 ' )
8987def delete_from_cursor_back (cursor_offset , line ):
9088 return 0 , line [cursor_offset :]
9189
92- @on ('' )
90+ @on ('\x0b ' )
9391def delete_from_cursor_forward (cursor_offset , line ):
9492 return cursor_offset , line [:cursor_offset ]
9593
96- @on ('d ' ) # option-d
94+ @on ('\x1b d ' ) # option-d
9795def delete_rest_of_word (cursor_offset , line ):
9896 m = re .search (r'\w\b' , line [cursor_offset :])
9997 if not m :
10098 return cursor_offset , line
10199 return cursor_offset , line [:cursor_offset ] + line [m .start ()+ cursor_offset + 1 :]
102100
103- @on ('' )
101+ @on ('\x17 ' )
104102def delete_word_to_cursor (cursor_offset , line ):
105103 matches = list (re .finditer (r'\s\S' , line [:cursor_offset ]))
106104 start = matches [- 1 ].start ()+ 1 if matches else 0
107105 return start , line [:start ] + line [cursor_offset :]
108106
109- @on ('y ' )
107+ @on ('\x1b y ' )
110108def yank_prev_prev_killed_text (cursor_offset , line ):
111109 raise NotImplementedError ()
112110
113- @on ('' )
111+ @on ('\x14 ' )
114112def transpose_character_before_cursor (cursor_offset , line ):
115113 return (min (len (line ), cursor_offset + 1 ),
116114 line [:cursor_offset - 1 ] +
117115 (line [cursor_offset ] if len (line ) > cursor_offset else '' ) +
118116 line [cursor_offset - 1 ] +
119117 line [cursor_offset + 1 :])
120118
121- @on ('t ' )
119+ @on ('\x1b t ' )
122120def transpose_word_before_cursor (cursor_offset , line ):
123121 raise NotImplementedError ()
124122
125123# bonus functions (not part of readline)
126124
127- @on ('r ' )
125+ @on ('\x1b r ' )
128126def delete_line (cursor_offset , line ):
129127 return 0 , ""
130128
131- @on ('u ' )
129+ @on ('\x1b u ' )
132130def uppercase_next_word (cursor_offset , line ):
133131 raise NotImplementedError ()
134132
135- @on ('c ' )
133+ @on ('\x1b c ' )
136134def titlecase_next_word (cursor_offset , line ):
137135 raise NotImplementedError ()
138136
0 commit comments