Skip to content

Commit afbb72d

Browse files
committed
Version 0.8.1
Using backslash to insert "?" and "/" in line editor and updating docs
1 parent a4e3693 commit afbb72d

File tree

7 files changed

+106
-17
lines changed

7 files changed

+106
-17
lines changed

Changelog

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
2019-10-18 s-n-g
1+
2019-10-19 s-n-g
2+
* Version 0.8.1
23
* CJK Unified Ideographs supported by the line edittor
34
* On python 2, trying to edit a station whose name contains
45
non-ASCII characters is prohibited and will end up in
56
displaying a relevant message
7+
* Line editor: using backslash to insert "?" and "\"
68
* Search term will not be lost when resizing the window
79
* Fixing issues with presenting search history
10+
* Themes now have a "Edit Cursor" field
811

912
2019-09-08 s-n-g
13+
* Version 0.8.0
1014
* Adding station editor ("a" and "A" to add a station, "e" to edit)
1115
* Line editor supports unlimited string length
1216
* Main help window separated to two pages (navigation with "n" / "p")

README.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,21 @@ <h2 id="search-function">Search function <span style="padding-left: 10px;"><sup
184184
<p>The <em>Search Window</em> supports normal and extend editing and in session history.</p>
185185
<p>One can always get help by pressing the “<strong>?</strong>” key.</p>
186186
<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>
187-
<p style="margin: 1.5em 4em 0 4em; text-indent: -2.5em;"><strong>Note:</strong> <strong>Python 2</strong> users are confined in typing ASCII characters only.</p>
188187
<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></style></h2>
189188
<p><strong>PyRadio</strong><em>Search function</em>” and “<em>Station edior</em>” use a <em>line editor</em> to permit typing and editing stations’ data.</p>
190189
<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>
191190
<ul>
192191
<li>In <strong>Python 2</strong>, only ASCII characters can be inserted.</li>
193192
<li>In <strong>Python 3</strong>, no such restriction exists. Furthermore, using CJK characters is also supported.</li>
194193
</ul>
194+
<p>One can always display help by pressing “<strong>?</strong>”, but that pauses a drawback; one cannot actually have a “<strong>?</strong>” withing the string.</p>
195+
<p>To do that, one would have to use the backslash key “<strong>\</strong>” and then press “<strong>?</strong>”.</p>
196+
<p>To sum it all up:</p>
197+
<ol type="1">
198+
<li>Press “<strong>?</strong>” to get help.</li>
199+
<li>Press “<strong>\?</strong>” to get a “<strong>?</strong>”.</li>
200+
<li>Press “<strong>\\</strong>” to get a “<strong>\</strong>”.</li>
201+
</ol>
195202
<h3 id="cjk-characters-support">CJK characters support</h3>
196203
<p>The <em>line editor</em> supports the insertion of <a target="_blank" href="https://en.wikipedia.org/wiki/CJK_Unified_Ideographs">CJK Unified Ideographs</a>, as described on <a target="_blank" href="https://en.wikipedia.org/wiki/CJK_Unified_Ideographs_(Unicode_block)">CJK Unified Ideographs (Unicode block)</a> also known as URO, abbreviation of Unified Repertoire and Ordering. These characters, although encoded as a single code-point (character), actually take up a 2-character space, when rendered on the terminal.</p>
197204
<p>A depiction of the editor’s behavior can be seen at this image: <a target="_blank" href="https://members.hellug.gr/sng/pyradio/pyradio-editor.jpg">pyradio-editor.jpg</a>.</p>

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,6 @@ One can always get help by pressing the "**?**" key.
222222

223223
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.
224224

225-
**Note:** **Python 2** users are confined in typing ASCII characters only.
226-
227225
## Line editor
228226

229227
**PyRadio** "*Search function*" and "*Station edior*" use a *line editor* to permit typing and editing stations' data.
@@ -234,6 +232,16 @@ The *line editor* works both on **Python 2** and **Python 3**, but does not prov
234232
* In **Python 2**, only ASCII characters can be inserted.
235233
* In **Python 3**, no such restriction exists. Furthermore, using CJK characters is also supported.
236234

235+
One can always display help by pressing "**?**", but that pauses a drawback; one cannot actually have a "**?**" withing the string.
236+
237+
To do that, one would have to use the backslash key "**\\**" and then press "**?**".
238+
239+
To sum it all up:
240+
241+
1. Press "**?**" to get help.
242+
2. Press "**\\?**" to get a "**?**".
243+
3. Press "**\\\\**" to get a "**\\**".
244+
237245
### CJK characters support
238246

239247
The *line editor* supports the insertion of [CJK Unified Ideographs](https://en.wikipedia.org/wiki/CJK_Unified_Ideographs), as described on [CJK Unified Ideographs (Unicode block)](https://en.wikipedia.org/wiki/CJK_Unified_Ideographs_(Unicode_block)) also known as URO, abbreviation of Unified Repertoire and Ordering. These characters, although encoded as a single code-point (character), actually take up a 2-character space, when rendered on the terminal.

pyradio.1

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,38 @@ One can always get help by pressing the "\fI?\fR" key.
239239

240240
After a search term has been successfully found (search is case insensitive), next occurrence can be obtained using the "\fIn\fR" key and previous occurrence can be obtained using the "\fIN\fR" key.
241241

242-
.IP \fBNote\fR
243-
\fBPython 2\fR users are confined in typing ASCII characters only.
242+
.SH LINE EDITOR
243+
244+
\fBpyradio\fR "\fISearch function\fR" and "\fIStation edior\fR" use a \fIline editor\fR to permit typing and editing stations' data.
245+
246+
The \fIline editor\fR works both on \fBPython 2\fR and \fBPython 3\fR, but does not provide the same functionality for both versions:
247+
248+
.RS 5
249+
.IP \fI*\fR 2
250+
In \fBPython 2\fR, only ASCII characters can be inserted.
251+
.IP \fI*\fR 2
252+
In \fBPython 3\fR, no such restriction exists. Furthermore, using CJK characters is also supported.
253+
254+
.RE
244255

256+
.PP
257+
One can always display help by pressing "\fI?\fR", but that pauses a drawback; one cannot actually have a "\fI?\fR" withing the string.
245258

246-
.SH CJK CHARACTERS SUPPORT
259+
To do that, one would have to use the backslash key "\fI\\\fR" and then press "\fI?\fR".
247260

248-
The \fIline editor\fR supports the insertion of \fICJK Unified Ideographs [1]\fR, as described on \fICJK Unified Ideographs (Unicode block) [2]\fR, also known as URO, abbreviation of Unified Repertoire and Ordering. These characters, although encoded as a single code-point (character), actually take up a 2-character space, when rendered on the terminal.
261+
To sum it all up:
262+
263+
.IP
264+
1. Press "\fI?\fR" to get help.
265+
.IP
266+
2. Press "\fI\\?\fR" to get a "\fI?\fR".
267+
.IP
268+
3. Press "\fI\\\\\fR" to get a "\fI\\\fR".
269+
270+
.PP
271+
\fBCJK CHARACTERS SUPPORT\fR
272+
273+
The \fIline editor\fR supports the insertion of \fICJK Unified Ideographs [1]\fR, as described on \fICJK Unified Ideographs (Unicode block) [2]\fR, also known as URO, abbreviation of Unified Repertoire and Ordering. These characters, although encoded as a single code-poin (character), actually take up a 2-character space, when rendered on the terminal.
249274

250275
A depiction of the editor's behavior can be seen at this image:
251276

@@ -266,17 +291,14 @@ There are three way to do that:
266291

267292
.RS 5
268293

269-
.IP 1.
294+
.IP 1. 3
270295
Press \fICtrl-U\fR or \fICtrl-D\fR to move the current station up or down.
271-
.IP 2.
296+
.IP 2. 3
272297
Type a station number and press \fICtrl-U\fR or \fICtrl-D\fR to move the current station there.
273-
.IP 3.
298+
.IP 3. 3
274299
Go to the position you want to move a station to, and press "\fIJ\fR". This will tag this position (making it the target of the move). Then go to the station you want to move and press \fICtrl-U\fR or \fICtrl-D\fR to move it there.
275300

276301

277-
278-
279-
280302
.SH SPECIFYING STATIONS' ENCODING
281303

282304
Normally, stations provide information about their status (including the title of the song playing, which \fBpyradio\fR displays) in Unicode (\fIutf-8\fR encoded). Therefore, \fBpyradio\fR will use \fIutf-8\fR to decode such data, by default.
@@ -553,7 +575,7 @@ Finally, include the file produced in your report.
553575

554576
.RS 5
555577

556-
.IP 1.
578+
.IP 1. 3
557579
\fBCJKwrap\fR (\fIhttps://gitlab.com/fgallaire/cjkwrap\fR) by Florent Gallaire - A library for wrapping and filling UTF-8 CJK text.
558580

559581
.SH FILES

pyradio/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" pyradio -- Console radio player. "
22

3-
version_info = (0, 8, 0)
3+
version_info = (0, 8, 1)
44

55
__version__ = version = '.'.join(map(str, version_info))
66
__project__ = __name__

pyradio/radio.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,7 @@ def _show_search_help(self):
11641164
DEL|,|^D |Delete character.
11651165
Backspace|,|^H |Backspace (delete previous character).
11661166
Up|,|^P| / |Down|,|^N |Get previous / next history item.
1167+
\\?| / |\\\\ |Insert a "|?|" or a "|\\|", respectively.
11671168
Enter| / |Esc |Perform / cancel search.
11681169
11691170
|Managing player volume does not work in search mode.
@@ -1177,6 +1178,7 @@ def _show_search_help(self):
11771178
DEL|,|^D |Delete character.
11781179
Backspace|,|^H |Backspace (delete previous character).
11791180
Up|,|^P| / |Down|,|^N |Get previous / next history item.
1181+
\\?| / |\\\\ |Insert a "|?|" or a "|\\|", respectively.
11801182
Enter| / |Esc |Perform / cancel search.
11811183
11821184
|Managing player volume does not work in search mode.

pyradio/simple_curses_widgets.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ class SimpleCursesLineEdit(object):
107107
'[', ']', '{', '}', '|', '\\', '/',
108108
)
109109

110+
""" True if backlash has been pressed """
111+
_backslash = False
112+
113+
""" Behaviour of ? key regarding \
114+
If True, display ? (\? to display help)
115+
If False, display help """
116+
_show_help_with_backslash = False
117+
110118
def __init__(self, parent, width, begin_y, begin_x, **kwargs):
111119

112120
self._parent_win = parent
@@ -211,6 +219,14 @@ def string(self, val):
211219
self._is_cjk()
212220
self._go_to_end()
213221

222+
@property
223+
def show_help_with_backslash(self):
224+
return self._show_help_with_backslash
225+
226+
@show_help_with_backslash.setter
227+
def show_help_with_backslash(self, val):
228+
self._show_help_with_backslash = val
229+
214230
def _is_cjk(self):
215231
""" Check if string contains CJK characters.
216232
If string is empty reset history index """
@@ -652,6 +668,12 @@ def _clear_to_end_of_line(self):
652668
self._go_to_end()
653669
self._is_cjk()
654670

671+
def _can_show_help(self):
672+
""" return not xor of two values
673+
self._backslash , self._show_help_with_backslash """
674+
return not ( (self._backslash and not self._show_help_with_backslash) or \
675+
(not self._backslash and self._show_help_with_backslash) )
676+
655677
def keypress(self, win, char):
656678
"""
657679
returns:
@@ -692,22 +714,29 @@ def keypress(self, win, char):
692714
self._previous_word()
693715
return 1
694716

695-
if char in (ord('?'), ):
717+
if char == 92 and not self._backslash:
718+
self._backslash = True
719+
return 1
720+
721+
elif char in (ord('?'), ) and self._can_show_help():
696722
# display help
697723
if logger.isEnabledFor(logging.DEBUG):
698724
logger.debug('action: help')
699725
self.keep_restore_data()
726+
self._backslash = False
700727
return 2
701728

702729
elif char in (curses.KEY_ENTER, ord('\n'), ord('\r')):
703730
""" ENTER """
731+
self._backslash = False
704732
if logger.isEnabledFor(logging.DEBUG):
705733
logger.debug('action: enter')
706734
if self._has_history:
707735
self._input_history.add_to_history(self._string)
708736
return 0
709737

710738
elif char in (curses.KEY_EXIT, 27):
739+
self._backslash = False
711740
if logger.isEnabledFor(logging.DEBUG):
712741
logger.debug('action: ESCAPE')
713742
self._edit_win.nodelay(True)
@@ -750,48 +779,55 @@ def keypress(self, win, char):
750779

751780
elif char in (curses.KEY_RIGHT, ):
752781
""" KEY_RIGHT """
782+
self._backslash = False
753783
if self.string:
754784
if logger.isEnabledFor(logging.DEBUG):
755785
logger.debug('action: RIGHT')
756786
self._go_right()
757787

758788
elif char in (curses.KEY_LEFT, ):
759789
""" KEY_LEFT """
790+
self._backslash = False
760791
if self.string:
761792
if logger.isEnabledFor(logging.DEBUG):
762793
logger.debug('action: LEFT')
763794
self._go_left()
764795

765796
elif char in (curses.KEY_HOME, curses.ascii.SOH):
766797
""" KEY_HOME, ^A """
798+
self._backslash = False
767799
if self.string:
768800
if logger.isEnabledFor(logging.DEBUG):
769801
logger.debug('action: HOME')
770802
self._go_to_start()
771803

772804
elif char in (curses.KEY_END, curses.ascii.ENQ):
773805
""" KEY_END, ^E """
806+
self._backslash = False
774807
if self.string:
775808
if logger.isEnabledFor(logging.DEBUG):
776809
logger.debug('action: END')
777810
self._go_to_end()
778811

779812
elif char in (curses.ascii.ETB, ):
780813
""" ^W, clear to start of line """
814+
self._backslash = False
781815
if self.string:
782816
if logger.isEnabledFor(logging.DEBUG):
783817
logger.debug('action: clear-to-end')
784818
self._clear_to_start_of_line()
785819

786820
elif char in (curses.ascii.VT, ):
787821
""" Ctrl-K - clear to end of line """
822+
self._backslash = False
788823
if self.string:
789824
if logger.isEnabledFor(logging.DEBUG):
790825
logger.debug('action: clear-to-end')
791826
self._clear_to_end_of_line()
792827

793828
elif char in (curses.ascii.NAK, ):
794829
""" ^U, clear line """
830+
self._backslash = False
795831
if logger.isEnabledFor(logging.DEBUG):
796832
logger.debug('action: clear')
797833
self.string = self._displayed_string = ''
@@ -800,20 +836,23 @@ def keypress(self, win, char):
800836

801837
elif char in (curses.KEY_DC, curses.ascii.EOT):
802838
""" DEL key, ^D """
839+
self._backslash = False
803840
if self.string:
804841
if logger.isEnabledFor(logging.DEBUG):
805842
logger.debug('action: delete')
806843
self._delete_char()
807844

808845
elif char in (curses.KEY_BACKSPACE, curses.ascii.BS,127):
809846
""" KEY_BACKSPACE """
847+
self._backslash = False
810848
if self.string:
811849
if logger.isEnabledFor(logging.DEBUG):
812850
logger.debug('action: backspace')
813851
self._backspace_char()
814852

815853
elif char in (curses.KEY_UP, curses.ascii.DLE):
816854
""" KEY_UP, ^N """
855+
self._backslash = False
817856
if self._key_up_function_handler is not None:
818857
try:
819858
self._key_up_function_handler()
@@ -825,6 +864,7 @@ def keypress(self, win, char):
825864

826865
elif char in (curses.KEY_DOWN, curses.ascii.SO):
827866
""" KEY_DOWN, ^P """
867+
self._backslash = False
828868
if self._key_down_function_handler is not None:
829869
try:
830870
self._key_down_function_handler()
@@ -836,6 +876,7 @@ def keypress(self, win, char):
836876

837877
elif char in (curses.KEY_NPAGE, ):
838878
""" PgDn """
879+
self._backslash = False
839880
if self._key_pgdown_function_handler is not None:
840881
try:
841882
self._key_pgdown_function_handler()
@@ -847,6 +888,7 @@ def keypress(self, win, char):
847888

848889
elif char in (curses.KEY_PPAGE, ):
849890
""" PgUp """
891+
self._backslash = False
850892
if self._key_pgup_function_handler is not None:
851893
try:
852894
self._key_pgup_function_handler()
@@ -855,6 +897,7 @@ def keypress(self, win, char):
855897

856898
elif char in (9, ):
857899
""" TAB """
900+
self._backslash = False
858901
if self._key_tab_function_handler is not None:
859902
try:
860903
self._key_tab_function_handler()
@@ -866,6 +909,7 @@ def keypress(self, win, char):
866909

867910
elif char in (curses.KEY_BTAB, ):
868911
""" Shift-TAB """
912+
self._backslash = False
869913
if self._key_stab_function_handler is not None:
870914
try:
871915
self._key_stab_function_handler()
@@ -877,9 +921,11 @@ def keypress(self, win, char):
877921

878922
elif 0<= char <=31:
879923
""" do not accept any other control characters """
924+
self._backslash = False
880925
pass
881926

882927
else:
928+
self._backslash = False
883929
if logger.isEnabledFor(logging.DEBUG):
884930
logger.debug('action: add-character')
885931
if self.log is not None:

0 commit comments

Comments
 (0)