summaryrefslogtreecommitdiff
path: root/asciifarm/client/display/window.py
blob: bae7797c97508140cab28ab1ee0353577a72c1df (plain)
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
40



class Window:
    """ Small wrapper around curses windows """
    
    def __init__(self, win, colours=False):
        
        self.setWin(win)
        self.colours = colours
            
    
    
    def setWin(self, win):
        self.win = win
    
    def getSize(self):
        if not self.win:
            return (0, 0)
        height, width = self.win.getmaxyx()
        return (width, height)
    
    def getPos(self):
        if not self.win:
            return (0, 0)
        y, x = win.getparyx()
        return (x, y)
    
    def addString(self, pos, string, colour=(0,0)):
        x, y = pos
        if self.colours:
            self.win.addstr(y, x, string, self.colours.get(colour))
        else:
            self.win.addstr(y, x, string)
    
    def erase(self):
        self.win.erase()