Skip to content

Commit 0410406

Browse files
committed
^X will remove search history item
1 parent 891aacd commit 0410406

File tree

4 files changed

+39
-5
lines changed

4 files changed

+39
-5
lines changed

README.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,7 @@ <h2 id="search-function">Search function <span style="padding-left: 10px;"><sup
14031403
<p>The <em>Search Window</em> supports normal and extend editing and in session history.</p>
14041404
<p>One can always get help by pressing the “<strong>?</strong>” key.</p>
14051405
<p>After a search term has been successfully found (search is case insensitive), next occurrence can be obtained using the “<strong>n</strong>” key and previous occurrence can be obtained using the “<strong>N</strong>” key.</p>
1406-
<p>All search widgets provide a “<em>search history</em>” function; pressing the <strong>Up</strong> or <strong>Down</strong> arrow will cycle through previously used search terms (maximum number remembered is 20).</p>
1406+
<p>All search widgets provide a “<em>search history</em>” function; pressing the <strong>Up</strong> or <strong>Down</strong> arrow will cycle through previously used search terms (maximum number remembered is 20). Pressing <strong>^X</strong> will remove an item from the history.</p>
14071407
<h2 id="line-editor">Line editor <span style="padding-left: 10px;"><sup style="font-size: 50%"><a href="#" title="Go to top of the page">Top</a></sup></span></h2>
14081408
<p><strong>PyRadio</strong><em>Search function</em>” and “<em>Station editor</em>” use a <em>Line editor</em> to permit typing and editing stations’ data.</p>
14091409
<p>The <em>Line editor</em> works both on <strong>Python 2</strong> and <strong>Python 3</strong>, but does not provide the same functionality for both versions:</p>

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ One can always get help by pressing the "**?**" key.
552552

553553
After a search term has been successfully found (search is case insensitive), next occurrence can be obtained using the "**n**" key and previous occurrence can be obtained using the "**N**" key.
554554

555-
All search widgets provide a "*search history*" function; pressing the **Up** or **Down** arrow will cycle through previously used search terms (maximum number remembered is 20).
555+
All search widgets provide a "*search history*" function; pressing the **Up** or **Down** arrow will cycle through previously used search terms (maximum number remembered is 20). Pressing **^X** will remove an item from the history.
556556

557557
## Line editor
558558

pyradio/radio.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3125,10 +3125,12 @@ def _show_search_help(self):
31253125
'''
31263126
else:
31273127
txt = '''Left| / |Right |Move to next / previous character.
3128+
Up| / |Down |Cycle within history.
31283129
M-F| / |M-B |Move to next / previous word.
31293130
HOME|,|^A| / |END|,|^E |Move to start / end of line.
31303131
^W| / |M-D|,|^K |Clear to start / end of line.
31313132
^U |Clear line.
3133+
^X |Remove history item.
31323134
DEL|,|^D |Delete character.
31333135
Backspace|,|^H |Backspace (delete previous character).
31343136
Up|,|^P| / |Down|,|^N |Get previous / next history item.

pyradio/simple_curses_widgets.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3339,7 +3339,7 @@ def __init__(self, parent, width, begin_y, begin_x, **kwargs):
33393339
''' callback function for KEY_STAB '''
33403340
self._key_stab_function_handler = value
33413341
elif key == 'string_changed_handler':
3342-
''' callback function for KEY_STAB '''
3342+
''' callback function for string change '''
33433343
self._string_changed_handler = value
33443344
elif key == 'paste_mode_always_on':
33453345
''' set paste mode and never disable it '''
@@ -4080,6 +4080,22 @@ def keypress(self, win, char):
40804080
self._mode_changed()
40814081
return 2
40824082

4083+
4084+
elif char == curses.ascii.CAN and \
4085+
self._has_history:
4086+
self._backslash_pressed = False
4087+
self._input_history.remove_from_history(self._string)
4088+
self._string = self._input_history.return_history(0, '')
4089+
if self.string:
4090+
if logger.isEnabledFor(logging.DEBUG):
4091+
logger.debug('action: CLEAR HISTORY')
4092+
self._go_to_end()
4093+
if not self._paste_mode_always_on:
4094+
if self._use_paste_mode and self._paste_mode:
4095+
self._paste_mode = self._disable_paste_mode = False
4096+
if self._mode_changed:
4097+
self._mode_changed()
4098+
40834099
elif char in (curses.KEY_ENTER, ord('\n'), ord('\r')):
40844100
''' ENTER '''
40854101
self._backslash_pressed = False
@@ -4586,6 +4602,21 @@ def add_to_history(self, a_string):
45864602
self._dirty = True
45874603
self._active_history_index = len(self._history)
45884604

4605+
def remove_from_history(self, a_string):
4606+
if a_string:
4607+
i = [(x, y) for x, y in \
4608+
enumerate(self._history) \
4609+
if y.lower() == a_string.lower()
4610+
]
4611+
if i:
4612+
self._history.pop(i[0][0])
4613+
self._dirty = True
4614+
if self._history:
4615+
if self._active_history_index == len(self._history):
4616+
self._active_history_index -= 1
4617+
else:
4618+
self._active_history_index = -1
4619+
45894620
def return_history(self, direction, current_string):
45904621
if self._history:
45914622
self._active_history_index += direction
@@ -4594,8 +4625,9 @@ def return_history(self, direction, current_string):
45944625
elif self._active_history_index >= len(self._history):
45954626
self._active_history_index = 0
45964627
ret = self._history[self._active_history_index]
4597-
if ret.lower() == current_string.lower():
4598-
return self.return_history(direction, current_string)
4628+
if ret and current_string:
4629+
if ret.lower() == current_string.lower():
4630+
return self.return_history(direction, current_string)
45994631
return ret
46004632
return ''
46014633

0 commit comments

Comments
 (0)