Are there any packages that offer this sort of thing? I'd prefer ones
from the Debian repositories but that's not absolutely necessary.
If that's too tied to specific systems for your taste,
why not cook up a library that smooths out those wrinkles?
I'm looking for Python packages that can help with text mode input,
i.e. for use with non-GUI programs that one runs from the command
prompt in a terminal window running a bash shell or some such.
What I'm specifically after is a way to provide a default value that
can be accepted or changed easily and also a way to provide a number
of different values to choose from.
I.e. for the default sort of input one might see:-
Colour? red
Hitting return would return 'red' to the program but you could also
backspace over the 'red' and enter something else. Maybe even better
would be that the 'red' disappears as soon as you hit any key other
than return.
For the select a value type of input I want something like the above
but hitting (say) arrow up and arrow down would change the value
displayed by the 'Colour?' prompt and hitting return would accept the
chosen value. In addition I want the ability to narrow down the list
by entering one or more initial characters, so if you enter 'b' at the Colour? prompt the list of values presented would only include colours starting with 'b' (beige, blue, black, etc.)
Are there any packages that offer this sort of thing? I'd prefer ones
from the Debian repositories but that's not absolutely necessary.
It might also be possible/useful to use the mouse for this.
This is what I was going to suggest. Rich is super easy to use.
I'm looking for Python packages that can help with text mode input,
What I'm specifically after is a way to provide a default value that
can be accepted or changed easily and also a way to provide a number
of different values to choose from.
I.e. for the default sort of input one might see:-
Colour? red
Hitting return would return 'red' to the program but you could also
backspace over the 'red' and enter something else. Maybe even better
would be that the 'red' disappears as soon as you hit any key other
than return.
For the select a value type of input I want something like the above
but hitting (say) arrow up and arrow down would change the value
displayed by the 'Colour?' prompt and hitting return would accept the
chosen value.
In addition I want the ability to narrow down the list
by entering one or more initial characters, so if you enter 'b' at the Colour? prompt the list of values presented would only include colours starting with 'b' (beige, blue, black, etc.)
Are there any packages that offer this sort of thing? I'd prefer ones
from the Debian repositories but that's not absolutely necessary.
It might also be possible/useful to use the mouse for this.
All of that is possible in curses, you just have to code it.
On 2025-01-13, Alan Gauld via Python-list <python-list@python.org> wrote:
All of that is possible in curses, you just have to code it.
All of that is easy with curses in C. Unfortunately, the high level
"panel" and "menu" curses subystems that make it easy aren't included
in the Python curses API,
On 14/01/2025 00:20, Grant Edwards via Python-list wrote:
On 2025-01-13, Alan Gauld via Python-list <python-list@python.org> wrote:
All of that is possible in curses, you just have to code it.
All of that is easy with curses in C. Unfortunately, the high level "panel" and "menu" curses subystems that make it easy aren't included
in the Python curses API,
panel is included. Just import curses.panel.
menu unfortunately isn't but it's not difficult to roll
your own by creating a window with a list of options, provided
you don't try to get too fancy(submenus etc).
Yes, thanks all, maybe just straightforward curses is the way to go.
Looking at some of the 'cleverer' ones they end up looking remarkably
like GUI code, in which case I might as well use a GUI. I have written
a (fairly simple) Gtk based python program, I was just trying to avoid
all the GUI overheads for a little new project.
On 14/01/2025 00:20, Grant Edwards via Python-list wrote:
On 2025-01-13, Alan Gauld via Python-list <python-list@python.org> wrote:
All of that is possible in curses, you just have to code it.
All of that is easy with curses in C. Unfortunately, the high level
"panel" and "menu" curses subystems that make it easy aren't included
in the Python curses API,
panel is included. Just import curses.panel.
menu unfortunately isn't but it's not difficult to roll your own by
creating a window with a list of options, provided you don't try to
get too fancy(submenus etc).
On 11/01/2025 14:28, Chris Green via Python-list wrote:
I'm looking for Python packages that can help with text mode input,
The standard package for this is curses which comes as part
of the standard library on *nix distros.
Yes, thanks all, maybe just straightforward curses is the way to go.
Looking at some of the 'cleverer' ones they end up looking remarkably
like GUI code, in which case I might as well use a GUI.
I have written a (fairly simple) Gtk based python program, I was
just trying to avoid all the GUI overheads for a little new project.
are your friend. If that's not sophisticated enough the gnu "readline" library with a simple command processor is a common next step.
I'm looking for Python packages that can help with text mode input,
i.e. for use with non-GUI programs that one runs from the command
prompt in a terminal window running a bash shell or some such.
What I'm specifically after is a way to provide a default value that
can be accepted or changed easily and also a way to provide a number
of different values to choose from.
I.e. for the default sort of input one might see:-
Colour? red
Hitting return would return 'red' to the program but you could also
backspace over the 'red' and enter something else. Maybe even better
would be that the 'red' disappears as soon as you hit any key other
than return.
For the select a value type of input I want something like the above
but hitting (say) arrow up and arrow down would change the value
displayed by the 'Colour?' prompt and hitting return would accept the
chosen value. In addition I want the ability to narrow down the list
by entering one or more initial characters, so if you enter 'b' at the Colour? prompt the list of values presented would only include colours starting with 'b' (beige, blue, black, etc.)
Are there any packages that offer this sort of thing? I'd prefer onesMaybe pythondialog could be useful for this. I've never used it so I
from the Debian repositories but that's not absolutely necessary.
Alan Gauld <learn2program@gmail.com> writes:
On 11/01/2025 14:28, Chris Green via Python-list wrote:
I'm looking for Python packages that can help with text mode input,
The standard package for this is curses which comes as part
of the standard library on *nix distros.
The thing about curses (which may or may not be a problem) is that, by design, it takes over the whole screen. If you want to do simpler text manipulations (showing a dismissible message, showing bold text, etc.) without interfering with existing text, curses can't do it, at least not easily.
On 15/01/2025 00:41, Keith Thompson via Python-list wrote:
Alan Gauld <learn2program@gmail.com> writes:
On 11/01/2025 14:28, Chris Green via Python-list wrote:
I'm looking for Python packages that can help with text mode input,
The standard package for this is curses which comes as part
of the standard library on *nix distros.
The thing about curses (which may or may not be a problem) is that, by
design, it takes over the whole screen. If you want to do simpler text
manipulations (showing a dismissible message, showing bold text, etc.)
without interfering with existing text, curses can't do it, at least not
easily.
It's not that difficult to use the terminfo codes directly. But
that won't give access to things like lists of default values, mouse
control etc that the OP wanted. But for simple text characteristics
and moving the cursor around terminfo works ok even if a bit tedious.
Here is "hello world" in bold...
import curses
curses.setupterm()
bold = curses.tigetstr('bold').decode('ascii')
normal = curses.tigetstr('sgr0').decode('ascii')
print(bold, 'Hello world', normal)
Whilst you can position the cursor etc it very quickly
becomes easier to just use full blown curses.
On 15/01/2025 00:41, Keith Thompson via Python-list wrote:
Alan Gauld <learn2program@gmail.com> writes:
On 11/01/2025 14:28, Chris Green via Python-list wrote:
I'm looking for Python packages that can help with text mode input,
The standard package for this is curses which comes as part
of the standard library on *nix distros.
The thing about curses (which may or may not be a problem) is that, by
design, it takes over the whole screen. If you want to do simpler text
manipulations (showing a dismissible message, showing bold text, etc.)
without interfering with existing text, curses can't do it, at least not
easily.
It's not that difficult to use the terminfo codes directly.
[...]
Here is "hello world" in bold...
import curses
curses.setupterm()
bold = curses.tigetstr('bold').decode('ascii')
normal = curses.tigetstr('sgr0').decode('ascii')
print(bold, 'Hello world', normal)
Alan Gauld <learn2program@gmail.com> writes:I haven't followed this whole thread, but rich (low-level) and textual (higher-level) are designed for this - part of the same project family -
On 15/01/2025 00:41, Keith Thompson via Python-list wrote:
Alan Gauld <learn2program@gmail.com> writes:
On 11/01/2025 14:28, Chris Green via Python-list wrote:
I'm looking for Python packages that can help with text mode input,
I'm looking for Python packages that can help with text mode input,
i.e. for use with non-GUI programs that one runs from the command
prompt in a terminal window running a bash shell or some such.
Sysop: | Tetrazocine |
---|---|
Location: | Melbourne, VIC, Australia |
Users: | 9 |
Nodes: | 8 (0 / 8) |
Uptime: | 136:14:11 |
Calls: | 161 |
Files: | 21,502 |
Messages: | 79,163 |