浏览代码

Formatting of post

Petra Lamborn 4 年前
父节点
当前提交
69bdbfc3f5
共有 1 个文件被更改,包括 33 次插入5 次删除
  1. 33
    5
      fedicurses.py

+ 33
- 5
fedicurses.py 查看文件

7
     ncwin.move(cy + lines, 0)
7
     ncwin.move(cy + lines, 0)
8
 
8
 
9
 def printPost(win, post, parser):
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
     newLine(win)
16
     newLine(win)
17
+    if (post["spoiler_text"] != ""):
18
+        win.addstr(post["spoiler_text"], curses.A_UNDERLINE)
19
+        newLine(win)
13
     parser.feed(post["content"])
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
 def printAtLevel(stdscr, col1, col2, posts, parser, level):
34
 def printAtLevel(stdscr, col1, col2, posts, parser, level):
16
     col1.clear()
35
     col1.clear()
18
     col1.move(0, 0)
37
     col1.move(0, 0)
19
     col2.move(0, 0)
38
     col2.move(0, 0)
20
     printPost(col1, posts[level], parser)
39
     printPost(col1, posts[level], parser)
40
+    newLine(col1)
21
     printPost(col1, posts[(level + 1) % len(posts)], parser)
41
     printPost(col1, posts[(level + 1) % len(posts)], parser)
22
     try:
42
     try:
23
         col2.addstr(str(posts[level]))
43
         col2.addstr(str(posts[level]))
34
         self.win = ncwin
54
         self.win = ncwin
35
         self.defncatt = defncatt
55
         self.defncatt = defncatt
36
         self.curatt = defncatt
56
         self.curatt = defncatt
57
+        self.openp = False
37
 
58
 
38
     def handle_starttag(self, tag, attrs):
59
     def handle_starttag(self, tag, attrs):
39
         if tag == 'p':
60
         if tag == 'p':
40
             self.curatt = self.defncatt
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
             self.curatt = self.curatt ^ curses.A_BOLD
66
             self.curatt = self.curatt ^ curses.A_BOLD
43
         elif tag == 'br':
67
         elif tag == 'br':
44
             newLine(self.win)
68
             newLine(self.win)
45
 
69
 
46
     def handle_endtag(self, tag):
70
     def handle_endtag(self, tag):
47
         if tag == 'p':
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
             self.curatt = self.curatt ^ curses.A_BOLD
77
             self.curatt = self.curatt ^ curses.A_BOLD
51
 
78
 
52
     def handle_data(self, data):
79
     def handle_data(self, data):
54
             self.win.addstr(data, self.curatt)
81
             self.win.addstr(data, self.curatt)
55
         except curses.error:
82
         except curses.error:
56
             pass
83
             pass
84
+        self.openp = True
57
 
85
 
58
 
86
 
59
 # print(mastodon.timeline()[0]["content"])
87
 # print(mastodon.timeline()[0]["content"])