# A terminal UI for Discourse using Brick

**URL:** <https://discourse.haskell.org/t/a-terminal-ui-for-discourse-using-brick/489>\
**Category:** Show and Tell\
**Created:** [March 21, 2019, 10:17pm UTC](https://discourse.haskell.org/t/a-terminal-ui-for-discourse-using-brick/489 "2019-03-21T22:17:47Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![jack](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/jack/32/239_2.png) [@jack](https://discourse.haskell.org/u/jack)\
**Post date:** [March 21, 2019, 10:17pm UTC](https://discourse.haskell.org/t/a-terminal-ui-for-discourse-using-brick/489/1 "2019-03-21T22:17:47Z")

</div>

I grew jealous of [reddit-terminal-viewer](https://github.com/michael-lazar/rtv) and so [I made a discourse version](https://github.com/jackoe/discourse-tui). Quick thanks to [this FPComplete screencast](https://www.fpcomplete.com/blog/building-tuis-in-haskell) for being such a great introduction to the topic.

[![](https://raw.githubusercontent.com/jackoe/discourse-tui/master/demo.svg?sanitize=true)](https://raw.githubusercontent.com/jackoe/discourse-tui/)

---

<div class="post-metadata">

**Author:** ![f-a](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/f-a/32/2740_2.png) [@f-a](https://discourse.haskell.org/u/f-a)\
**Post date:** [March 22, 2019, 12:28am UTC](https://discourse.haskell.org/t/a-terminal-ui-for-discourse-using-brick/489/2 "2019-03-22T00:28:24Z")

</div>

Excellent! I can run it, but when I select a post:

```
f@x60s:/tmp/discourse-tui/dist-newstyle/build/i386-linux/ghc-8.6.4/discourse-tui-0.1.0.0/x/discourse-tui/build/discourse-tui$ ./discourse-tui http://discourse.haskell.org
discourse-tui: JSONParseException Request {
host = "discourse.haskell.orgt"
port = 80
secure = False
requestHeaders = [("Accept","application/json")]
path = "/489.json"
queryString = ""
method = "GET"
proxy = Nothing
rawBody = False
redirectCount = 10
responseTimeout = ResponseTimeoutDefault
requestVersion = HTTP/1.1
}
(Response {responseStatus = Status {statusCode = 200, statusMessage = "OK"}, responseVersion = HTTP/1.1, responseHeaders = [("Server","nginx"),("Date","Fri, 22 Mar 2019 00:22:53 GMT"),("Content-Type","text/html"),("Last-Modified","Sun, 21 Jan 2018 08:56:48 GMT"),("Transfer-Encoding","chunked"),("ETag","W/\"5a6455d0-33b9\""),("Content-Encoding","gzip")], responseBody = (), responseCookieJar = CJ {expose = []}, responseClose' = ResponseClose}) (ParseError {errorContexts = [], errorMessage = "Failed reading: not a valid json value", errorPosition = 1:1 (0)})
```

---

<div class="post-metadata">

**Author:** ![jack](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/jack/32/239_2.png) [@jack](https://discourse.haskell.org/u/jack)\
**Post date:** [March 22, 2019, 3:21am UTC](https://discourse.haskell.org/t/a-terminal-ui-for-discourse-using-brick/489/3 "2019-03-22T03:21:43Z")

</div>

Thanks for pointing that out. I just pushed the fix.

---

<div class="post-metadata">

**Author:** ![gilmi](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/gilmi/32/45_2.png) [@gilmi](https://discourse.haskell.org/u/gilmi)\
**Post date:** [March 22, 2019, 6:56am UTC](https://discourse.haskell.org/t/a-terminal-ui-for-discourse-using-brick/489/4 "2019-03-22T06:56:50Z")

</div>

It looks great! Good job!

---

<div class="post-metadata">

**Author:** ![f-a](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/f-a/32/2740_2.png) [@f-a](https://discourse.haskell.org/u/f-a)\
**Post date:** [March 22, 2019, 8:15am UTC](https://discourse.haskell.org/t/a-terminal-ui-for-discourse-using-brick/489/5 "2019-03-22T08:15:22Z")

</div>

Ok, i tried it and it definitely is a slick experience (especially considering how poorly discourse degrades on browsers like `lynx`)!

In case you care: `discourse-tui` compiles fine with `cabal new- install` too.

Again, good job!

---

<div class="post-metadata">

**Author:** ![mpickering](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/mpickering/32/4585_2.png) [@mpickering](https://discourse.haskell.org/u/mpickering)\
**Post date:** [March 22, 2019, 8:32am UTC](https://discourse.haskell.org/t/a-terminal-ui-for-discourse-using-brick/489/6 "2019-03-22T08:32:40Z")

</div>

Technical question: Are you using the built in list widget to render the comment threads? How are you dealing with rendering variable length replies? Are you rendering each reply in a fixed height box?

---

<div class="post-metadata">

**Author:** ![jack](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/jack/32/239_2.png) [@jack](https://discourse.haskell.org/u/jack)\
**Post date:** [March 22, 2019, 8:48am UTC](https://discourse.haskell.org/t/a-terminal-ui-for-discourse-using-brick/489/7 "2019-03-22T08:48:16Z")

</div>

Yeah, I’m using the built in fixed-width one. I really had no idea how to do scrolling (as in down the page) otherwise. The top-level topics are fine as fixed-height, but it gets messy with replies/posts. The compromise I picked is to show 8 lines (adding empty space if it’s less), and let someone view the post full-page with the right arrow on keyboard.

If you know of a variable-height solution, please let me know.

---

<div class="post-metadata">

**Author:** ![pagoda\_5b](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/pagoda_5b/32/115_2.png) [@pagoda\_5b](https://discourse.haskell.org/u/pagoda_5b)\
**Post date:** [March 22, 2019, 8:49am UTC](https://discourse.haskell.org/t/a-terminal-ui-for-discourse-using-brick/489/8 "2019-03-22T08:49:30Z")

</div>

It would be great to add markdown rendering as next step.

I know it’s not fair to propose and not do it, but I won’t find the time, so I’m just throwing the idea

---

<div class="post-metadata">

**Author:** ![jack](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/jack/32/239_2.png) [@jack](https://discourse.haskell.org/u/jack)\
**Post date:** [March 22, 2019, 9:07am UTC](https://discourse.haskell.org/t/a-terminal-ui-for-discourse-using-brick/489/9 "2019-03-22T09:07:59Z")

</div>

I appreciate the idea! It would be amazing to have it show up as actual bold, italic, and links (and to also have clickable links open in a terminal browser as an option). Looking at [the Brick.Markup documentation](https://hackage.haskell.org/package/brick-0.47/docs/Brick-Markup.html), it seems like there’s a reasonable way to pull it off. I’m already using pandoc to convert the raw html the API gives to markdown anyway.

It’s next on the list after implementing a way to like/post/reply.

---

<div class="post-metadata">

**Author:** ![jtdaugherty](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/jtdaugherty/32/385_2.png) [@jtdaugherty](https://discourse.haskell.org/u/jtdaugherty)\
**Post date:** [March 29, 2019, 6:39pm UTC](https://discourse.haskell.org/t/a-terminal-ui-for-discourse-using-brick/489/10 "2019-03-29T18:39:29Z")

</div>

Brick author here - for what it’s worth, I wouldn’t recommend using the Markup module for that. On [the matterhorn project](https://github.com/matterhorn-chat/matterhorn) we do Brick renderings of Markdown, and it ends up being much better to just convert the Markdown AST to Vty images / Brick widgets directly. (We use [Cheapskate](http://hackage.haskell.org/package/cheapskate) for Markdown parsing and representation.)

---

<div class="post-metadata">

**Author:** ![jack](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/jack/32/239_2.png) [@jack](https://discourse.haskell.org/u/jack)\
**Post date:** [March 29, 2019, 7:06pm UTC](https://discourse.haskell.org/t/a-terminal-ui-for-discourse-using-brick/489/11 "2019-03-29T19:06:10Z")

</div>

Duly noted. I’ll definitely try Cheapskate.

Also, thank you for making Brick.

---

<div class="post-metadata">

**Author:** ![jtdaugherty](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/jtdaugherty/32/385_2.png) [@jtdaugherty](https://discourse.haskell.org/u/jtdaugherty)\
**Post date:** [March 29, 2019, 7:28pm UTC](https://discourse.haskell.org/t/a-terminal-ui-for-discourse-using-brick/489/12 "2019-03-29T19:28:17Z")

</div>

You’re welcome! I’m glad you’re enjoying it!

---

<div class="post-metadata">

**Author:** ![NorfairKing](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/norfairking/32/514_2.png) [@NorfairKing](https://discourse.haskell.org/u/NorfairKing)\
**Post date:** [March 30, 2019, 2:55am UTC](https://discourse.haskell.org/t/a-terminal-ui-for-discourse-using-brick/489/13 "2019-03-30T02:55:05Z")

</div>

Author of the webinar here; Thank you for the kind words! (Ping me privately if there are other topics that you’d like to see covered!)
