Browse Source

Non-working two column

Petra Lamborn 4 years ago
parent
commit
fa88bf2af4
1 changed files with 23 additions and 5 deletions
  1. 23
    5
      fedicurses.py

+ 23
- 5
fedicurses.py View File

@@ -2,6 +2,11 @@ import curses
2 2
 from html.parser import HTMLParser
3 3
 from mastodon import Mastodon
4 4
 
5
+def newLine(ncwin, lines=1):
6
+    cy, cx = ncwin.getyx()
7
+    ncwin.move(cy + lines, 0)
8
+
9
+
5 10
 class PostParser(HTMLParser):
6 11
     def __init__(self, ncwin, defncatt):
7 12
         HTMLParser.__init__(self)
@@ -14,11 +19,12 @@ class PostParser(HTMLParser):
14 19
             self.curatt = self.defncatt
15 20
         elif tag == 'strong':
16 21
             self.curatt = self.curatt ^ curses.A_BOLD
22
+        elif tag == 'br':
23
+            newLine(self.win)
17 24
 
18 25
     def handle_endtag(self, tag):
19 26
         if tag == 'p':
20
-            cy, cx = self.win.getyx()
21
-            self.win.move(cy + 2, 0)
27
+            newLine(self.win, 2)
22 28
         elif tag == 'strong':
23 29
             self.curatt = self.curatt ^ curses.A_BOLD
24 30
 
@@ -35,17 +41,29 @@ def main(stdscr):
35 41
             api_base_url = 'd100.club'
36 42
     )
37 43
     posts = mastodon.timeline()
38
-    parser = PostParser(stdscr, 0)
39 44
     stdscr.clear()
40 45
     # stdscr.addstr("test")
41 46
     curses.halfdelay(10)
47
+    my, mx = stdscr.getmaxyx()
48
+    c1w = c2w = (mx - 1) // 2
49
+    if (mx % 2) != 0:
50
+        c2w = c2w - 1
51
+    colw1 = curses.newwin(1, 1, my - 1, c1w)
52
+    colw2 = curses.newwin(1, 1 + c1w + 1, my - 1, c2w)
53
+    #colw1.border()
54
+    #colw2.border()
55
+    parser = PostParser(colw1, 0)
56
+    colw1.move(0,0)
42 57
     try:
43 58
         for post in posts:
44
-            stdscr.addstr(post["account"]["acct"])
45
-            stdscr.addstr(": ")
59
+            colw1.addstr(post["account"]["acct"], curses.A_BOLD)
60
+            colw1.addstr(':', curses.A_BOLD)
61
+            newLine(colw1)
46 62
             parser.feed(post["content"])
47 63
     except:
48 64
         pass
65
+    colw1.refresh()
66
+    colw2.refresh()
49 67
     stdscr.refresh()
50 68
     i = 'c'
51 69
     q = 0