Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0259cf8

Browse filesBrowse files
committed
page_up and page_down keys mapped
1 parent 5382d09 commit 0259cf8
Copy full SHA for 0259cf8

2 files changed

+61-20Lines changed: 61 additions & 20 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎bpython/cli.py‎

Copy file name to clipboardExpand all lines: bpython/cli.py
+35-10Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -292,16 +292,6 @@ def atbol(self):
292292

293293
return not self.s.lstrip()
294294

295-
def back(self):
296-
"""Replace the active line with previous line in history and
297-
increment the index to keep track"""
298-
299-
self.cpos = 0
300-
self.rl_history.enter(self.s)
301-
self.clear_wrapped_lines()
302-
self.s = self.rl_history.back()
303-
self.print_line(self.s, clr=True)
304-
305295
def bs(self, delete_tabs=True):
306296
"""Process a backspace"""
307297

@@ -498,6 +488,33 @@ def end(self, refresh=True):
498488

499489
return True
500490

491+
def hbegin(self):
492+
"""Replace the active line with first line in history and
493+
increment the index to keep track"""
494+
self.cpos = 0
495+
self.clear_wrapped_lines()
496+
self.rl_history.enter(self.s)
497+
self.s = self.rl_history.first()
498+
self.print_line(self.s, clr=True)
499+
500+
def hend(self):
501+
"""Same as hbegin() but, well, forward"""
502+
self.cpos = 0
503+
self.clear_wrapped_lines()
504+
self.rl_history.enter(self.s)
505+
self.s = self.rl_history.last()
506+
self.print_line(self.s, clr=True)
507+
508+
def back(self):
509+
"""Replace the active line with previous line in history and
510+
increment the index to keep track"""
511+
512+
self.cpos = 0
513+
self.clear_wrapped_lines()
514+
self.rl_history.enter(self.s)
515+
self.s = self.rl_history.back()
516+
self.print_line(self.s, clr=True)
517+
501518
def fwd(self):
502519
"""Same as back() but, well, forward"""
503520

@@ -787,6 +804,14 @@ def p_key(self, key):
787804
# Redraw (as there might have been highlighted parens)
788805
self.print_line(self.s)
789806

807+
elif key in ("KEY_NPAGE", '\T'): # page_down or \T
808+
self.hend()
809+
self.print_line(self.s)
810+
811+
elif key in ("KEY_PPAGE", '\S'): # page_up or \S
812+
self.hbegin()
813+
self.print_line(self.s)
814+
790815
elif key in key_dispatch[config.cut_to_buffer_key]: # cut to buffer
791816
self.cut_to_buffer()
792817
return ''
Collapse file

‎bpython/repl.py‎

Copy file name to clipboardExpand all lines: bpython/repl.py
+26-10Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -158,29 +158,45 @@ def append(self, line):
158158
if line:
159159
self.entries.append(line)
160160

161+
def first(self):
162+
"""Move back to the beginning of the history."""
163+
if not self.is_at_end:
164+
self.index = len(self.entries) - 1
165+
return self.entries[-self.index]
166+
161167
def back(self):
162-
if not self.is_at_end():
168+
"""Move one step back in the history."""
169+
if not self.is_at_end:
163170
self.index += 1
164171
return self.entries[-self.index]
165172

173+
def forward(self):
174+
"""Move one step forward in the history."""
175+
if self.index > 1:
176+
self.index -= 1
177+
return self.entries[-self.index]
178+
else:
179+
self.index = 0
180+
return self.saved_line
181+
182+
def last(self):
183+
"""Move forward to the end of the history."""
184+
if not self.is_at_start:
185+
self.index = 0
186+
return self.entries[0]
187+
188+
@property
166189
def is_at_end(self):
167-
return self.index >= len(self.entries)
190+
return self.index >= len(self.entries) or self.index == -1
168191

192+
@property
169193
def is_at_start(self):
170194
return self.index == 0
171195

172196
def enter(self, line):
173197
if self.index == 0:
174198
self.saved_line = line
175199

176-
def forward(self):
177-
if self.index > 1:
178-
self.index -= 1
179-
return self.entries[-self.index]
180-
else:
181-
self.index = 0
182-
return self.saved_line
183-
184200
@classmethod
185201
def from_filename(cls, filename):
186202
history = cls()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.