author | Radek Brich <radek.brich@devl.cz> |
Sat, 21 Feb 2015 12:01:57 +0100 | |
changeset 118 | 8c7970520632 |
parent 117 | 8680c2333546 |
permissions | -rwxr-xr-x |
83
ebe732b9ef19
Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
1 |
#!/usr/bin/env python3 |
ebe732b9ef19
Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
2 |
|
ebe732b9ef19
Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
3 |
from tuikit.core.buffer import Buffer |
ebe732b9ef19
Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
4 |
from tuikit.driver.curses import CursesDriver |
ebe732b9ef19
Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
5 |
|
ebe732b9ef19
Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
6 |
|
85
6828c5b16087
Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents:
84
diff
changeset
|
7 |
colors = ('blue', 'green', 'cyan', 'red', |
6828c5b16087
Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents:
84
diff
changeset
|
8 |
'magenta', 'brown', 'lightgray', 'gray', |
6828c5b16087
Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents:
84
diff
changeset
|
9 |
'lightblue', 'lightgreen', 'lightcyan', 'lightred', |
6828c5b16087
Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents:
84
diff
changeset
|
10 |
'lightmagenta', 'yellow', 'white') |
6828c5b16087
Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents:
84
diff
changeset
|
11 |
|
83
ebe732b9ef19
Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
12 |
buffer = Buffer(16, 8) |
95
05392e369ede
Refactoring: Swap drawing operations parameters. Coords are now last and have default values.
Radek Brich <radek.brich@devl.cz>
parents:
92
diff
changeset
|
13 |
buffer.fill('#') |
05392e369ede
Refactoring: Swap drawing operations parameters. Coords are now last and have default values.
Radek Brich <radek.brich@devl.cz>
parents:
92
diff
changeset
|
14 |
buffer.hline('-', 1, 1, 14) |
05392e369ede
Refactoring: Swap drawing operations parameters. Coords are now last and have default values.
Radek Brich <radek.brich@devl.cz>
parents:
92
diff
changeset
|
15 |
buffer.hline('-', 1, 6, 14) |
05392e369ede
Refactoring: Swap drawing operations parameters. Coords are now last and have default values.
Radek Brich <radek.brich@devl.cz>
parents:
92
diff
changeset
|
16 |
buffer.vline('|', 7, 2, 4) |
05392e369ede
Refactoring: Swap drawing operations parameters. Coords are now last and have default values.
Radek Brich <radek.brich@devl.cz>
parents:
92
diff
changeset
|
17 |
buffer.puts('Hello!', 8, 4) |
83
ebe732b9ef19
Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
18 |
buffer.frame() |
ebe732b9ef19
Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
19 |
|
85
6828c5b16087
Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents:
84
diff
changeset
|
20 |
buffer2 = Buffer(30, 10) |
6828c5b16087
Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents:
84
diff
changeset
|
21 |
buffer2.setattr('white on black') |
6828c5b16087
Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents:
84
diff
changeset
|
22 |
buffer2.frame() |
6828c5b16087
Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents:
84
diff
changeset
|
23 |
|
6828c5b16087
Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents:
84
diff
changeset
|
24 |
for idx, color in enumerate(colors): |
6828c5b16087
Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents:
84
diff
changeset
|
25 |
buffer2.setattr(color) |
95
05392e369ede
Refactoring: Swap drawing operations parameters. Coords are now last and have default values.
Radek Brich <radek.brich@devl.cz>
parents:
92
diff
changeset
|
26 |
buffer2.puts(color, 3 + 12 * (idx // 8), 1 + idx % 8) |
85
6828c5b16087
Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents:
84
diff
changeset
|
27 |
|
6828c5b16087
Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents:
84
diff
changeset
|
28 |
buffer3 = Buffer(30, 10) |
6828c5b16087
Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents:
84
diff
changeset
|
29 |
buffer3.setattr('white on black') |
6828c5b16087
Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents:
84
diff
changeset
|
30 |
buffer3.frame() |
6828c5b16087
Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents:
84
diff
changeset
|
31 |
|
6828c5b16087
Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents:
84
diff
changeset
|
32 |
for idx, color in enumerate(colors[:8]): |
6828c5b16087
Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents:
84
diff
changeset
|
33 |
buffer3.setattr('black on {}'.format(color)) |
95
05392e369ede
Refactoring: Swap drawing operations parameters. Coords are now last and have default values.
Radek Brich <radek.brich@devl.cz>
parents:
92
diff
changeset
|
34 |
buffer3.puts(' '+color.ljust(10), 2, 1 + idx) |
85
6828c5b16087
Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents:
84
diff
changeset
|
35 |
buffer3.setattr('{}, underline, bold'.format(color)) |
95
05392e369ede
Refactoring: Swap drawing operations parameters. Coords are now last and have default values.
Radek Brich <radek.brich@devl.cz>
parents:
92
diff
changeset
|
36 |
buffer3.puts(' '+color.ljust(10), 15, 1 + idx) |
85
6828c5b16087
Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents:
84
diff
changeset
|
37 |
|
6828c5b16087
Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents:
84
diff
changeset
|
38 |
buffer3.setattr('lightgray, blink') |
95
05392e369ede
Refactoring: Swap drawing operations parameters. Coords are now last and have default values.
Radek Brich <radek.brich@devl.cz>
parents:
92
diff
changeset
|
39 |
buffer3.puts('blink', 3, 8) |
85
6828c5b16087
Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents:
84
diff
changeset
|
40 |
|
83
ebe732b9ef19
Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
41 |
driver = CursesDriver() |
ebe732b9ef19
Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
42 |
with driver: |
ebe732b9ef19
Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
43 |
driver.draw(buffer) |
85
6828c5b16087
Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents:
84
diff
changeset
|
44 |
driver.draw(buffer2, 20, 00) |
6828c5b16087
Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents:
84
diff
changeset
|
45 |
driver.draw(buffer3, 20, 10) |
84
04dfb5ddf031
Refactor Driver, CursesDriver: draw, setattr, input.
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
46 |
driver.flush() |
04dfb5ddf031
Refactor Driver, CursesDriver: draw, setattr, input.
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
47 |
driver.getevents() |