demos/02_curses.py
author Radek Brich <radek.brich@devl.cz>
Wed, 03 Sep 2014 19:13:37 +0200
changeset 110 cf3d49cdd6e2
parent 95 05392e369ede
child 117 8680c2333546
permissions -rwxr-xr-x
Add cursesw driver, using curses get_wch() for unicode input. It alse has enabled keypad() to let curses interpret control keys and mouse input.

#!/usr/bin/env python3

import demobase

from tuikit.core.buffer import Buffer
from tuikit.driver.curses import CursesDriver


colors = ('blue', 'green', 'cyan', 'red',
          'magenta', 'brown', 'lightgray', 'gray',
          'lightblue', 'lightgreen', 'lightcyan', 'lightred',
          'lightmagenta', 'yellow', 'white')

buffer = Buffer(16, 8)
buffer.fill('#')
buffer.hline('-', 1, 1, 14)
buffer.hline('-', 1, 6, 14)
buffer.vline('|', 7, 2, 4)
buffer.puts('Hello!', 8, 4)
buffer.frame()

buffer2 = Buffer(30, 10)
buffer2.setattr('white on black')
buffer2.frame()

for idx, color in enumerate(colors):
    buffer2.setattr(color)
    buffer2.puts(color, 3 + 12 * (idx // 8), 1 + idx % 8)

buffer3 = Buffer(30, 10)
buffer3.setattr('white on black')
buffer3.frame()

for idx, color in enumerate(colors[:8]):
    buffer3.setattr('black on {}'.format(color))
    buffer3.puts(' '+color.ljust(10), 2, 1 + idx)
    buffer3.setattr('{}, underline, bold'.format(color))
    buffer3.puts(' '+color.ljust(10), 15, 1 + idx)

buffer3.setattr('lightgray, blink')
buffer3.puts('blink', 3, 8)

driver = CursesDriver()
with driver:
    driver.draw(buffer)
    driver.draw(buffer2, 20, 00)
    driver.draw(buffer3, 20, 10)
    driver.flush()
    driver.getevents()