diff --git a/command_prompt.py b/command_prompt.py index f048e21..72c7006 100644 --- a/command_prompt.py +++ b/command_prompt.py @@ -45,12 +45,15 @@ class Command_prompt(Label): self.text=self.raw_text def on_key_down(self, keyboard, keycode, text, modifiers): - #print(keycode,text,modifiers) + print(keycode,text,modifiers) if self.insert: + # process command if keycode[1]=="enter": self.insert=False self.parse_command() self.set_text("") + + # move elif keycode[1]=="left": self.move_cursor_relative(-1) elif keycode[1]=="right": @@ -60,6 +63,14 @@ class Command_prompt(Label): elif len(modifiers)==1 and modifiers[0]=="ctrl" and text=="e": self.move_cursor(len(self.raw_text)) + # delete + elif keycode[1]=="backspace": + self.backspace() + elif keycode[1]=="delete": + self.delete_forward() + elif len(modifiers)==1 and modifiers[0]=="ctrl" and text=="k": + self.delete_all_forward() + def on_textinput(self,window,text): #print(text) if self.insert: @@ -77,6 +88,33 @@ class Command_prompt(Label): self.cursor+=len(text) self.draw() + # delete before cursor + def backspace(self): + # do not delete leading ':' + if self.cursor==1: + return + if self.cursor==len(self.raw_text): + self.raw_text=self.raw_text[:self.cursor-1] + else: + self.raw_text=self.raw_text[:self.cursor-1]+self.raw_text[self.cursor:] + self.cursor-=1 + self.draw() + # delete after cursor + def delete_forward(self): + if self.cursor==len(self.raw_text): + return + else: + self.raw_text=self.raw_text[:self.cursor]+self.raw_text[self.cursor+1:] + self.draw() + # delete until end of line(self): + def delete_all_forward(self): + if self.cursor==len(self.raw_text): + return + else: + self.raw_text=self.raw_text[:self.cursor] + self.draw() + + # set text in prompt def set_text(self,text): self.raw_text=text