Browse Source

Formatting of post

Petra Lamborn 4 years ago
parent
commit
69bdbfc3f5
1 changed files with 33 additions and 5 deletions
  1. 33
    5
      fedicurses.py

+ 33
- 5
fedicurses.py View File

@@ -7,10 +7,29 @@ def newLine(ncwin, lines=1):
7 7
     ncwin.move(cy + lines, 0)
8 8
 
9 9
 def printPost(win, post, parser):
10
-    win.addstr(post["account"]["acct"], curses.A_BOLD)
11
-    win.addstr(':', curses.A_BOLD)
10
+    if (post["reblog"] is not None):
11
+        win.addstr("{} boosted {}:".format(post["account"]["acct"],
12
+                                           post["reblog"]["account"]["acct"]),
13
+                   curses.A_BOLD)
14
+    else:
15
+        win.addstr("{}:".format(post["account"]["acct"]), curses.A_BOLD)
12 16
     newLine(win)
17
+    if (post["spoiler_text"] != ""):
18
+        win.addstr(post["spoiler_text"], curses.A_UNDERLINE)
19
+        newLine(win)
13 20
     parser.feed(post["content"])
21
+    if parser.openp:
22
+        newLine(win)
23
+
24
+    botstring = "{} @ {} UTC".format(post["visibility"],
25
+                                     post["created_at"
26
+                                         ].strftime(
27
+                                             "%Y-%m-%d %H:%M:%S"))
28
+    cy, cx = win.getyx()
29
+    my, mx = win.getmaxyx()
30
+    win.addstr(cy, mx - len(botstring), botstring, curses.A_UNDERLINE)
31
+
32
+    newLine(win, 1)
14 33
 
15 34
 def printAtLevel(stdscr, col1, col2, posts, parser, level):
16 35
     col1.clear()
@@ -18,6 +37,7 @@ def printAtLevel(stdscr, col1, col2, posts, parser, level):
18 37
     col1.move(0, 0)
19 38
     col2.move(0, 0)
20 39
     printPost(col1, posts[level], parser)
40
+    newLine(col1)
21 41
     printPost(col1, posts[(level + 1) % len(posts)], parser)
22 42
     try:
23 43
         col2.addstr(str(posts[level]))
@@ -34,19 +54,26 @@ class PostParser(HTMLParser):
34 54
         self.win = ncwin
35 55
         self.defncatt = defncatt
36 56
         self.curatt = defncatt
57
+        self.openp = False
37 58
 
38 59
     def handle_starttag(self, tag, attrs):
39 60
         if tag == 'p':
40 61
             self.curatt = self.defncatt
41
-        elif tag == 'strong':
62
+            # newLine(self.win)
63
+        elif tag == 'strong' or tag == 'b':
64
+            self.curatt = self.curatt ^ curses.A_REVERSE
65
+        elif tag == 'em' or tag == 'i':
42 66
             self.curatt = self.curatt ^ curses.A_BOLD
43 67
         elif tag == 'br':
44 68
             newLine(self.win)
45 69
 
46 70
     def handle_endtag(self, tag):
47 71
         if tag == 'p':
48
-            newLine(self.win, 2)
49
-        elif tag == 'strong':
72
+            newLine(self.win)
73
+            self.openp = False
74
+        elif tag == 'strong' or tag == 'b':
75
+            self.curatt = self.curatt ^ curses.A_REVERSE
76
+        elif tag == 'em' or tag == 'i':
50 77
             self.curatt = self.curatt ^ curses.A_BOLD
51 78
 
52 79
     def handle_data(self, data):
@@ -54,6 +81,7 @@ class PostParser(HTMLParser):
54 81
             self.win.addstr(data, self.curatt)
55 82
         except curses.error:
56 83
             pass
84
+        self.openp = True
57 85
 
58 86
 
59 87
 # print(mastodon.timeline()[0]["content"])