Exploring terminfo

Grant Edwards grant.b.edwards at gmail.com
Fri Jan 15 17:29:46 EST 2021


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:

    #!/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