Skip to content

Commit

Permalink
Improve rendering of posts
Browse files Browse the repository at this point in the history
  • Loading branch information
scriptonist committed Jan 14, 2019
1 parent 793f2d2 commit 99ca9c0
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions pkg/posts/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,27 @@ func openPost(app *tview.Application, postcuid string, list *tview.List) {
return ""
}(),
)
noresponse := len(singlePost.Post.Responses)
for ind, response := range singlePost.Post.Responses {
writeToTextView(
textView,
fmt.Sprintf("\n%d", ind+1),
fmt.Sprintf("---"),
fmt.Sprintf("\n[green]Response %d/%d[white]", ind+1, noresponse),
fmt.Sprintf("[green]--------------[green]"),
renderTerminal(response.ContentMarkdown),
)
if len(response.Replies) > 0 {
writeToTextView(textView,
"\n\t[green]Replies[white]",
"\t[green]=======[white]",
"\n[yellow]Replies[white]",
"[yellow]=======[white]",
)
noreplies := len(response.Replies)
for indreply, reply := range response.Replies {
writeToTextView(
textView,
fmt.Sprintf("\n\t%d", indreply+1),
fmt.Sprintf("\t---"),
fmt.Sprintf("\tAuthor: %s", reply.Author.Name),
fmt.Sprintf("\t%s", renderTerminal(reply.ContentMarkdown)),
fmt.Sprintf("\n[yellow]Reply %d/%d[white]", indreply+1, noreplies),
fmt.Sprintf("[yellow]~~~~~~~~~~~[white]"),
fmt.Sprintf("Author: %s", reply.Author.Name),
indentMarkdown(renderTerminal(reply.ContentMarkdown), "\t"),
)

}
Expand Down Expand Up @@ -135,3 +137,11 @@ func renderTerminal(content string) string {
return out

}

func indentMarkdown(s string, prefix string) string {
// var lines []string
// for _, line := range strings.Split(s, "\n") {
// lines = append(lines, fmt.Sprintf("%s%s", prefix, line))
// }
return fmt.Sprintf("%s%s", prefix, s)
}

0 comments on commit 99ca9c0

Please sign in to comment.