💾 Archived View for geminiprotocol.net › history › phlog › gemini-in-100-lines.gmi captured on 2023-09-08 at 16:00:41. Gemini links have been rewritten to link to archived content

View Raw

More Information

-=-=-=-=-=-=-

Gemini in 100 lines

(originally posted in Gopherspace on 2019-06-24)

Once of the design criteria in the Gemini FAQ is that "a basic but usable (not ultra-spartan) client should fit comfortably within 50 or so lines of code in a modern high-level language. Certainly not more than 100". This is an easy thing to say right at the outset of a project, but if there's any hope of sticking to it then it's important to actually *write* such a client early on to make sure that all the armchair designing isn't rapidly moving us out of territory where it's possible. So, I've gone and done that.

At https://tildegit.org/solderpunk/gemini-demo-1 you'll find a Gemini client written in Python which lets you navigate menus in a similar fashion to VF-1 (i.e. with numeric indices). It will follow redirects, and it can handle relative links in Gemini maps. Anything with a text/* MIME type is just printed to the screen. It will pay attention to the declared charset. Anything with a non-text MIME type will be opened using an external program as specified by /etc/mailcap (If you go to gemini://gemini.conman.org/test you'll find an image!).

It *just* fits in 100 lines! I wouldn't call it comfortable (either the fit to 100 lines or the client for daily use), but it can be done. I'm pretty happy that I could get redirection and binary file handling in to something this small.

A 50 line version would need to be pretty minimal - probably something like wget or curl which just fetches something to the disk and that's it, and/or prints text right to the screen, without formatting menus at all. I'll give this a go. To be honest, it sounds like less than I wanted from the 50 LOC client. It's good to get this hands-on sense for just how much code is needed to do things.

I don't know if Python is unusually compact or verbose here. If you write an equivalently capable client in some other language, please let me know about it! Hopefully this can be done in less than 100 LOC in other languages too.