API Reference

Classes

class cursebox.Cursebox(blocking_events=True)

A wrapper for curses which provides simple API calls.

Instances should be created using the with statement, which will take care of initializing the curses environment and disposing of it when the context is lost:

>>> with Cursebox() as cb:
>>>    cb.put(42, 13, "Hello from curses!", colors.black, colors.white)
>>>    cb.refresh()

Cursebox also handles keyboard strokes and events:

>>> event = cb.poll_event()
>>> if event == EVENT_CTRL_C:
>>>     exit()
add_thread(thread)
clear()

Clears the terminal.

height

The height of the current terminal.

hide_cursor()

Hides the cursor.

poll_event()

Checks if an event happens and returns a string related to the event.

Returns -1 if nothing happened during self.screen.timeout milliseconds.

If the event is a normal (letter) key press, the letter is returned (case sensitive)

Returns:Event type
put(x, y, text, fg, bg)

Puts a string at the desired coordinates using the provided colors.

Parameters:
  • x – X position
  • y – Y position
  • text – Text to write
  • fg – Foreground color number
  • bg – Background color number
put_arrow(x, y, direction, fg, bg)
refresh()

Refreshes the screen.

set_cursor(x, y)

Sets the cursor to the desired position.

Parameters:
  • x – X position
  • y – Y position
width

The width of the current terminal.

class cursebox.pairs.Pairs

Collection object that stores curses color pairs.

When a color pair is needed, it can be retrieved by calling __getitem__:

>>> pairs = Pairs()
>>> a_pair = pairs[0, 3]

If the pair does not exist, it is created and pushed in a FIFO dictionary of limited size (32767 entries). A very big terminal will never have more than 10000 characters displayed, so this enables to use virtually all color combinations at all times.

reset()