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 withscr.new_win
orscr.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
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
-
move_cursor
(pos=None)[source]¶ Move the text cursor to the new position.
Parameters: pos – the new position (x, y) or default (0, 0)
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
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
-
-
class
ezcurses.screen.
Window
(screen, orig=None, size=None)[source]¶ Bases:
ezcurses.screen.Screen
Contents: