Browse Source

Working typesetting

Petra Lamborn 4 years ago
parent
commit
62bff8be88
1 changed files with 26 additions and 12 deletions
  1. 26
    12
      fedicurses.py

+ 26
- 12
fedicurses.py View File

10
 
10
 
11
 def newLine(ncwin, lines=1):
11
 def newLine(ncwin, lines=1):
12
     cy, cx = ncwin.getyx()
12
     cy, cx = ncwin.getyx()
13
-    ncwin.move(cy + lines, 0)
13
+    # my, mx = ncwin.getmaxyx()
14
+    try:
15
+        ncwin.move(cy + lines, 0)
16
+    except curses.error:
17
+        pass
14
 
18
 
15
 def bump(win):
19
 def bump(win):
16
     my, mx = win.getmaxyx()
20
     my, mx = win.getmaxyx()
17
     cy, cx = win.getyx()
21
     cy, cx = win.getyx()
18
-    if cx != mx:
19
-        win.move(cy, cx + 1)
20
-
22
+    if cx < mx and cx != 0:
23
+        try:
24
+            win.move(cy, cx + 1)
25
+        except curses.error:
26
+            pass
21
 
27
 
22
 def typeset(text, win, attr, colour):
28
 def typeset(text, win, attr, colour):
23
     my, mx = win.getmaxyx()
29
     my, mx = win.getmaxyx()
24
     line = 0
30
     line = 0
25
     position = 0
31
     position = 0
26
     strlen = len(text)
32
     strlen = len(text)
27
-    while position < (strlen - 1):
33
+    while position < (strlen):
28
         cy, cx = win.getyx()
34
         cy, cx = win.getyx()
29
         if cx == mx:
35
         if cx == mx:
30
             if cy == my:
36
             if cy == my:
31
                 raise curses.error("Out of space")
37
                 raise curses.error("Out of space")
32
         rem = (mx - cx) + 1
38
         rem = (mx - cx) + 1
33
         nsp = text.find(' ', position)
39
         nsp = text.find(' ', position)
34
-        if nsp == -1 or nsp - position > rem:
40
+        if (strlen - position <= rem):
41
+            win.addnstr(text[position:], rem,
42
+                        attr | curses.color_pair(colour))
43
+            position = strlen
44
+        elif (nsp == -1 or nsp - position > rem): # and not strlen - position <= rem:
35
             if cx == 0:
45
             if cx == 0:
36
                 win.addnstr(text[position:], rem, attr |
46
                 win.addnstr(text[position:], rem, attr |
37
                             curses.color_pair(colour))
47
                             curses.color_pair(colour))
40
         else:
50
         else:
41
             win.addnstr(text[position:], nsp - position,
51
             win.addnstr(text[position:], nsp - position,
42
                         attr | curses.color_pair(colour))
52
                         attr | curses.color_pair(colour))
43
-            position = nsp + 1
53
+            position = max(nsp, 0) + 1
44
             bump(win)
54
             bump(win)
45
 
55
 
46
 def printPost(win, post, parser):
56
 def printPost(win, post, parser):
47
-    win.addstr(post["account"]["acct"], curses.A_BOLD)
57
+    # win.addstr(post["account"]["acct"], curses.A_BOLD)
58
+    typeset(post["account"]["acct"], win, curses.A_BOLD, 0)
48
     if (post["reblog"] is not None):
59
     if (post["reblog"] is not None):
49
-        win.addstr(" boosted ")
50
-        win.addstr(post["reblog"]["account"]["acct"], curses.A_BOLD)
51
-    win.addstr(":")
60
+        # win.addstr(" boosted ")
61
+        typeset(" boosted ", win, 0, 0)
62
+        # win.addstr(post["reblog"]["account"]["acct"], curses.A_BOLD)
63
+        typeset(post["reblog"]["account"]["acct"], win, curses.A_BOLD, 0)
64
+    # win.addstr(":")
65
+    typeset(":", win, 0, 0)
52
     newLine(win)
66
     newLine(win)
53
     if (post["spoiler_text"] != ""):
67
     if (post["spoiler_text"] != ""):
54
         win.addstr(post["spoiler_text"], curses.A_UNDERLINE)
68
         win.addstr(post["spoiler_text"], curses.A_UNDERLINE)
115
 
129
 
116
     def handle_endtag(self, tag):
130
     def handle_endtag(self, tag):
117
         if tag == 'p':
131
         if tag == 'p':
118
-            newLine(self.win)
132
+            newLine(self.win, 2)
119
             self.openp = False
133
             self.openp = False
120
         elif tag == 'strong' or tag == 'b':
134
         elif tag == 'strong' or tag == 'b':
121
             self.curatt = self.curatt ^ curses.A_REVERSE
135
             self.curatt = self.curatt ^ curses.A_REVERSE