@@ -13,30 +13,44 @@ import (
1313
1414// openPost opens a post in a new tview box
1515func openPost (app * tview.Application , postcuid string , list * tview.List ) {
16+
17+ textView := tview .NewTextView ().
18+ SetDynamicColors (true ).
19+ SetRegions (true ).
20+ SetWrap (true ).
21+ SetWordWrap (true ).
22+ SetTextAlign (tview .AlignLeft ).
23+ SetChangedFunc (func () {
24+ app .Draw ()
25+ })
26+
27+ textView .Box = textView .Box .SetBorder (true ).SetBorderPadding (1 , 1 , 2 , 1 )
28+ textView .SetBorder (true )
29+
30+ go func () {
31+ if err := app .SetRoot (textView , true ).SetFocus (textView ).Run (); err != nil {
32+ app .Stop ()
33+ panic (err )
34+ }
35+ }()
36+
1637 var singlePost Post
38+ textView .SetText ("[green::l]Loading..." )
1739 b , err := makeRequest (fmt .Sprintf ("%s/%s" , postAPI , postcuid ))
1840 if err != nil {
1941 app .Stop ()
2042 log .Fatal (err )
2143 }
44+ textView .SetText ("" )
45+ textView .ScrollToBeginning ()
2246
2347 err = json .Unmarshal (b , & singlePost )
2448 if err != nil {
2549 app .Stop ()
2650 log .Fatal (err )
2751 }
2852
29- textView := tview .NewTextView ().
30- SetDynamicColors (true ).
31- SetRegions (true ).
32- SetWrap (true ).
33- SetWordWrap (true ).
34- SetTextAlign (tview .AlignLeft ).
35- SetChangedFunc (func () {
36- app .Draw ()
37- })
38-
39- title := fmt .Sprintf ("Title: %s" , singlePost .Post .Title )
53+ title := fmt .Sprintf ("\n Title: %s" , singlePost .Post .Title )
4054 var author string
4155 if singlePost .Post .Author .Name != "" {
4256 author = fmt .Sprintf ("Author: %s" , singlePost .Post .Author .Name )
@@ -89,9 +103,6 @@ func openPost(app *tview.Application, postcuid string, list *tview.List) {
89103
90104 }
91105
92- textView .Box = textView .Box .SetBorder (true ).SetBorderPadding (1 , 1 , 2 , 1 )
93- textView .SetBorder (true )
94-
95106 textView .SetDoneFunc (func (key tcell.Key ) {
96107 if key == tcell .KeyEscape {
97108 if err := app .SetRoot (list , true ).SetFocus (list ).Run (); err != nil {
@@ -101,10 +112,6 @@ func openPost(app *tview.Application, postcuid string, list *tview.List) {
101112 }
102113 })
103114
104- if err := app .SetRoot (textView , true ).SetFocus (textView ).Run (); err != nil {
105- app .Stop ()
106- panic (err )
107- }
108115}
109116
110117func writeToTextView (t * tview.TextView , contents ... string ) {
0 commit comments