Thursday, October 28, 2021

May you live in interesting times

Hey everybody.

So last February now, I, in a fit of optimism, thought I'd take on the Guile Potluck duties for 2021: asking people to submit the fun stuff they were up to, and then I'd blog about it. That didn't happen, for which I humbly apologize. But I should know by now that every time I actually commit to something publicly visible in free software, reality intervenes. So from now on, I promise that I will never again commit to anything.

But life is getting better, my vision problems are improving. My back is all healed and I can actually sit in an office chair all day without pain.

So yeah.

Anyway, while I shy away from term commitment, I do have intention to make good on old promises.

In the meantime (and one of the reasons I'm actually talking about feelings on this backup blog right now instead of my standard repository of feelings) I do have to do something about my always-neglected primary website Lonely Cactus which apparently has gone to blog heaven.  A pity. There was some cool stuff on there.

My hope is to get Lonely Cactus up and running on a different set of technologies, as a learning exercise.  Maybe a GNU/Hurd VM. Maybe Guix.  Because if you're going to do something weird, might as well go all the way.

But in real life, if you're keeping score, I have returned to /dev/null. Single again, no kids in the house anymore, unfit, no church life to speak of. I still own this dilapidated, century-old house in Los Angeles, and have a day job, so I'm better off than billions of people. And I'm lucky in that comparatively few people I know have died during the plague year. 

Time for life v4.0, or v5.0. I'm not sure of my current revision number.


Monday, March 29, 2021

Guile Potluck 2021 Part 1: Genshou and Anguish

Preface

Guile Potluck 2021 was an event where hackers got to advertise their exciting new projects.  It wrapped up a few weeks ago, and at that time I was my intention to blog my way through the entrants right away.  Well, I have not been expedient on that front.
I'm so very sorry it has taken me so long to get back to Guile Potluck 2021.  Somewhere between family, kids, the day job, actually working on Guile, and the vague depression that quarantine seems to instill in me, it all got away from me.
But hey, let's see what we've got. I'll start from the end, and work my way back to the beginning.

Genshou, by Walter Lewis

https://git.sr.ht/~wklew/genshou

Here, wklew implements an extensible effects system, that allows stateful computations without any mutation.  Thought provoking stuff, especially if you like pondering monads, denotational semantics and other such things.

Honestly, it is projects like this that activate my impostor syndrome with regards to Scheme. Many Scheme hackers approach it from a deep interest in Computer Science, and mostly I look at their work in awe whilst carrying on with my second-hand understanding of programming that somehow I've built a career on.
 

Anguish, by Rutger van Beusekom

https://gitlab.com/rutger.van.beusekom/anguish
 


 

rutger.van.beusekom has written as parser for the POSIX sh language
using PEG grammar, which he hopes to convert into a full fledged shell
in future. At the moment, it converts shell statements into an SXML-like representation.

I am excited to see someone exercise Guile's PEG parser, which is both powerful and under-utilized.

Thursday, February 18, 2021

Guile Potluck 2021

 Hello All-

In celebration of the (slightly belated) 10-year anniversary of Guile v2.0, we're having another Guile Potluck!  The Guile Potluck is a randomly annual event to give people a chance to show off their Guile projects and skills.  Think of it as a game jam, but, not constrained to games. 

To participate, on or before Mar 6, send an email to guile-user@gnu.org with Potluck in the subject line. Please include instructions on how to find your entry, which could be anything you like.  For example,

   - a script showing off some feature of Guile or your favorite Guile library
   - a blog post describing something interesting about Guile
   - an updated release of a neglected library
   - a mini-game
   - a graphical or audio demoscene-type demo
   
There probably won't be any prizes.  But there will definitely be an e-mail and blog post about the entries.

I'd love to see y'all participate. Feel free to e-mail me at spk121@yahoo.com if you'd like to discuss anything directly.

And please forward this info along, if you know of any other corners of the internet that might be interested.

Regards,
Mike Gran



Monday, July 30, 2018

On the Joys and Perils of YouTube

For want of a social aspect to my technology addiction, of late I have been recording video content and placing it on YouTube.  It has been an interesting endeavor, because it involves skills that I heretofore have never trained.  How does one look good on camera?  What does one do with one's hands?  What it the efficient way to record and edit video.  What is the right way to do lighting and audio?  It has been fun so far, largely because the videos I've recorded still look so amateurish.  That I will be able to learn and progress at something new enchants me.

YouTube is an amazing platform, and the result of untold man-years of effort. The voice recognition involved in the automatic closed captioning is impressive.

But as any graybeard GNU-ster will attest, placing you content solely in the hands of a faceless evil corporation like Google is unwise, since I am not their customer.  Their advertisers are their customers, and their users are just free content creators and a source of training data for their AI.  So, in parallel, I've been revisiting the idea of resurrecting my website.

It is a somewhat overwhelming idea for me because there are infinite possibilities.  I could (and should) just do a WordPress instance and call it a day, for that would be efficient, but, I would love to take the opportunity to learn something new.

Over the weekend, I enumerated my many sources of internet content.  So far, I've discovered
  • YouTube
  • Twitter
  • A code blog on Blogger
  • A personal website, hosted by a hosting provided, that is never updated
  • Another personal website that is just a parked domain right now
  • Yet another personal website, on my home PC, that is rarely updated
  • A security camera
Over a weekend's pondering, I have decided that I will keep three projects, and that each of these will just be different skins on the same content.
  • The true content backend -- not publicly visible -- which will be the source.  Video, images, audio will be stored in their native resolution and formats
  • A website.  It will be GNU-friendly.  No weird javascript.  Video will be medium resolution to split the difference quality and download time.  Probably 720p Ogg+Theora+Vorbis.  Audio will be Ogg+Vorbis or MP3.  Images will be JPEG.
  • YouTube.
  • A gopher server where the 1990s will live on forever.  Video will be shrunk to 352x288 pixel MP4 or CIF-sized 3gp+h.263+AMR_NB.  Audio will be MP3.  Images will be 640x480 GIF.
I will probably end up with a LAMP instance with Python/Django or whatever because hosting VMs like that.

---

In my personal archaeology, I also found these projects that are not externally visible or not working
  • An instance of the never-completed telnet PupperBBS, which has no content
  • A real-time chat service called Jozabad
  • A shoutcast/icecast server that has been serving up the same song for who knows how long

Thursday, January 25, 2018

The Ridiculous Gopher Project: BBSs and ZModem

In the previous entry, I talked about the ridiculous Gopher project, in which I might try to make a presence for myself in Gopher Space.

So my first though was that I would have a blog and a webgallery over gopher.

The blog entries are a very simple prospect, since they need to be plain text.  I don't really like the block paragraph style, but, I did sketch out a conversion from markdown to troff to text that does some nice formatting.

The directory of the blog entries is a bit more complicated.  I had an idea for a cgi that handled directory structures and indices that are date-based with a parallel directory structure and index that is keyword based.

But anyway, I got stuck on my first step, and fell down a rabbit hole, as per usual.

So I thought to myself, what if I wanted to have comments for my gopher blog?  How would that work?  What technology would I used?  Well, in the original Gopher spec, there is a capacity for a Telnet session.  I thought that I could make a tiny Telnet-based BBS with just enough functionality to let one leave a comment or read comments.

So I went on the internet to find a tiny BBS to examine.  I found just about the simplest BBS one could imagine.  It is called Puppy BBS.
I found it in here: http://cd.textfiles.com/simtel/simtel20/MSDOS/FIDO/.index.html

So there this California-based guy named Tom Jennings who does a lot of stuff in the intersection between tech and art. Once upon a time he was a driving force behind FidoNet, which was a pre-internet community of dial-up BBSs. He's done many cool things since FidoNet.

Check out his cool art at http://www.sensitiveresearch.com/

I guess Tom wrote PuppyBBS as a reaction to how complicated BBSs had become back in the late 1980s.

So I thought, hey, does this thing still build and run? Well, not exactly. First off, it uses a MS-DOS C library that handles serial comms, which, of course, doesn't work on Microsoft Windows 10 or on Linux. And even if that library did still exist, I couldn't try it even if I wanted to. I mean, if I wanted to try it I would need two landlines and two dial-up modems so I could call myself. I do have a dial-up modem in a box in the garage, but, I'm not going to get another landline for this nonsense.

Anyway, I e-mailed Tom and asked if I could hack it up and post it on Github, and he said okay. And so this is what this is PuppyBBS.

Puppy BBS has four functions:
  • write messages
  • read messages
  • upload files
  • download files
From there, I started writing a Telnet-based BBS, which PupperBBS.  And that went pretty well.  It took very little time to get the message reading and writing running.  I was on a roll, so I decided that I would quickly tackle the other two functions that PuppyBBS had: uploading and downloading files.  And that was where it all got complicated.

PuppyBBS used XModem for file transfer, because it was the 80's and that was what people did.  But I thought ZModem, which was faster and more reliable, would be the way to go.  So, I thought I'd just link a zmodem library to the BBS and I'd be ready to go.

But, I couldn't find a zmodem library that was ready to go.  All zmodem code seems to be derived for lrzsz, so I downloaded the code from lrzsz and made it into a library.  To do that, I had to understand the code, so I tried to read it.  That code is so very 1980s.  It is terrible, so I had to fix it.

(Let the record show that by "terrible" I mean terrible from a reader's point of view.  It was written with so much global state and no indication of which procedures modify that state.  There is no isolation, no separation of concerns.  As a practical matter, it works great.)

And that led to a full week of untangling it all, which is what became the libzmodem library.  Now my libzmodem isn't really much more readable than the original code, but, at least it makes more sense to me.

Great, now I linked libzmodem to PupperBBS to add some ZModem send and receive functionality.  Now to test it.  I set up PupperBBS.  I telnetted in to the system, got to the BBS, and tried to upload and download some files.  It became apparent that for ZModem to work, the telnet program itself has to have some parnership with rz and sz, launching one or the other as appropriate.

Since this had to have worked in the past, some internet searches led me to zssh on sourceforge  . zssh has a telnet program that has a built-in zmodem send and receive functionality.  Unfortunately, it wasn't packaged on Fedora didn't compile out of the box, so I started trying to understand it and fix it.

So, anyway to summarize:
  1. Let's do a Gopher blog!
  2. How do you do comments?
  3. Telnet works on Gopher!
  4. Let's make a BBS
  5. BBS's do Zmodem
  6. Let's make a ZModem library
  7. Let's make a Telnet client that does ZModem.
And this is why I never finish anything.

Thursday, January 04, 2018

The ridiculous gopher project

My primary New Year's Resolution for 2018 is to start no new projects, and to only finish old ones.  In looking over my repos  -- more aptly titled the graveyard of 1,000 Saturdays -- I have excavated a couple of projects from the earth.

I'm starting, for now, with what is one of the most ridiculous of all possible projects: a gopher-protocol blog.  Do you remember gopher?  It was a protocol and a network ecosystem that existed just before HTTP took over the world.  I presented the world as directories that contained files, and users could poke around and look at those files to their heart's content.

There is a reason that I'm nostalgic for those days, and it lies primarily in how all of the world of HTTP and the world of iPhone and Android applications are really data-mining spy operations.  The gopher protocol is too primitive to allow the wholesale data mining operations that the modern web has become.  I has no client side scripting and cookies.  And because the world of gopher is so strange and hard to reach, there is a bit of a pioneer mindset among aficionados


So yeah, gopher.  A big directory of files of the types on the following list.  Take a look at this table of filetypes that Gopher handles natively.


Itemtype Content
0Text file
1Directory
5PC binary
6UNIX uuencoded file
8Telnet Session
9Binary File
gGIF image
sSound
IImage (other than GIF)
0Text file

Pretty old school, eh?  Just feel the power of the 1990s.

There are a lot of people running blogs in Gopher.  Really they just are directories of plain text files, ordered by date.  It is very pure, but, slightly boring.  So I looked at that list and asked myself if I could create a modern (lol) Gopher blog engine.

You can, of course, write servers that push out dynamic-generated content, but the clients only receive these static files.  Do you remember back when Perl5 was the way one would write CGI scripts that created "dynamic" HTML?  You can to the same thing here: make CGI scripts that create text files or GIF images.

In my conception, a modern gopher weblog engine would have text files of blog entries, a gallery of GIFs, and a commenting system.  Lacking any other gopher available method, the commenting system would be a Telnet session.

So I have picked up a couple of old ideas: a weblog software with a Gopher interface, a web gallery with a Gopher interface, and a tiny Telnet BBS where people can leave comments.  I've (re)started with the BBS, because it is the most ridiculous.

Monday, January 01, 2018

Writing as little as possible

My New Year's Resolution for 2018 is to start no new projects.  For 2018, I will only finish my many, many uncompleted projects.

I've started up with one of my most pointless coding projects: a telnet BBS.  Writing a BBS in the late 1980's and early 1990's was something of a rite of passage.  Much like writing your own blog software was in the late 1990's and 2000's.

But going back to the idea of finishing things, I've given myself some additional constraints.
  • Write as little code as possible.
  • Use common libraries and components sensibly and liberally.
  • Bend my concept to the strengths and constraints created by the libraries and components, instead of wrangling them into matching my vision.
This ends up being very hard to do.  To be specific, it is very difficult to quash my ego and perfectionism; that perfectionism is why my repo has two dozens projects, of which only three are functional.

One of the forces that pushes me to write my own code, instead of using other people's code, is that reading and understanding other people's code and documentation is hard and it doesn't feel like an accomplishment.  To properly use another library, one really does need to put in the work of reading the docs and understanding their logic, which is deeply unsatisfying.

Will 2018 be the year I recover from Incompletion Syndrome?  Time will tell.

Monday, October 30, 2017

Couchsurfing

One of the best decisions I've made over the last decade is to participate in Couchsurfing. Couchsurfing is generically letting travelers stay in your home for free, just for the experience of meeting people.  Couchsurfing is also specifically the corporation that runs the couchsurfing.com website and its associated app.  There are other websites that facilitate traveler hosting, such as Warm Showers.

Key to the couchsurfing.com implementation of the idea is a rating/reviewing system and the idea of preserving one's reputation.  The backpackers comment on the places they've stayed.  The hosts comment on the people that have stayed with them.  A reputation is built up, and, hopefully, safety and civility for hosts and guests is ensured by the online reputation system.  To be honest, it all works quite well.  I've had only one bad experience out of the three dozen groups that have stayed with me.

But there absolutely have been tragic events associated with couchsurfing: theft, sexual assault, and a couple of murders have occurred, as well as a not insignificant amount of douchebaggery that surrounds creepy guys interacting with single women.  But for experienced guests and hosts, I would wager that the safety and security is much greater than other interactions that one has with strangers.

Thinking about all of the current discussions that swirl about about power dynamics, sexual assault, the gig economy, toxic masculinity, and tech, I have put some thought into why couchsurfing.com hasn't degenerated into a complete nightmare like most online communities tend to do.  My conclusion is that power dynamics are weak.  I, as a host, don't particularly fear couchsurfing.com the website.  If they are rude to me, I'll just quit.  If putting up people in my home became inconvenient, I would just quit.  The people that stay with me, if they didn't like me, there are tens of thousands of hotel rooms in the city they could go to.  There is so little gain or loss to be had by participating.  The idea requires, at least on the part of the host, a sense of altruism.

But then again, participating in free software and open source also requires a sense of altruism on the part of the volunteers, yet it doesn't always achieve the same community spirit.

One thing I like about backpacker communities vs free software communities is that there is greater freedom of religion in backpacker communities.  When I head off to mass on Sunday, my guests never ridicule me.  They are there for intercultural exchange, so when someone does something out of the world urban normal, it is odd and interesting.  I have never confessed to be a church-goer in a free software context.  I fear the consequences.

(On couchsurfing.com, they claim there are 70,000 hosts in Los Angeles.  This is a lie.  There are about 300 active hosts and they are hammered with requests daily.)



Wednesday, October 11, 2017

10/11/2017

One of my favorite pastimes is imagining and planning to write new coding projects: researching technologies, checking out libraries I might use, making GUI mockups, downloading similar projects.

I was thinking the other day that it might be fun to create a desktop-based editor that had an HTTP server embedded.  The HTTP server would serve up only one document, which is the document being currently edited, and it would show a live representation of the screen as being show the person editing the document.

I was thinking it might be fun to re-implement the old HyperCard system.

I was thinking that it might be fun to make a real-time chat client/server, like the old talkd daemon did on consoles back in the day.  The client would show every character being typed, in real time, instead of line by line.

I was thinking it might be fun to make a collaboratively editable mosaic: a million tiles across by a million tiles wide, where each tile is 16 pixels square.  Anyone could make new tiles and could place them anywhere on the grid.

I was thinking that it might be fun to make a webpage whose primary purpose was to annoy the server operator.  The webpage would have buttons to make silly noises on the server machine, and the webcam on the server machine would capture pictures of the operator being annoyed and place them on the webpage.

I was thinking it would be fun to make a Twitter bot, that automatically searches for and retweets controversial statements, but, changing key words to make them more benign and playful.

I was thinking that it might be fun to make a Christian devotional app that keeps the list of the ~600 New Testament commandments and chooses one at random for someone to follow on any given day.  Also it could chime for Matins, Sext, Vespers, and Compline.

I was thinking it might be good to make an app for depressed and despairing people. Upon logging in, you could write about your struggle, and after submitting, you'd receive an anonymized note that someone else had written about their struggle.

Monday, September 25, 2017

9/25/17

For work, I have a project that requires a C++ program on Windows 10 that compiles without any library dependencies except the C++14 standard library and the Win32 API only when the C++ standard library lacks necessary functionality. Standard C++ has no fork/exec or spawn, so that is one area when I'm using the Win32 API.   It is a very strange API that is usually abstracted away using CoreFX .NET classes.  I'm rarely this close to Win32 metal.  But I'm beginning to understand why Cygwin's fork/exec are so odd.

--

So I'm fat. I'm probably about the median weight by USA standards, but, I'm still overweight in a BMI sense.  Of course almost all USA men have a BMI above the recommended 25.1 or whatever.

But I once had an eating disorder.  When I was young, I basically starved myself.  As part of my recovery from that, I've had to change my thinking completely.  I stopped letting myself be concerned about what my weight was or what I was eating.  Whenever I find myself worrying to much about food or weight, I tell myself that I am not allowed to concern myself with that, and I don't let myself think about it.

But now I've decided to lose some weight.  To avoid going off the rails, I'm trying to find some non-subjective metrics about weight, so that I don't have to trust the evidence of my (anorexic, lying) eyes.

That lead me into some interesting research on what shape American men used to be, before the obesity epidemic.  And some of the best metrics for men, and what shape men used to be, is from the US Department of Defense.

DOD-HDBK-743A (1991) "Anthropometry of U.S. Military Personnel" and Technical Report 72-51-CE (1971) "The Body Size of Soldiers: U.S. Army Anthropometry: 1966" are a deep dive into the length, breadth, and circumference of every part of a man.  The difference between then and now is astounding.


Friday, September 22, 2017

9/22/17

In digging through the ASIO C++ library examples, I came across an actual use of std::bind. Its entry in cppreference seemed like buzzword salad, so I never previously had paid it any attention.

But in ASIO, they use std::bind to create functions from class methods and associated data.  The functions get passed to its async driver.  So if I liken the output of std::bind to a sort of closure that returns a procedure, it makes sense to me.

Wednesday, September 20, 2017

9/20/2017

On my birthday, I kayaked the sea caves on Santa Cruz island, which was fun.

I've been quite depressed lately: my exercise regimen has faltered.

I'm glad to find that one can use ASIO as a header-only package without installing all of Boost.

Saturday, November 05, 2016

Movin' on up to the Top

Maybe it was the death of Pieter Hintjens, or maybe just (late) middle age that has me mentally reviewing the type of programming that I’ve done and how I’ve gone about it.

But here’s the thing: I remember paper tape and VT420s and CP/M and 8" floppies.  I am a dinosaur.

When I started programming, I started with the high-level language of the 1980s: plain old C.  And I did it on the high-level platforms of the day: MS-DOS and UNIX. This was a great choice, in hindsight, because after 30 years, I’m still programming on C in UNIX-like systems.

But as technology advanced, my niche, which was once the top level of the stack -- CLI programs of the old UNIX philosophy – is now basically two levels up from the bottom.  And many, many layers have been built atop the layer where I make my living.

I’m down in the weeds, so to speak.  And as a consequence, none of my non-tech friends have ever understood what I do because there is nothing I can show them that has any connection to their understanding of technology: phone apps, webpages, or desktop applications.  Talking about DO178B or writing device drivers at dinner is a bit of a snoozefest.

There’s another thing that has held me down in the weeds: free software.  For most of my career I’ve been working in free software: GNU, GCC, Linux.  It places a high value on stability.  I have programs that I've been maintaining for over a decade with not a huge amount of effort.  That stability is so comforting.

Maybe it might be fun to climb my way back to the top of the stack: this highest level languages and toolkits.  In the GUI space, the amount of churn is rather amazing, but, then again, the amount of churn in the UX patterns form factors is also very high.

I'm not really sure what is at the top of the stack these days.  I did some searching.

Likely the highest level toolkit and language out there right now is Unity, but, it is a bit specialized for the game space.

The highest level language out there right now is undoubtedly Perl 6, but, its GUI toolkit hooks seem to be rather raw.

For Windows 10, C# on UWP is probably the winner.

Among the maintained languages for the GTK/Gnome stack, the high level language is probably Python.  Among the maintained languages for the Qt stack, is it QML and C++.

I don't know much about mobile, but, Android seems to be C# via Xamarin, and iOS is Swift.

In the web space, it is obviously JavaScript of some description. I have no clue what the top level GUI toolkit is.  Maybe it is the React JavaScript library.  As for the language itself, plain old JavaScript seems to be coming back in fashion.  The back end is mysterious.  It used to be Java.  Now it seems to be one of a dozen languages and rail-like things.

After Unity, Qt seems to be the most multiplatform native toolkit, with HTML5 being the most multiplatform of all.

The real question is, if I wanted to write a stupid program that my friends could run, what platform would it be?

HTML5 would be the best, followed by native mobile, followed by desktop Windows 10. It is a shame that the HTML5 development experience is such a mess.

It is interesting how there is so much fragmentation in the high level. I wonder how many of these toolkits will still be relevant in five years?  Microsoft toolkits have the highest level of churn. Remember WinForms or XNA?

Maybe I should stick with Unix-like CLI in C, where I belong.

What do you think?  Do you have a different opinion on what is the high-level language and toolkit on your favorite platform?

Saturday, October 29, 2016

guile-aspell 0.3 released

I am pleased to announce an update of guile-aspell, which is a library for comparing a string against a dictionary and suggesting spelling corrections. It is in the GNU Guile dialect of the Scheme programming language.  It is based on the aspell library.

The webpage for the library is at http://lonelycactus.com/guile-aspell.html

The development tree is at https://github.com/spk121/guile-aspell/

The latest source archive is at http://lonelycactus.com/tarball/guile_aspell-0.3.tar.gz

The NEWS for this release is
- move to FFI bindings
- drop Guile 1.8 support

There is no mailing list per se, but, you can contact the project either via https://github.com/spk121/guile-aspell/issues or by e-mailing me directly at spk121@yahoo.com

Thanks,
Mike Gran

Sunday, October 23, 2016

guile-curl v0.4 released

I am pleased to announce an small update of guile-curl, which is a library for fetching files by URL from the internet in the GNU Guile dialect of the Scheme programming language.  It supports many protocols, such as https, ftp, tftp, and, most importantly, gopher.

The webpage for the library is at http://lonelycactus.com/guile-curl.html

The development tree is at https://github.com/spk121/guile-curl/

The latest source archive is at http://lonelycactus.com/tarball/guilecurl-0.4.tar.gz

The NEWS for this release is
- support for READDATA callbacks
- bug fixes, especially with respect to garbage collection on newer versions of Guile.

There is no mailing list per se, but, you can contact the project either via https://github.com/spk121/guile-curl/issues or by e-mailing me directly at spk121@yahoo.com

Thanks,
Mike Gran

Sunday, October 02, 2016

The Bug Report

So I get a bug report. It is on GNU/Linux, of course, because that is the only ecosystem that sends bug reports.

So first I boot up my work box (Computer #1, Windows 10) which is the one that has the sweet monitor and try to VPN to the Server box (Computer #2, GNU/Linux Fedora Server, amd64).  But, of course, at one point I'd stripped all the non-console-mode functionality off of the server, so VPN is a fail.  I could have done the fix easily via ssh and emacs-nox, but, I figure it will only take a minute to get a graphical environment up and running.

There's a GNU Linux VM running on VirtualBox on the work box, but, I get distracted from the actual problem when I can't figure out how to get VirtualBox to create a large screen.  Totally not a problem, but, I get obsessed with this minutiae and can't let it go. I waste time tweaking the virtual graphics card settings with no effect.

So then I boot up the old linux box (Computer #3, GNU/Linux Fedora Workstation). It is 64 bit, but, it is running the i686 distro for reasons lost to history.  And then I remember that when I upgraded my wireless router, it stopped connecting via USB-connected Wifi. There are wpa_supplicant errors. Don't know why.  Spent a couple of hours trying to make it work.

Thus, I drag the old linux box to the room with the router so I can plug it in directly.  The only table is covered in padlocks, bottles of sunscreen, beads, jars of coins, and multiple Rubik's Cubes.  I clear a space.


The power cable to the spare monitor has gone missing.  It is a tiny HP w17e, but, still higher resolution than what I was getting from VirtualBox.   I search for 20 minutes. Eventually steal the power cable from work box.  My mostly ruined back complains when I shimmy under the desk to untangle it from the cable octopus.

I boot up old linux box.  Huh, it is only 100BaseT.  I dutifully do a "dnf upgrade". 1404 packages to update.  That takes another half hour.

And thus, I've used up the four hours of Saturday morning time which is the only time I have to devote to personal hacking.  Sorry bug reporter.  I'm too stupid to work on your request, and the computer gods hate me.  Better luck next week.

Tuesday, July 12, 2016

Pip-Boy like terminal application in Guile, part 4: the terminal

This is the fourth in a series of articles where I try to recreate some Pip Boy like displays in GNU Guile and ncurses.

A Pip Boy is a fictional computer in the Fallout 4 computer games.  GNU Guile is an implementation of the Scheme language.  Ncurses is a library for creating text user interfaces on terminals like the Linux terminal, Xterm, or the Gnome Terminal.

One of the iconic experiences in Fallout 4 is using the in-game computers, which are bulky, green screen monochrome terminals not unlike a DEC VT100.  Actually a closer match is the Televideo TVI-912.  Generally they are used in two ways: displaying a text block with some selectable links, or playing a hacking minigame.  Today we'll look at the first.

The basic user experience is this:
  • When activated, the terminal will begin an animation where it is add adding text to the screen one glyph at a time at about ~75 characters per second.  There is a tick sound associated with each glyph appearing on the screen.
  • Clicking the mouse or pressing enter will interrupt this drawing animation and will make all the text appear on the screen.  There is a tick sound associated with this.
  • Once drawing is complete, any text surrounded by square brackets become a link.
  • The first link is highlighted.
  • Mousing over a link or using the arrow keys will move between links.  There is a tick sound associated with moving between links.
  • Clicking on a link or pressing enter will select the highlighted link and end the interaction.  There is a sound associated with selection.
So, here there is user interaction, audio cues, time-based rendering.  It actually is a fair bit of functionality, and it also is not too friendly to the paradigm provided by the ncurses toolkit.


So I put together three different code units
As a side note, Guile has had a complete set of bindings to the multimedia enving GStreamer, which I wanted to use, but, it appears to be in need of some maintenance.  I did look at it so see if I could patch it up, but, the binding is related to the Glib binding, and I didn't want to take the time to understand all that right now.  Pulseaudio is much lower level, but, also much simpler.  I had code lying around from some old game engine attempt.

If you've coded in QT or GTK, you know that a central function of a GUI toolkit main loop is to allow each widget to send out notifications and to have other widgets be able to subscribe and react to these notifications.  In QT, these are "signals" and "slots".  In GTK they are "signals" and "signal handlers".
To keep things somewhat simple, the primitive main loop works like this...
  • There are one or more event handlers. An event handler may have an associated widget.
  • The main loop checks for an event in the queue: either a keypress, a mouse event, or a signal sent out by one of the widgets. If it finds an event, it sends it to all the event handlers.  Every handler receives every event: there is no attempt to be precise.
  • If no event is ready, the main loop sends an "idle" event to all the signal handlers, does a single step in Pulseaudio's main loop, and then sleeps for a few microseconds.

This is familiar territory.  There's nothing new under the sun.

I had to choose between letting Pulseaudio run its own event loop in its own thread, or to merge Pulseaudio's event look in to my main event loop.  I chose the latter.

Put together, it all looks like this.  For the life of me, I cannot seem to record audio on my screengrab.  I blame Wayland.



The code, in its current form, is here.  It is not ready for use.

Sunday, June 12, 2016

A Pipboy-like terminal application in Guile: Part 3 - labels and progress bars

So, in trying to put together a new release of the ncurses binding for GNU Guile, I decided I'd try to make a Pip-Boy like application that runs in a terminal emulator like xterm or Gnome Terminal  This is just for the nonsense of it, and the challenge.

FYI, Ncurses is a library for text user interfaces.  Guile is an implementation of the Scheme programming language.  And a Pip Boy is a fictional computer that appears in the Fallout video games.

In the first two parts of this little series of nonsense (part 1part 2), I wrote about how rendering a string -- turning a logical string into a display string -- got very complicated once you tried to word break properly with non-English and non-ASCII text, deal with control characters, and think about bi-directionality. Unicode is hard.  I pulled in two libraries, GNU Fribidi and GNU Libunistring, to create this procedure to wrap a string.  So much coder's blood spilled to do something so apparently simple... 

(define (string-render str tabsize n-cells alignment bidi)
  "Given a string STR, this converts the string into a list of strings
with each string contining N-CELLS cells or fewer.  Tabs are expanded
into TABSIZE spaces.  Other Unicode spaces are replace with the common
space character.  Any control characters are replaced with replacement glyphs.  If alignment is 'left, lines are padded with spaces at the end of each string to take up N-CELLS.  If ALIGNMENT is 'right, lines are padded with spaces on the left. ALIGNMENT can also be 'center. If BIDI is true, strings are converted from logical order to visual order."

So anyway, I bashed out a couple of widgets.
  • A "label" is some wrapped text in a box, possibly with a border
  • A "progress bar" is short text followed by a colored bar whose length is a representation 0% to 100%.
There isn't much to say about the code, which is here.  It is all very rough and boring and workman-like and verbose.  To render these widgets, I settled on an outside-in drawing model.
  1. The ncurses panel's size is determined first.
  2. Any border is on the outside edge of the panel, reducing the available window size by 1 on all four sides.
  3. Inside of that is a user-defined padding width.
  4. What remains inside of that is available for content.


Here's more Unicode and xterm trivia, which excites me because I am a weirdo.

Boxes

There are a few usable sets of border drawing characters.  These should be well aligned if you have a proper monospace font in your browser.

;; Light box
;; ┌─┐
;; │ │
;; └─┘
(define *box-chars-light* "┌─┐│ │└─┘")
;; Light round box
;; ╭─╮
;; │ │
;; ╰─╯
(define *box-chars-rounded* "╭─╮│ │╰─╯")
;; Heavy box
;; ┏━┓
;; ┃ ┃
;; ┗━┛
(define *box-chars-heavy* "┏━┓┃ ┃┗━┛")
;; Double box
;; ╔═╗
;; ║ ║
;; ╚═╝
(define *box-chars-double* "╔═╗║ ║╚═╝")
;; Block-char box
;; ▛▀▜
;; ▌ ▐
;; ▙▄▟

(define *box-chars-block* "▛▀▜▌ ▐▙▄▟")

xterm 256-color palette

If you want a good all-green palette from the xterm 256-color palette without modifying the xterm colors, you have about ~10 available colors.


With the above widgets and colors, I was able to make the following with just a few (very long) lines of code.

Next Time

Before I get to the interactive widgets, I want to get to the audio design.  In Fallout 4, there are tiny click noises when you scroll or select an object on the GUI, which is very satisfying from a UX perspective.  So I have to figure out how to do some audio.  I guess I'm going to have to dig into GStreamer, which is always daunting...

Thursday, June 09, 2016

Mapping xterm 256-color palette colors to X11 color names

Here is a table that might be of some use to somebody, someday.

The xterm-like terminals all have pretty similar predefined colors in their 256-color palettes.  The 1st eight colors seem to vary since they often get replaced with system colors, but the remainder are quite stable among 256-color terminal emulators claiming xterm compliance.

Unrelated to this, X11 has long included a file called /usr/share/X11/rgb.txt that has names of colors.  I wondered what overlap there was between these two things.

So, this is a list of the xterm 256-color palette indices vs X11 RGB color names.  To declare something a match, I chose the closest X11 color to the xterm palette color in LAB coordinates, but, never searched farther that 6.9 units of difference in LAB space.  Under those criteria, 129 of 256 xterm colors approximate named X11 RGB colors.



0: BLACK
1: WEBMAROON
2: WEBGREEN
3: OLIVE
4: NAVY, NAVYBLUE
5: WEBPURPLE
6: TEAL
7: SILVER
8: WEBGRAY, WEBGREY
9: RED, RED1
10: GREEN, LIME, X11GREEN, GREEN1
11: YELLOW, YELLOW1
12: BLUE, BLUE1
13: MAGENTA, FUCHSIA, MAGENTA1
14: CYAN, AQUA, CYAN1
15: WHITE
16: BLACK
18: BLUE4, DARKBLUE
20: MEDIUMBLUE, BLUE3
21: BLUE, BLUE1
22: DARKGREEN
24: DEEPSKYBLUE4
26: ROYALBLUE
28: GREEN4
30: CYAN4, DARKCYAN
37: LIGHTSEAGREEN
40: GREEN3
44: CYAN3
46: GREEN, LIME, X11GREEN, GREEN1
48: SPRINGGREEN, SPRINGGREEN1
51: CYAN, AQUA, CYAN1
54: INDIGO
59: GRAY37, GREY37
62: SLATEBLUE3
65: DARKSEAGREEN4
66: PALETURQUOISE4
68: CORNFLOWERBLUE
74: SKYBLUE3
75: STEELBLUE1
76: CHARTREUSE3
78: SEAGREEN3
79: MEDIUMAQUAMARINE, AQUAMARINE3
80: MEDIUMTURQUOISE
86: AQUAMARINE, AQUAMARINE1
88: RED4, DARKRED
89: MAROON4
90: MAGENTA4, DARK MAGENTA, DARKMAGENTA
92: DARKVIOLET
94: DARKGOLDENROD4
95: LIGHTPINK4
96: PLUM4
100: YELLOW4
102: GRAY53, GREY53
108: DARKSEAGREEN
110: SKYBLUE3
114: PALEGREEN3
116: DARKSLATEGRAY3
117: LIGHTSKYBLUE
118: CHARTREUSE, CHARTREUSE1
122: AQUAMARINE, AQUAMARINE1
123: DARKSLATEGRAY1
134: MEDIUMORCHID3
136: DARKGOLDENROD
138: ROSYBROWN
141: MEDIUMPURPLE1
143: DARKKHAKI
145: GRAY69, GREY69
149: DARKOLIVEGREEN3
152: POWDERBLUE
154: GREENYELLOW
159: PALETURQUOISE1
160: RED3
162: VIOLETRED
164: MAGENTA3
167: INDIANRED
171: MEDIUMORCHID1
172: ORANGE3
173: LIGHTSALMON3
178: GOLD3
180: BURLYWOOD3
184: YELLOW3
186: KHAKI3
187: LEMONCHIFFON3
188: GRAY84, GREY84
195: LIGHTCYAN, LIGHTCYAN1
196: RED, RED1
198: DEEPPINK, DEEPPINK1
201: MAGENTA, FUCHSIA, MAGENTA1
203: INDIANRED1
205: HOTPINK
208: DARKORANGE
209: SALMON1
210: LIGHTCORAL
211: PALEVIOLETRED1
213: ORCHID1
214: DARKGOLDENROD1
215: SANDYBROWN
217: LIGHTPINK1
220: GOLD, GOLD1
223: PEACHPUFF, PEACHPUFF1
224: MISTYROSE, MISTYROSE1, MISTYROSE2
225: THISTLE1
226: YELLOW, YELLOW1
230: LIGHTGOLDENRODYELLOW
231: WHITE
232: GRAY3, GREY3
233: GRAY7, GREY7
234: GRAY11, GREY11
235: GRAY15, GREY15
236: GRAY19, GREY19
237: GRAY23, GREY23
238: GRAY27, GREY27
239: GRAY30, GREY30, GRAY31, GREY31
240: GRAY34, GREY34, GRAY35, GREY35
241: GRAY38, GREY38, GRAY39, GREY39
242: GRAY42, GREY42
243: GRAY46, GREY46
244: WEBGRAY, WEBGREY
245: GRAY54, GREY54
246: GRAY58, GREY58
247: GRAY62, GREY62
248: GRAY66, GREY66
249: GRAY70, GREY70
250: GRAY74, GREY74
251: GRAY78, GREY78
252: GRAY81, GREY81, GRAY82, GREY82
253: GRAY85, GREY85, GRAY86, GREY86
254: GRAY89, GREY89, GRAY90, GREY90
255: GRAY93, GREY93

Saturday, June 04, 2016

A Pipboy-like terminal application in Guile: Part 2 - more on strings

Hello again. I'm back to talk about recreating some Pip Boy like terminal widgets in ncurses.

Last time, I started talking about the remedial problems of how to *render* a string for a character cell console, e.g., how to convert a logical string to a list of visual strings that can be displayed on a terminal.  So far, I said that you need to
  • Put the string in Unicode NFC normalization, because NFC normalized strings are more likely to be prepared glyphs on a terminal and not overstruck glyphs.  Unicode normalization is discussed in http://www.unicode.org/reports/tr15/
  • Convert tabs to spaces
  • Replace almost all of the control characters or Private Use Area characters with replacement glyphs.  This hygiene is necessary since some unhandled control character could garble the terminal display.  Some control characters that don't get removed are the 5 line separators (CR, LF, NEL, PS, and LS) and the 8 bidirectional  formatting characters (LRE, RLE, LRO, RLO, PDF, LRI, RLI, FSI, PDI, LRM, RLM, and ALM) because we'll use them in a second.
So that just leaves
  • Prepare to handle any right-to-left text in the string.  This is described in the Unicode Bidirectional Algorithm in http://www.unicode.org/reports/tr9/
  • Do any Arabic shaping of the glyphs
  • Wrap the string to a given number of character cells.  The Unicode line-breaking algorithm is described here: http://www.unicode.org/reports/tr14/tr14-35.html
  • Pad the list of wrapped strings to left, center, or right aligned

Bidirectional text

First off, I'm not qualified to talk about this, but here's the highlights.

Most European languages are written left to right.  The big right-to-left alphabets are Arabic and Hebrew.  Here in the Los Angeles, I'd guess the most common right-to-left languages are probably Persian, Hebrew, Arabic, and Yiddish.

But Scheme strings are normally encoded in logical order: e.g. the beginning of a string is the part of the string that would be read first by a human.  If a string contained a line of French, the first character would be the left-most character to be displayed on a screen.  If it contained Arabic, the first character would be the right-most character to be displayed on a screen.

Terminal emulators generally take one of two strategies when given strings to display. They either
  • Display the text from left-to-right regardless of the contents of the text
  • Or, try to be context sensitive when they display the text, switching from left-to-right and right-to-left depending on the apparent language of the text
Weirdly, in a ncurses application, neither strategy is particularly helpful.  If a terminal does the former, it becomes the programmers' responsibility to convert the string from logical order to visual order.  If it does the latter, and you ask ncurses to write a string at a given (y,x) position, it is hard to know if that x is columns counted from the left or columns counted from the right.

Consider the following program, and its output on the Cygwin terminal.  It starts ncurses, prints a line of Latin text starting at column 30, row 1, and prints a word in the Hebrew alphabet starting at column 30, row 2.  Both lines are supposed to begin a column 30, but, the terminal tries to be helpful and makes the second line print in the 30th column from the right, which is unlikely to be the intention of the programmer.

(use-modules (ncurses curses))
(setlocale LC_ALL "")
(define win (initscr))
(addstr win "LATIN TEXT" #:x 30 #:y 1)
(addstr win (string #\ט\# ק\# ס\# ט ) #:x 30 #:y 2)
(refresh win)
(sleep 10)
(endwin)



So, what to do?

To complicate matters, Unicode has some explicit control characters that can be embedded in strings when one wants to explicitly state the directionality of all or part of the text.  They can be used to explicitly indicate the direction of a run of text, or override the current general direction of the text. The 8 bidirectional  formatting characters (LRE, RLE, LRO, RLO, PDF, LRI, RLI, FSI, PDI, LRM, RLM, and ALM) need to be interpreted.  See Unicode TR#9 for details.

One strategy is to
  1. Use a library like GNU FriBiDi to convert the string from logical to visual order
  2. Set the terminal program to *not* try to help with bidirectionalization.
So, the FriBiDi function fribidi_log2vis is the important function for this.  There needs to be a Guile function that wraps up the FriBiDi functionality.  There isn't one yet.

Arabic Shaping

Arabic shaping is another one of those topics about which I know almost nothing, but, here's the highlights.

The same Arabic letter can have a different glyph depending on where it appears in a word.  If it appears in the middle of a word, the glyph should join smoothly to its neighboring letters, like English cursive letters.  If it appears at the beginning or end of a word it has a different form.  And it might also look different when it is a single letter not in a word.


Some new terminal emulators are smart enough to do this shaping for you. If it detects an Arabic letter in the middle of a work, it uses the correct glyph.  But if you've asked your terminal to *not* help with bidirectionalization so that the behavior of the ncurses screen locations is still predictable, it is still going to do Arabic letter shaping for you?  I don't know.  It is a mess.

There are other complications.  There are Unicode controls that exist to encourage characters to be joined (ZWJ, for example) or to discourage it (ZWNJ).

In any case, if you need to do shaping manually instead of leaving it to your terminal emulator, again GNU FriBiDi is your goto library for this.  And someone needs to package that for Guile, too.

Line Length and Line Breaking

OK.  You have your string.  It is NFC, untabified, has no nasty control characters in it, and you've decided upon some strategy for bidirectional text.  Next up, we need to figure out how much screen real estate each string takes up, and whether the lines need to be wrapped.

For console programs, each character takes up zero, one, or two cells. Latin letters usually take one cell. Chinese, Japanese, and Korean letters usually take two, as in the following pic.



So how do you tell how many cells a glyph is going to take?  Basically the C library function wcwidth is the basis for this.  It will tell you if a codepoint has a glyph that takes up one cell or two.  Unicode has their own explanation over here: http://unicode.org/reports/tr11/

Guile needs a function to compute the screen width of a line of text.  I like u32_strwidth from GNU Libunistring, and that's a function that needs to be made available to Guile, too.

But this also has some problems.  Some characters have a width that is ambiguous, and should be 2 cells on a screen that mostly consists of CJK text, or should be 1 on a screen that mostly consists of Latin text.  Some example ambiguous width characters are some punctuation or math symbols.  Not all terminals agree on what to do about ambiguous width characters. But I'm not going to solve this problem.

But once one knows how many screen cells a line of text is going to take, it would seem fairly easy to then construct a line-breaking algorithm.  Line breaks need to be put in at all the explicit line breaks of the five line breaking characters CR, LF, NEL, PS, and LS. Remember that CR+LF counts as just a single line break.  And then lines that exceed a desired number of columns need to be broken at plausible locations at the end of words.

There are some other complications.  There are some Unicode characters that are there to prevent line breaking or encourage line breaking: various hyphens, soft hyphens, double hyphens, word joiners.

Hopefully this convinces you that line breaking is not really something you should treat casually.    See Unicode TR #14 for its generic line breaking algorithm.  It is actually quite complex.  In any case, I'm not going to engineer a console line-wrapping algorithm.  I like the one in GNU Libunistring called u32_width_linebreaks() described here. And, again, this isn't available to Guile yet, so I need to package that, too.

But if there were such a function, it would take a string and break it into a list of strings, where each element of the list had one screen line of text.

Alignment and Padding

Alright, now we're at the end of this process.  The last step is padding the string to get the desired alignment.

The default alignment for Latin console text should be to have an aligned left margin and a ragged right margin.  For RTL text is should be to have an aligned right margin and a ragged left margin.  So you need a function that tries to determine the general directionality of a paragraph.

If you want a paragraph of text to be right-aligned or center-aligned, you need to pad the strings on the left with spaces.  To know how many spaces to pad a line, you need to know how many cells a line occupies on the screen.  Again it all goes back to wcwidth and  u32_strwidth as described above.

Next

So I'll come back when I have all the above functionality in some library somewhere, and we'll finally be ready to put some green text in a green box.