Friday, February 6, 2015

Cerberus Alpha: Tuning the program for the OS

The first challenge that I ran into was with the nifty little line drawing characters that I used to make the menu boxes look nice. Writing the program for the first time I copied the box drawing characters off of the wikipedia page about them. This worked fine in testing, but when running the program for the first time in Tiny Core the boxes looked like fuzz and when editing the program it was like garbled text. It turns out that the terminal emulator (aterm) that runs from the desktop in Tiny Core does not support the UTF-8 characters I was using. I found a workaround that looks like this:

echo -e "\e(0lqqqqqqqqqqq\e(BMenu:\e(0qqqqqqqqqqqqqqqqk\e(B"
echo -e "\e(0x\e(B Enter 1: Simple Install        \e(0x\e(B"
echo -e "\e(0x\e(B Enter 2: Full Install          \e(0x\e(B"
echo -e "\e(0x\e(B Enter 3: Simple Uninstall      \e(0x\e(B"
echo -e "\e(0x\e(B Enter 4: Thorough Uninstall    \e(0x\e(B"
echo -e "\e(0x\e(B Enter q: to quit to terminal   \e(0x\e(B"
echo -e "\e(0x\e(B Enter r: to reboot             \e(0x\e(B"
echo -e "\e(0mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj\e(B"
Although it looks a bit like crap in the code, it did actually render very well when running. It uses the escape character \e(0 to begin inputting text in alternate characters and \e(B to end this input mode. This change worked for the terminal emulator aterm, but later on when I was running the program from the command line without X the problem reared its ugly head again. I reverted the menu section code back to what it was originally (actually I rewrote it a bit more carefully) and once again it gave the desired printout. Technically, if you rerun the program from aterm it will still give ugly looking output. Hopefully at some point I will get around to writing a check for what environment the program is running from to fix this issue. Here is what the menu looks like, at least when it works right:

┌───────────Menu:────────────────┐
│ Enter 1: Simple Install        │
│ Enter 2: Full Install          │
│ Enter 3: Simple Uninstall      │
│ Enter 4: Thorough Uninstall    │
│ Enter 5: Replace sethc instead │
│ Enter q: to quit to terminal   │
│ Enter r: to reboot             │
└────────────────────────────────┘
You might by now notice the "replace sethc instead" option in the program has no "uninstall" function. This was intended for Windows XP as an alternate method. It works, but there are already much better programs out there designed to do the same thing for XP. It could be used as a last resort for Windows 8 too though, so I will try to get around to adding the option to undo it.

No comments:

Post a Comment