Screen Module

The tacotui.screen module contains functions and attributes for manipulating the terminal screen and setting the cursor position. The functions set control the screen directly, where the screen.pos object has string attributes containing ANSI Codes that, when printed to the terminal, control the display.

Basic screen functions

tacotui.screen.clear()

Clear the screen and fill with the theme background color

tacotui.screen.clearline()

Clear the current line and fill with the current background color

tacotui.screen.hide_cursor(hide=True)

Show or hide the cursor

Attributes screen.scrwidth and screen.scrheight provide the character width and height of the screen. These are set on startup, so manually resizing the terminal while the program is running may give weird results.

Printing

A few functions are included that wrap the builtin print method, allowing for printing in a specific color or centering text, without printing a newline.

tacotui.screen.sprint(s)

Print without newline and immediately update the display

Parameters:s (string) – The string to print
tacotui.screen.write(s, c=None)

Write a string in the given color

Parameters:
  • s (string) – The string to print
  • c (string) – Color name from the tacotui.color module
tacotui.screen.centertext(s, width=80)

Center the text, padded with spaces

Parameters:
  • s (string) – The text to center
  • width – Total width of final padded string
Returns:

s – Centered string padded with spaces

Return type:

string

Note

This currently won’t work if s contains escape codes since Python’s format doesn’t know how to exclude those from the string length.

Curosr Positioning

There are two ways to set cursor position. First is the setxy function.

tacotui.screen.setxy(x, y)

Set the cursor position, (1, 1) is top left corner

x: int
Horizontal cursor position
y: int
Vertical cursor position

The second method uses the screen.pos object which has attributes that can be directly printed to the terminal. Attribues screen.pos.x*, screen.pos.y* and screen.pos.xy*_* are available, where the asterisk is replaced with an integer indicating screen position. The attribute value is a string ANSI escape code that will set the terminal position. Note that

Typical usage in an f-string:

screen.sprint(f'{screen.pos.xy5_3}This text starts at x=5, y=3.')

The screen.pos object also has attributes push and pop that push the current screen position onto a stack.

screen.sprint(f'{screen.pos.x4}{screen.push}{screen.pos.x15}x=15')
screen.sprint(f'{screen.pos.pop}x=4 again')

Coloring functions

The color functions set or reset the color applied to all subsequent prints. See Color Module for how to specify the colors.

tacotui.screen.setcolor(c)

Set the current color

Parameters:c (string) – Color name from the tacotui.color module
tacotui.screen.resetcolor()

Reset colors to terminal default