• Re: Tools to help with text mode (i.e. non-GUI) input

    From Alan Gauld@3:633/280.2 to All on Thu Jan 16 12:06:07 2025
    On 15/01/2025 00:54, Grant Edwards via Python-list wrote:

    are your friend. If that's not sophisticated enough the gnu "readline" library with a simple command processor is a common next step.

    On that front the cmd module in Python is often overlooked
    but is useful for structuring a non-GUI-like text UI.

    It doesn't support mouse or screen mapping or colours etc.
    But if all you want/need is a pdb type interface it works well.

    --
    Alan G
    Author of the Learn to Program web site
    http://www.alan-g.me.uk/
    http://www.amazon.com/author/alan_gauld
    Follow my photo-blog on Flickr at:
    http://www.flickr.com/photos/alangauldphotos



    --- MBSE BBS v1.0.8.4 (Linux-x86_64)
    * Origin: ---:- FTN<->UseNet Gate -:--- (3:633/280.2@fidonet)
  • From Roel Schroeven@3:633/280.2 to All on Thu Jan 16 20:09:36 2025
    Op 11/01/2025 om 15:28 schreef Chris Green via Python-list:
    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.
    Maybe pythondialog could be useful for this. I've never used it so I
    can't really tell if it will fit your requirements, but at least it
    seems worth a look. It looks like it supports text input with a default
    value (https://pythondialog.sourceforge.io/doc/widgets.html#single-line-input-fields).
    The other thing you describe is, if I understand correctly, an input
    with predefined values but also the ability to enter a custom value. At
    first sight that doesn't seem to be provided.

    PyPI page: https://pypi.org/project/pythondialog/
    Home page: https://pythondialog.sourceforge.io/

    --
    "Let everything happen to you
    Beauty and terror
    Just keep going
    No feeling is final"
    -- Rainer Maria Rilke


    --- MBSE BBS v1.0.8.4 (Linux-x86_64)
    * Origin: ---:- FTN<->UseNet Gate -:--- (3:633/280.2@fidonet)
  • From Alan Gauld@3:633/280.2 to All on Sat Jan 18 05:11:47 2025
    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.

    --
    Alan G
    Author of the Learn to Program web site
    http://www.alan-g.me.uk/
    http://www.amazon.com/author/alan_gauld
    Follow my photo-blog on Flickr at:
    http://www.flickr.com/photos/alangauldphotos



    --- MBSE BBS v1.0.8.4 (Linux-x86_64)
    * Origin: ---:- FTN<->UseNet Gate -:--- (3:633/280.2@fidonet)
  • From Keith Thompson@3:633/280.2 to All on Sat Jan 18 06:03:16 2025
    Alan Gauld <learn2program@gmail.com> writes:
    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)

    Cool -- but I think you want:

    print(bold, 'Hello world', normal, sep='')

    Whilst you can position the cursor etc it very quickly
    becomes easier to just use full blown curses.

    --
    Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
    void Void(void) { Void(); } /* The recursive call of the void */

    --- MBSE BBS v1.0.8.4 (Linux-x86_64)
    * Origin: None to speak of (3:633/280.2@fidonet)
  • From Grant Edwards@3:633/280.2 to All on Sat Jan 18 08:09:14 2025
    On 2025-01-17, Alan Gauld via Python-list <python-list@python.org> wrote:
    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.

    It's easy to do, but it's tricky to do it right.

    https://github.com/GrantEdwards/Python-curses-and-terminfo

    [...]

    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)

    Don't forget to use tparm() to parameterize strings for things like
    "move curser".

    Once you've parameterized the string (if needed), you've _might_ need
    to worry about the stuff in the string that's meant to be interpreted
    by tputs/putp:

    Quoting man tparm(3)

    All terminfo strings [including the output of tparm] should be
    printed with tputs or putp.

    That's becuase terminfo strings can contain escape sequences that are
    filterd out and interpreted by tputs/putp. The approach above only
    works if you only care about certain terminals, and you know that none
    of the terminfo strings you're using have those interal terminfo
    escape sequences in them [AFAIK, that's true for the linux console,
    xterm and the like, but not for many serial terminals.]

    --
    Grant



    --- MBSE BBS v1.0.8.4 (Linux-x86_64)
    * Origin: ---:- FTN<->UseNet Gate -:--- (3:633/280.2@fidonet)
  • From Mats Wichmann@3:633/280.2 to All on Sat Jan 18 08:11:57 2025
    On 1/17/25 12:03, Keith Thompson via Python-list wrote:
    Alan Gauld <learn2program@gmail.com> writes:
    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 haven't followed this whole thread, but rich (low-level) and textual (higher-level) are designed for this - part of the same project family -
    and really worth a look. I know someone else mentioned rich earlier.

    There's a little video on the textual homepage that shows some of what
    it can do in action:

    https://github.com/Textualize/textual


    --- MBSE BBS v1.0.8.4 (Linux-x86_64)
    * Origin: ---:- FTN<->UseNet Gate -:--- (3:633/280.2@fidonet)
  • From Lele Gaifax@3:633/280.2 to All on Sat Jan 18 19:08:04 2025
    Chris Green via Python-list <python-list@python.org> writes:

    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.

    I'd suggest giving a try to https://pypi.org/project/questionary/,
    seems very close to what you are looking for and very simple to drive.

    Another package is https://github.com/petereon/beaupy, that seems a good
    fit as well.

    ciao, lele.
    --=20
    nickname: Lele Gaifax | Quando vivr=C3=B2 di quello che ho pensato ieri
    real: Emanuele Gaifas | comincer=C3=B2 ad aver paura di chi mi copia. lele@metapensiero.it | -- Fortunato Depero, 1929.

    --- MBSE BBS v1.0.8.4 (Linux-x86_64)
    * Origin: ---:- FTN<->UseNet Gate -:--- (3:633/280.2@fidonet)