summaryrefslogtreecommitdiff
path: root/asciifarm/client/display/messagepad.py
blob: f447e44f9d23bf7ac375a203f609b3a14b4d057b (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
41

import curses
import textwrap

class MessagePad():
    
    def __init__(self, maxLines=10):
        #self.maxLines = maxLines
        #self.pad = curses.newpad(maxLines+2, 200)
        self.changed = False
        #self.lastView = None
        self.messages = []
    
    def addMessage(self, message):
        self.messages.append(message)
        self.changed = True
    
    #def getHeight(self):
        #return self.maxLines
    
    def update(self, win, force=False):
        if not self.changed and not force or not win:
            return
        height, width = win.getmaxyx()
        if height < 1:
            return
        lines = []
        for message in self.messages:
            lines += textwrap.wrap(message, width)
        if len(lines) > height:
            lines = lines[len(lines)-height:]
        win.erase()
        win.addstr(0,0,'\n'.join(lines))
        self.changed = False
        win.noutrefresh()
            #0,
            #0,
            #y,
            #x,
            #ymax-1,
            #xmax-1)