Skip to content

Commit 2b8d8a4

Browse files
removed control characters from source code
1 parent 723cf05 commit 2b8d8a4

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

bpython/curtsiesfrontend/manual_readline.py

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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')
2726
def 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')
3432
def right_arrow(cursor_offset, line):
3533
return min(len(line), cursor_offset + 1), line
3634

37-
@on('')
35+
@on('\x01')
3836
@on('KEY_HOME')
3937
def beginning_of_line(cursor_offset, line):
4038
return 0, line
4139

42-
@on('')
40+
@on('\x05')
4341
@on('KEY_END')
4442
def end_of_line(cursor_offset, line):
4543
return len(line), line
4644

47-
@on('f')
48-
@on('l')
45+
@on('\x1bf')
46+
@on('\x1bl')
4947
@on('\x1bOC')
5048
def 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('\x1bb')
5755
@on('\x1bOD')
5856
@on('\x1bB')
5957
def 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')
7169
def 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')
7876
def 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')
8987
def delete_from_cursor_back(cursor_offset, line):
9088
return 0, line[cursor_offset:]
9189

92-
@on('')
90+
@on('\x0b')
9391
def delete_from_cursor_forward(cursor_offset, line):
9492
return cursor_offset, line[:cursor_offset]
9593

96-
@on('d') # option-d
94+
@on('\x1bd') # option-d
9795
def 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')
104102
def 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('\x1by')
110108
def yank_prev_prev_killed_text(cursor_offset, line):
111109
raise NotImplementedError()
112110

113-
@on('')
111+
@on('\x14')
114112
def 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('\x1bt')
122120
def transpose_word_before_cursor(cursor_offset, line):
123121
raise NotImplementedError()
124122

125123
# bonus functions (not part of readline)
126124

127-
@on('r')
125+
@on('\x1br')
128126
def delete_line(cursor_offset, line):
129127
return 0, ""
130128

131-
@on('u')
129+
@on('\x1bu')
132130
def uppercase_next_word(cursor_offset, line):
133131
raise NotImplementedError()
134132

135-
@on('c')
133+
@on('\x1bc')
136134
def titlecase_next_word(cursor_offset, line):
137135
raise NotImplementedError()
138136

0 commit comments

Comments
 (0)