Happy New Year!

A long time ago, a friend introduced me to sl (steam locomotive). It’s a very… simple (yet not simple), program that draws a train on the terminal if you “accidentally” type sl instead of ls.

When I first heard of it, I thought it would be fun to add cars that actually contain file names. Then I started looking into supporting unicode characters… supporting building on windows…

I took a break from working on my fork for a while, until last month when I thought “I want to learn rust, but I don’t know what to write/work on…” SL came to mind.

I read about interoping existing code bases with rust, so I started out with moving the main function to rust and having the backend be in C. Maybe uncommon, but I felt the main was easier to translate first than the actual train functions.

I moved off of ncurses and pdcurses to crossterm which helped increase portability since it removed needing to ship a curses library with the binary.

Then I saw some info on zig, and moved the backend to zig 🤣. Zig has a cool translate-c the original output did not build, but really helped get things going.

I then moved the backend to rust as well, just to see how it would be writing it in rust (there’s some pain points in both languages with constant multi-dimentional arrays vs slices…).

After a bit, I was got curious about rust and wasm and started looking into using wasm-pack to port SL to web (I had moved the “UX” from curses to crossterm, so why not abstract it a bit more to support injecting in a web frontend?). This involved separating out the backend (again…) to a no_std library, trying out traits, setting up a mono repo… yarn workspaces… rollup… github actions… and… Finally a demo below! (if you’re curious, the project lives here).

SL

This is SL hosted in an iframe! You can customize the cars with a query parameter to the iframe as well as adjusting other options such as which train you want to see.

SL

Most of the code for the visuals for the web version was done using GitHub Copilot which was fun to figure out how to utilize better (I get Copilot through work). I originally just used chat and inline chat, but kept hearing about a richer editing experience (which I finally found the UI for!).

All in all… It’s been a fun side project over the holidays. There’s still some oddities with the web version (which luckily I do no see in the native version). And I think it will be fun to make a richer embedded web experience for… no real… usefulness (maybe we’ll see ascii art trains across more websites 🤣).

SL