Skip to content

Commit e326a22

Browse files
author
Charles Duffy
committed
cut+yank buffer support, ctrl+a and ctrl+e navigation
committer: Charles Duffy <cduffy@messageone.com>
1 parent 4a45123 commit e326a22

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

‎bpython/cli.py‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ def __init__( self, scr, interp, statusbar=None, idle=None):
219219
it's blocking (waiting for keypresses). This, again, should be in a
220220
different class"""
221221

222+
self.cut_buffer = ''
222223
self.buffer = []
223224
self.scr = scr
224225
self.interp = interp
@@ -1001,6 +1002,20 @@ def delete( self ):
10011002
if self.mvc(-1):
10021003
self.bs(False)
10031004

1005+
def cut_to_buffer ( self ):
1006+
"""Clear from cursor to end of line, placing into cut buffer"""
1007+
self.cut_buffer = self.s[ -self.cpos : ]
1008+
self.s = self.s[ : -self.cpos ]
1009+
self.cpos = 0
1010+
self.print_line( self.s, clr=True )
1011+
self.scr.redrawwin()
1012+
self.scr.refresh()
1013+
1014+
def yank_from_buffer ( self ):
1015+
"""Paste the text from the cut buffer at the current cursor location"""
1016+
self.addstr( self.cut_buffer )
1017+
self.print_line( self.s, clr=True )
1018+
10041019
def clrtobol( self ):
10051020
"""Clear from cursor to beginning of line; usual C-u behaviour"""
10061021
if not self.cpos:
@@ -1053,12 +1068,20 @@ def p_key( self ):
10531068
elif self.c == 'KEY_RIGHT': # Cursor Right
10541069
self.mvc( -1 )
10551070

1056-
elif self.c == "KEY_HOME":
1071+
elif self.c in ("KEY_HOME", '^A', chr(1)): # home or ^A
10571072
self.mvc(len(self.s) - self.cpos)
10581073

1059-
elif self.c == "KEY_END":
1074+
elif self.c in ("KEY_END", '^E', chr(5)): # end or ^E
10601075
self.mvc(-self.cpos)
10611076

1077+
elif self.c in ('^K', chr(11)): # cut to buffer
1078+
self.cut_to_buffer()
1079+
return ''
1080+
1081+
elif self.c in ('^Y', chr(25)): # yank from buffer
1082+
self.yank_from_buffer()
1083+
return ''
1084+
10621085
elif self.c in ('^W', chr(23)): # C-w
10631086
self.bs_word()
10641087
self.complete()

0 commit comments

Comments
 (0)