@@ -133,35 +133,28 @@ def process_event(self, e: Union[events.Event, str]) -> None:
133133 self .current_line = ""
134134 self .cursor_offset = 0
135135 self .repl .run_code_and_maybe_finish ()
136- else :
137- if e in self .rl_char_sequences :
138- self .cursor_offset , self .current_line = self .rl_char_sequences [
139- e
140- ](self .cursor_offset , self .current_line )
141- elif e in ("<ESC>" ,):
142- pass
143- elif e in ("<Ctrl-d>" ,):
144- if self .current_line == "" :
145- self .repl .send_to_stdin ("\n " )
146- self .has_focus = False
147- self .current_line = ""
148- self .cursor_offset = 0
149- self .repl .run_code_and_maybe_finish (for_code = "" )
150- else :
151- pass
152- elif e in ("\n " , "\r " , "<Ctrl-j>" , "<Ctrl-m>" ):
153- line = self .current_line
154- self .repl .send_to_stdin (line + "\n " )
136+ elif e in self .rl_char_sequences :
137+ self .cursor_offset , self .current_line = self .rl_char_sequences [e ](
138+ self .cursor_offset , self .current_line
139+ )
140+ elif e == "<Ctrl-d>" :
141+ if not len (self .current_line ):
142+ self .repl .send_to_stdin ("\n " )
155143 self .has_focus = False
156144 self .current_line = ""
157145 self .cursor_offset = 0
158- self .repl .run_code_and_maybe_finish (for_code = line + "\n " )
159- else : # add normal character
160- self .add_input_character (e )
146+ self .repl .run_code_and_maybe_finish (for_code = "" )
147+ elif e in ("\n " , "\r " , "<Ctrl-j>" , "<Ctrl-m>" ):
148+ line = f"{ self .current_line } \n "
149+ self .repl .send_to_stdin (line )
150+ self .has_focus = False
151+ self .current_line = ""
152+ self .cursor_offset = 0
153+ self .repl .run_code_and_maybe_finish (for_code = line )
154+ elif e != "<ESC>" : # add normal character
155+ self .add_input_character (e )
161156
162- if self .current_line .endswith (("\n " , "\r " )):
163- pass
164- else :
157+ if not self .current_line .endswith (("\n " , "\r " )):
165158 self .repl .send_to_stdin (self .current_line )
166159
167160 def add_input_character (self , e : str ) -> None :
0 commit comments