-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindow.py
More file actions
39 lines (27 loc) · 912 Bytes
/
Copy pathWindow.py
File metadata and controls
39 lines (27 loc) · 912 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import curses
from Exceptions import BoundsError
class Window(object):
def __init__(self, curses_window, width, height):
self.window = curses_window
self.window.nodelay(1)
self.width = width
self.height = height
self.window.timeout(1)
def in_bounds(self, x, y):
if x < 0 or x >= self.width:
return False
if y < 0 or y >= self.height:
return False
return True
def put_char(self, x, y, char, color):
if not self.in_bounds(x, y):
raise BoundsError
try:
self.window.addstr(y, x, char, curses.color_pair(color))
except curses.error as e:
pass
def center_text(self, y, text):
length = len(text)
self.window.addstr(int(y), int((self.width - length) / 2), text, curses.A_REVERSE)
def clear(self):
self.window.clear()