ezcurses Screen

class ezcurses.screen.Cursed(noecho=True, cbreak=True, keypad=True)[source]

Bases: object

Cursed is a context manager that handles the setup and resetting of the terminal for curses programming.

Just wrap your code with:

with Cursed() as scr:
    ...

And either use the scr variable, or create windows or pads from it with scr.new_win or scr.new_pad.

class ezcurses.screen.Pad(screen, size=None)[source]

Bases: ezcurses.screen.Screen

refresh(orig=None, top_left=None, bottom_right=None, clear=False)[source]

Draw out the changes.

Parameters:
  • orig – the optional origin of where to start the top left in the pad, default (0, 0) or the very top left of the full pad
  • top_left – where to start the pad update, default (0, 0)
  • bottom_right – where to end the pad update, default (width, height)
  • clear – clear for the next refresh, default False
class ezcurses.screen.Screen(stdscr)[source]

Bases: object

background(c, color=None)[source]

Draw out a character across the window with an optional color.

Parameters:
  • c – the character to fill the window with.
  • color – the foreground or (fg, bg) colors
border(h=None, v=None)[source]

Draw out a border around a window, with configurable characters.

Parameters:
  • h – the optional horizontal line character used on top/bottom
  • v – the optional vertical line character used on left/right
change_color(pos=None, n=1, color=None)[source]

Change the color of all characters in this line.

Parameters:
  • pos – the position to change, default (0, 0)
  • n – the number of characters to the right to change, default 1
  • color – the optional foreground or (fg, bg) colors
clear()[source]

Clears the screen, window, or pad.

erase()[source]

Erase the screen, window or pad.

get_menu_item(items, orig=None, force=False, color=None, selected_color=None, selected=0, exit_keys=None)[source]

Convenience function to create a menu and return the item selected.

Parameters:
  • items – the list of (key char, item string) menu items. Use None as a key if you don’t want a hotkey for that menu item.
  • orig – optional origin, default (0, 0)
  • force – force the user to make a choice, instead of returning None on ESCAPE.
  • color – the foreground color of the menu item text, or (fg, bg), defaults to (‘white’, ‘black’) or white on black background
  • selected_color – the foreground color of the selected menu item text, or (fg, bg), defaults to reverse of color
  • selected – the integer associated with the item selected, default 0
  • exit_keys – optional set of keys that will exit the menu, which return that value if pressed
getch(**kwargs)[source]

Get an input character as a one-length string, one key press.

Parameters:echo – whether to echo the character while typing, default False
Returns:the character typed
getkey(**kwargs)[source]

Get an input character as an integer (chr/ord), one key press.

Parameters:echo – whether to echo the character while typing, default False
Returns:the integer value of the character typed
getstr(pos=None)[source]

Get an input string at a position, returned on pressing Enter.

Parameters:
  • pos – the optional position, default (0, 0)
  • echo – whether to echo the string while typing, default False
Returns:

the string typed

hline(c, pos=None, n=None)[source]

Draw a horizontal line

Parameters:
  • c – the character to use
  • pos – the optional position to start at, default (0, 0)
  • n – the optional length, default max width
max_size()[source]

The width and height of the screen

Returns:(width, height)
move_cursor(pos=None)[source]

Move the text cursor to the new position.

Parameters:pos – the new position (x, y) or default (0, 0)
multi_menu(menus)[source]

Take multiple menus, and display them to the user and get a result for each. This is useful if you want to do something like show a screen where the user can make multiple selections and you want to get a valid choice for each.

Parameters:menus – a list of menus created with new_menu
Returns:a list of results, each index corresponding to the menu passed
new_layout(**kwargs)[source]

Create a Layout to add rows and columns to.

Parameters:border – whether to draw border around new windows, default True
Returns:the layout object
new_menu(items, orig=None, color=None, selected_color=None, selected=0, exit_keys=None)[source]

Make a new menu in the screen or window, and return it. After that, draw it with:

menu.draw()

And activate the menu with:

menu.get_item()
Parameters:
  • items – the list of (key char, item string) menu items. Use None as a key if you don’t want a hotkey for that menu item.
  • orig – optional origin, default (0, 0)
  • force – force the user to make a choice, instead of returning None on ESCAPE.
  • color – the foreground color of the menu item text, or (fg, bg), defaults to (‘white’, ‘black’) or white on black background
  • selected_color – the foreground color of the selected menu item text, or (fg, bg), defaults to reverse of color
  • selected – the integer associated with the item selected, default 0
  • exit_keys – optional set of keys that will exit the menu, which return that value if pressed
new_pad(size=None)[source]

Create a new pad from the screen

Parameters:size – optional (width, height), default the max terminal
Returns:the new Pad instance
new_win(orig=None, size=None)[source]

Create a new window from the screen.

Parameters:
  • orig – the optional origin, default (0, 0) or top left
  • size – the optional size, (width, height)
Returns:

the new Window instance

refresh()[source]

Draw out the changes to the screen, window or pad.

vline(c, pos=None, n=None)[source]

Draw a vertical line

Parameters:
  • c – the character to use
  • pos – the optional position to start at, default (0, 0)
  • n – the optional length, default max height
write(msg, pos=None, color=None)[source]

Write a message to the screen, window or pad at a position.

Parameters:
  • msg – the message to write
  • pos – the position to write the message in, default (0, 0)
  • color – the optional foreground color or (foreground, background)
class ezcurses.screen.Window(screen, orig=None, size=None)[source]

Bases: ezcurses.screen.Screen

move_window(orig=None)[source]

Move the window to a new origin.

Parameters:orig – the new (x, y) or default (0, 0)
ezcurses.screen.curse(func)[source]

Contents:

Indices and tables