Skip to content

Commit 9c27b43

Browse files
committed
Fix '_Termbox__instance' is not defined; implement clear(), height, width
1 parent d890c89 commit 9c27b43

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

examples/termbox/termbox.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def __init__(self, msg):
2020
def __str__(self):
2121
return self.msg
2222

23-
__instance = None
23+
_instance = None
2424

2525
# keys ----------------------------------
2626
KEY_F1 = (0xFFFF-0)
@@ -133,16 +133,16 @@ def __str__(self):
133133

134134
class Termbox:
135135
def __init__(self, width=132, height=60):
136-
global __instance
137-
if __instance:
136+
global _instance
137+
if _instance:
138138
raise TermboxException("It is possible to create only one instance of Termbox")
139139

140140
try:
141-
tdl.init(width, height)
141+
self.console = tdl.init(width, height)
142142
except tdl.TDLException as e:
143143
raise TermboxException(e)
144144

145-
__instance = self
145+
_instance = self
146146

147147
def __del__(self):
148148
self.close()
@@ -154,9 +154,9 @@ def __enter__(self):
154154
return self
155155

156156
def close(self):
157-
global __instance
157+
global _instance
158158
# tb_shutdown()
159-
__instance = None
159+
_instance = None
160160
# TBD, does nothing
161161

162162
def present(self):
@@ -173,17 +173,17 @@ def change_cell(self, x, y, ch, fg, bg):
173173
def width(self):
174174
"""Returns width of the terminal screen.
175175
"""
176-
return int(tb_width())
176+
return self.console.width
177177

178178
def height(self):
179179
"""Return height of the terminal screen.
180180
"""
181-
return int(tb_height())
181+
return self.console.height
182182

183183
def clear(self):
184184
"""Clear the internal cell buffer.
185185
"""
186-
tb_clear()
186+
self.console.clear()
187187

188188
def set_cursor(self, x, y):
189189
"""Set cursor position to (x;y).

0 commit comments

Comments
 (0)