Exploring terminfo
Grant Edwards
grant.b.edwards at gmail.com
Fri Jan 15 21:30:18 EST 2021
On 2021-01-15, Grant Edwards <grant.b.edwards at gmail.com> wrote:
> On 2021-01-15, Grant Edwards <grant.b.edwards at gmail.com> wrote:
>
>> Entities that are parameterized (e.g. goto location) would need to be
>> passed through curses.tiparm() before they're decoded and printed. I'm
>> goign to try that next.
>
> The curses module doesn't expose tiparm, but you can use tparm
> instead
NB: The example code below may fail to work properly if all of the
below are true.
* You're using a real, physical terminal
* Connected to a real, physical serial port (not a pty)
* Without flow control
* And the terminal requires "pauses" to allow time for the
terminal to execute the some commands before it can accept
further data.
The functionality that is added by tputs() is to insert "padding"
(typically extra NUL bytes) before/after certain certain terminal
operations.
What I _don't_ know at this point is what happens if you're using a
terminfo description that specifies padding, but you're not connected
to a physical terminal via a real serial port.
> #!/usr/bin/python
> import curses,sys
>
> curses.setupterm()
>
> write = sys.stdout.write
>
> bold = curses.tigetstr('bold').decode('ascii')
> norm = curses.tigetstr('sgr0').decode('ascii')
> cls = curses.tigetstr('clear').decode('ascii')
> cup = curses.tigetstr('cup')
>
> def goto(row,column):
> write(curses.tparm(cup,row,column).decode('ascii'))
>
> def clear():
> write(cls)
>
> clear()
> name = input("enter name: ")
>
> for row in [3,5,10,20]:
> goto(row, row+5)
> write(f'{bold}Hi there {name}{norm}')
> goto(row+1, row+6)
> write(f'Hi there {name}')
>
> goto(24,0)
> input("press enter to exit: ")
> clear()
>
More information about the Python-list
mailing list