소스 검색

Non-working two column

Petra Lamborn 4 년 전
부모
커밋
fa88bf2af4
1개의 변경된 파일23개의 추가작업 그리고 5개의 파일을 삭제
  1. 23
    5
      fedicurses.py

+ 23
- 5
fedicurses.py 파일 보기

2
 from html.parser import HTMLParser
2
 from html.parser import HTMLParser
3
 from mastodon import Mastodon
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
 class PostParser(HTMLParser):
10
 class PostParser(HTMLParser):
6
     def __init__(self, ncwin, defncatt):
11
     def __init__(self, ncwin, defncatt):
7
         HTMLParser.__init__(self)
12
         HTMLParser.__init__(self)
14
             self.curatt = self.defncatt
19
             self.curatt = self.defncatt
15
         elif tag == 'strong':
20
         elif tag == 'strong':
16
             self.curatt = self.curatt ^ curses.A_BOLD
21
             self.curatt = self.curatt ^ curses.A_BOLD
22
+        elif tag == 'br':
23
+            newLine(self.win)
17
 
24
 
18
     def handle_endtag(self, tag):
25
     def handle_endtag(self, tag):
19
         if tag == 'p':
26
         if tag == 'p':
20
-            cy, cx = self.win.getyx()
21
-            self.win.move(cy + 2, 0)
27
+            newLine(self.win, 2)
22
         elif tag == 'strong':
28
         elif tag == 'strong':
23
             self.curatt = self.curatt ^ curses.A_BOLD
29
             self.curatt = self.curatt ^ curses.A_BOLD
24
 
30
 
35
             api_base_url = 'd100.club'
41
             api_base_url = 'd100.club'
36
     )
42
     )
37
     posts = mastodon.timeline()
43
     posts = mastodon.timeline()
38
-    parser = PostParser(stdscr, 0)
39
     stdscr.clear()
44
     stdscr.clear()
40
     # stdscr.addstr("test")
45
     # stdscr.addstr("test")
41
     curses.halfdelay(10)
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
     try:
57
     try:
43
         for post in posts:
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
             parser.feed(post["content"])
62
             parser.feed(post["content"])
47
     except:
63
     except:
48
         pass
64
         pass
65
+    colw1.refresh()
66
+    colw2.refresh()
49
     stdscr.refresh()
67
     stdscr.refresh()
50
     i = 'c'
68
     i = 'c'
51
     q = 0
69
     q = 0