What Is In An Interface

Posted on Feb 25, 2021

I’ve been working in a couple of things lately, but most recently, I’ve been revisiting minitimer and I’ve revived an old project of mine that I’m provisionally calling scalc (which isn’t published anywhere yet). Nothing beats getting my feet wet in the warm waters of C, bad pun intended.

If you try out minitimer, you’ll quickly notice that its interface is “hybrid.” It makes use of a standard, common terminal based UI where you see things printed out on the screen and it accepts some basic keyboard commands. But, it also accepts those same commands piped into a named pipe that, unless you’ve tweaked your config.h file, lives in /tmp.

Named pipes are somewhat of a predecessor of UNIX sockets… and a way to use the filesystem as a your user interface… Are you getting the Plan 9 vibes already? Are you? You should!

OK, just a very simple example of what the idea here is.

If you run minitimer on one shell, you can interact with it by pressing some keys while it runs. For instance, the p key pauses minitimer.

$ minitimer 00:10:00
  00:09:34

However, you might want interact with minitimer from another place on your system! Maybe you are redirecting minitimer’s output into WM status bar like swaybar or i3status! How do you interact with it in that scenario? Hey, don’t worry! There comes the named pipe to your rescue!

$ ls -l /tmp/minitimer*
prw------- 1 ari ari 0 feb 25 01:02 /tmp/minitimer.454523
$ echo 'p' > /tmp/minitimer.454523 # Pauses minitimer 
$ echo 'q' > /tmp/minitimer.454523 # Quits minitimer

Some programs bring this to the next level by only providing I/O through files. Notably, IRC client ii routes all I/O back and forth through files. If you’re one of my people, who suspend their systems to disk (“hibernate”), you should know that no matter which frontend you use to do so (e.g. your DE or systemctl), suspending a system on Linux in essence is performed by sending a message to a file.1 The following will suspend your system to RAM:2

# echo 'mem' > /sys/power/state

So, if you thought that UIs were divided into GUIs, terminal UIs (curses, interactive prompts, whatever), and CLIs… well, filesystem-based UIs do also exist!

In fact, my scalc proto-project aims to be a filesystem-based calculator! Still polishing ideas and details, though. I actually love this phase of experimenting that comes before the very first root commit! In a very, very preliminar way, I’d like to have scalc to work somewhat like this:

$ echo '3+4=' > /tmp/scalc.in
$ tail -n 1 /tmp/scalc.out
7

I’d like it not to have any direct output to screen, actually. I’m not that sure whether that will prove to be practical or not, but I believe that the only way to design a program is by trial and error and intuition. Who knows what might arise from this! A web server… LOL, just kidding…

I’m very, very in love with exploring this approach further. I know, it’s not suited for everything, but my intuition is that we could use it for way more things that basically are some kind of filter (in the functional programming sense) that operates on an I/O stream.

I’ll be updating you with further news on my projects in next posts. I think I may be able to have a semi-functional first version of scalc soon. Make sure you follow this site’s RSS feed!


  1. It’s not a FIFO strictly speaking, but the idea is the same. ↩︎

  2. echo’ing ‘disk’ to /sys/power/state will suspend the system to disk, but without any of the important checks that frontends perform before (e.g. checking whether there is enough space on the swap partition), so don’t try it unless you know your system is able to hibernate correctly, at the risk of data loss. ↩︎