tb: a terminal browser
I’ve been working on a terminal browser lately.
I got the idea because my friend has a laptop so old, that he cannot even use a GUI on it, he just uses it in tty mode, which means that he couldn’t browse the internet, and also not preview the apps we were working on (Open Classeviva).
I decided to build it in rust because of ratatui, the TUI library, and because I figured I would need more concurrency control than what go gives me.
The engine#
Logically, I began the project by building the browser engine first. I already knew a bit on how browsers work, but not enough.
I found a great guide by Matt Brubeck on how to build a toy browser engine. I’m building upon his guide, making the (what will be) browser more feature complete.
For example, I added complex CSS selector support (such as #navbar.main > a.navbar-link > span
)
and used concurrency primitives to make a concurrency-safe tree structure.
Also, I used pest
as a parser, which I don’t know if that will cause issues in the future, but we’ll see.
Intricacies of the web in the terminal#
Of course, it’s impossible to render a webpage in the terminal perfectly, 1:1.
For example, font-size
is forced to be 1
. And thus, em
and rem
are always worth 1
terminal cell.
One thing that i was surprised to find out wouldn’t be a problem is image support: most modern terminals all support some image protocol which I can use. There are even multiple third party ratatui widgets for images.
What’s next#
I took a break from the project as I was busy in life, but now that I finally have time, I need to work on the layout engine.
I was thinking of using taffy
to calculate the layout, then using ratatui
to render it.
I still need to figure out how to manage text, as taffy
doesn’t deal with text, but I’ll figure something out.