Saturday, 5 June 2010

Recipe: A decent terminal emulator for Windows

After having been spoilt by the luxury of a using a proper terminal daily for several years I am now forced back into the world of Windows, and cmd.exe or the abomination knows as Windows Console. I'm not sure how the team that wrote cmd.exe/console.exe could actually continue to release the application in good faith (no auto-select by default, then when you do enable it all you get is block select - seriously, wtf?), but anyway, it's not worth pointing out its many deficiences when time is better spent getting a superior alternative set up.

Ingredients:
  • Cygwin, for unix commands in windows (ls, ps, grep, sed, awk, xargs, find, ssh, wget, cat, less, ...) along with your flavour of competent shell (e.g. bash, zsh, etc).
  • puttycyg, for the terminal emulator itself. This is a patch over regular PuTTY that provides an additional connection option of a loopback interface ("Cygterm") to a local cygwin installation. So you get a decent configureable terminal in PuTTY, useable not only for remote connections but as a local terminal emulator for your favourite shell on your local Windows machine.
  • Optionally (but highly recommended), PuTTY Connection Manager (puttycm) for a pretty decent multi-tab wrapper around all your PuTTY instances, along with configureable keyboard shortcuts for creating new tabs/sessions and navigating between sessions (no more shift?-alt-tab/taskbar clutter nonsense).
  • Another optional is some proper fonts (i.e. not Courier *), for example: Liberation, Bitstream Vera, Inconsolata, Proggy, or any number of other high-quality programmer fonts that double up as decent terminal fonts. As a previous fan of Bitstream Vera Sans, after having worked in Windows for about a month now and discovering Consolas as a default-installed font of Office 2007, this has now become my primary choice and I would highly recommend it to others going forward. For some reason Microsoft continue to do pretty well in secondary areas, e.g. hardware/typography but poorly in their primary software capacity (hmm perhaps they're not too dissimilar to Apple after all -- or should that comparison be the other way round?).

Method:
  1. Install all the various applications and fonts you wish, and configure your PuTTY sessions as normal (Puttycyg will also pick up any preexisting PuTTY sessions you had created however). In order to create a new local Cygwin interface, simply create a new session with "Connection type" set to the (newly-available) option of "Cygterm" and specify the "Host Name/IP address" as a single dash (-) which instructs puttycyg to use your default shell.
  2. If working with more than one Cygwin installation the only consideration you'll need to have when using puttycyg is you'll need to start it in the working directory of the /cygwin/bin/ installation you want to use - so any shortcuts you create for the terminal be sure to modify the "working directory" accordingly (puttycyg does include a cygwin auto-detection method however which should be sufficient for single cygwin installations).
  3. You may also want to auto-load your local cygwin session in your shortcut (e.g. for a single-click terminal launch, or easy access via a launcher such as Launchy), in which case you simply need to add "-load [cygterm-session-name]" to your shortcut's target command line. 
  4. If using zsh and Windows 7/Vista you may experience some irritating errors when starting the shell or executing commands; they are usuall some variety of "fatal error - unable to remap ...\zsh\*.dll to same address as parent(0x...)". There is thankfully a simple solution to this:
  • ensure you have the "rebase" package installed in your cygwin instance
  • execute "${CYGWIN_HOME}/bin/ash.exe"
  • $ rebaseall
  • Relaunch your Cygwin instances.
As an added bonus, the following are RGB listings for the excellent "Dark Pastels" colour scheme that Konsole provides out of the box that you can use in your PuTTY sessions (also cmd.exe if you so wish) for even better looking terminals:

Colour                      RGB Values

Default Foreground          R:220, G:220, B:205
Default Bold Foreground     R:220, G:220, B:205

Default Background          R:44, G:44, B:44
Default Bold Background     R:44, G:44, B:44

ANSI Black                  R:63, G:63, B:63
ANSI Black Bold             R:112, G:144, B:128

ANSI Red                    R:112, G:80, B:80
ANSI Red Bold               R:220, G:163, B:163

ANSI Green                  R:96, G:180, B:138
ANSI Green Bold             R:114, G:213, B:162

ANSI Yellow                 R:223, G:175, B:143
ANSI Yellow Bold            R:240, G:223, B:175

ANSI Blue                   R:154, G:185, B:215
ANSI Blue Bold              R:148, G:192, B:243

ANSI Magenta                R:220, G:140, B:196
ANSI Magenta Bold           R:236, G:147, B:213

ANSI Cyan                   R:140, G:209, B:211
ANSI Cyan Bold              R:147, G:225, B:227

ANSI White                  R:220, G:220, B:205
ANSI White Bold             R:255, G:255, B:255

So, that's my recipe on how to get a decent local terminal emulator + shell set up in Windows. Please leave a comment with suggestions for alternatives or improvements if you have any; while the above is a significant improvement over the default cmd.exe behaviour it's still a way off a comparable Linux setup these days.

Saturday, 8 May 2010

Death to Caps Lock: Addendum

Just a small update in my quest to kill off the caps lock key;

I've recently started a new job where everything is as locked down as it could be, meaning I'm restricted to a user-level account on Windows XP. After being so used to using caps lock as control I have now often been inadvertently replacing blocks of text with capital X or C while attempting to cut or copy.

So, after being frustrated enough to do something about it I tried my earlier recommended solution of using SharpKeys to perform the remapping, however I then discovered that SharpKeys currently only allows performing a global remapping meaning you need to be an administrator to perform it.

After a bit of googling I then thankfully discovered there is a way to perform the same remapping on a per-user basis, i.e. writing to HKEY_CURRENT_USER rather than HKEY_LOCAL_MACHINE.

While it should be possible to add this functionality to SharpKeys now that the source code is available I however needed a quicker solution, so just manually updated the registry. The following is a .reg file that you can use to perform this local remapping; all this particular entry will do is simply remap caps lock to left control and nothing more:
Windows Registry Editor Version 5.00 

[HKEY_CURRENT_USER\Keyboard Layout] 
"Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,1d,00,3a,00,00,00,00,00
Be sure to log out and log back in to have it applied!

In the interests of completeness the following is a .reg file that can revert the remapping changes by simply removing the key:
Windows Registry Editor Version 5.00 

[HKEY_CURRENT_USER\Keyboard Layout] 
"Scancode Map"=-

Sunday, 6 December 2009

Astronomy Picture of the Day


This is just a quick plug for a site I believe more people should be aware of... </disclaimer>
For those looking for some astronomical inspiration, or who just plain appreciate beautiful images of the cosmos, I'd highly recommend subscribing to Astronomy Picture of the Day, where you can find some spectacular images such as the one to the left.

Saturday, 1 August 2009

Tab to all form controls in OS X

Just recently found out how to fix a small annoyance I've had with OS X since day 1, and thought I'd share. By default when you're in a form, tabbing between controls, OS X limits the tabbing to text-like boxes, so elements such as checkboxes and submit buttons are skipped. This is unfortunately not the same behaviour as Linux (KDE at least) and Windows, so for those who come to OS X after another OS may find it frustrating to discover this fact, as I have.

The fix is trivial, and as always Apple provide the UI to do it for you (I should have looked harder to find it in the first place!):

System Preferences -> Keyboard & Mouse -> open the Keyboard Shortcuts tab.

At the bottom of the page there is an option, Full Keyboard Access. All you need do is switch the option to All controls from the default "Text boxes and lists only".

Done!

Sunday, 7 June 2009

Death to Caps Lock



Even though it is cruise control for cool, personally I think it is the number one most useless key on modern keyboards. "Why not Scroll Lock or Pause/Break?" you may ask; well, you see, the Caps Lock key is in a fantastic position - usually directly next to the home row, and as large if not larger than a Control key. That position could be used for much more useful keys; for example in the case of programming or general UNIX-usage, Control. On OS X the Command (Apple) key is perhaps a better candidate, due to the preference of Command over Control for general OS and application shortcuts. Scroll Lock and Pause/Break are simply too small and too far away to be annoying, as useless as they may be.

If you've yet to try remap your Caps Lock key, I would highly recommend it. Once you get used to having the convenience of a Control or Command key essentially at the natural resting place of your left pinky you really cannot live without it. Productivity is greatly improved when you're able to copy/paste or save files or close applications or terminate commands or logout or an infinity of other commands depending on what apps you use in the blink of an eye, without scrunching your hand and probably giving yourself huge cause for RSI in the future.

The problem is, how do you actually go about remapping your Caps Lock key? Google gives thousands of results on the subject but they're usually fragmented by operating system and have a tendency to get outdated with alarming regularity. So here I hope to document the procedure for several major operating systems in a single place, for as much my own reference as anyone else's. Without further ado:

OS X

Very simple; open System Preferences and go to Keyboard & Mouse. On the Keyboard tab, click the Modifier Keys... button. This pops up a simple dialog allowing you to remap all your modifier keys; in the case of Caps Lock this is easily changed to Command or Control, depending on your preference. Changes should take effect immediately.

Windows

Short of manually hacking scan codes in the registry you're going to need a third-party application to do the job. One such app that I've been using for years now is the excellent SharpKeys by Randy. Another such tool is KeyTweak, although I've yet to use it so can't comment. All these tools are essentially pretty frontends to the magical HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout registry key that controls how raw key codes are mapped to actually key presses in Windows.

In SharpKeys you can simply add a mapping from Special: Caps Lock to Special: Left Ctrl (you can press Type Key when adding a mapping to simply press the keys you want to map without hunting for them in the huge list of keys), and click Write to Registry to save the changes. You'll need to logout and back in for the changes to be registered.

UNIX derivatives (Linux/BSD)

The method for accomplishing the mapping in virtual terminals (i.e. non-X modes) is specific to individual distributions so I'll only cover the ones I currently use here, which are Ubuntu and FreeBSD. For X use, with a modern Xorg installation that uses HAL the process is the same no matter what the distribution -- in this case both of Ubuntu 9.04 (Jaunty Jackalope) and FreeBSD 7.x. Your distro/window manager of choice might include a pretty GUI frontend to accomplish a similar task, which I won't cover here. The methods I use are to ensure that no matter how I use a machine the keys are consistently mapped; both in X (regardless of window manager) and on regular virtual terminals, regardless of which user I'm logged in as at the time.

X.Org X11

As of X.Org release 7.3, the HAL system is used to provide hotplug support of input devices. The (at first) frustrating consequence is all your preexisting InputDevice sections in xorg.conf are not used, so the old way of adding an Option "XkbOptions" "ctrl:nocaps" line to an InputDevice keyboard section will not work (well, there is a way to get it to work in the old style, but this method may not be around for much longer so it's not advisable to use it).

The new way is to use a HAL policy to match any keyboards that get plugged in and perform the remapping there. The old X11-style options are carried over almost verbatim so the names and values of such a policy should be familiar, even though it's now an XML configuration file.

Create a file with extension .fdi in /etc/hal/fdi/policy (/usr/local/etc/hal/fdi/policy on FreeBSD) with the following contents:


<?xml version="1.0" encoding="UTF-8"?>
<deviceinfo version="0.2">
<device>
<match key="info.capabilities" contains="input.keyboard">
<merge key="input.xkb.Options" type="string">ctrl:nocaps</merge>
</match>
</device>
</deviceinfo>


If the above doesn't work after a HAL restart you can also try input.x11_options.XkbOptions instead of input.xkb.Options, which allows you to directly pass old-style X11 options through.

On FreeBSD you'll also need to ensure HAL and DBUS are running in order for this method to work.

Here's a post on the Ubuntu forums with further discussion on the issue.

Ubuntu Virtual Terminals
As described in this bug the process is pretty simple. All you need to do is add the following line to /etc/default/console-setup:

XKBOPTIONS="ctrl:nocaps"

then do a

# dpkg-reconfigure console-setup

to persist the change.

You're also able to directly hack /etc/console-setup/boottime.kmap.gz to perform whatever additional mapping you may require, although for mapping caps lock to control the above method is far easier & safer.

FreeBSD Virtual Terminals

Several keymappings are available by default in /usr/share/syscons/keymaps; in the case of the US and UK layouts versions already exist that have caps lock mapped as the left control key. To use for example the UK layout it's as simple as adding the following line to /etc/rc.conf

keymap='uk.iso-ctrl.kbd'

and rebooting for the change to take effect.

If no such preconfigured layout exists for your language/setup then it's easy enough to copy one of the preexisting layouts and simply change the Clock mapping to that of Control (while maintaining character codes!), then change the above keymap setting to point to your new layout.

Fix Explorer's annoying habit of forgetting folder view settings in Vista

If you know what I'm talking about in the title then you'll find this a godsend. This was the single most annoying feature with Vista, which is saying something considering the only reason I use it is for occasional gaming. What possessed Microsoft to think releasing a major new version of Windows with this issue intact was acceptable I'll never know, but at last I have been able to get Explorer to display things how I want them to be displayed, not how Microsoft "recommends" your folders should be displayed.

Monday, 4 May 2009

Casual games: LostWinds

If you have access to a Wii and its WiiWare application download service, I would highly recommend you take a look at LostWinds (MetaCritic ranking).

This post is almost a year late (the game was released on the 20th May 2008) however I am slowly trying to backtrack on all the great indie games I've played over the previous months and make sure I've blogged about the ones that truly stand out. LostWinds is one such game.

Triple-A games on the Wii are still to this day struggling to find a natural use of the motion controls; most games end up feeling gimmicky in their inputs and a lot of the time you don't even need any waggle-power to play a game; you can simply revert to a (natural) standard controller layout. Don't get me wrong; the motion controls work fantastic in party games (and a couple of first-party titles), but there are only so many party games you can play before minigame madness turns into actual insanity. As a somewhat die-hard gamer I enjoy playing all types of games, and have always had a soft spot for platformers. Some of my first gaming experiences as a child were with Super Mario Brothers and Sonic, so the genre does hold quite large sway over me. </disclaimer>...

So LostWinds is a 2D platformer, basically, with quite a few puzzle elements in it. You control Toku, a cute little guy whose job it is is to save the world, or, rather:
release the curse placed upon the world of Mistralis by evil Balasar
Yeah, alright, we've heard this plotline a million times over now; the main innovation here comes in two main areas: controls and art/atmosphere.

About the controls:

You play the game using the wiimote + nunchuck, with the nunchuck hat controlling L/R movement and the wiimote controlling jumping. And by "controlling jumping" I literally mean controlling -- whilst holding in the jump button you're able to flick the wiimote to define a path for Toku to jump along. You don't however control Toku directly; the wiimote cursor happens to be a wind spirit, so these defined paths are instead gusts of wind that help Toku along his jumps.

Jumping is not the only thing that these wind-spirit gusts are useful for (I'll refrain from the obvious joke ;-). Water and fire play a large part in the game, and being in control of wind you're able to create plumes of water or fire to douse or burn things along your way. For example, you're able to flick some water out of a stream onto a plant to help it grow, allowing you to access higher areas, or flick a burning torch so that the fire is directed onto a route-blocking thornbush, freeing access beyond it.

As you progress through the game your wind spirit is granted more and more powers; an example of an early such power is a second powered gust (meaning you can double jump, or route water/fire around corners...). There's a lot of potential for this in other games; I certainly hope other developers take heed of such functionality. Instead of having the wiimote as a simple controller of your avatar, the cursor becomes an avatar in its own right, helping the protagonist along his or her way.

About the art:

Whilst a 2D platformer in nature the world is rendered in full 3D with a fixed front-facing camera, so some gorgeous backgrounds are on display. The art style is very wispy and cheerful, as you can see from the above screenshot; artistic license is taken in this regard so style and theme trump realism and accuracy. With the million-odd WWII/zombie/generic-futuristic-shooter games out there striving for Zomg Realistic! (tm) graphics games such as LostWinds which break this mould are hugely welcome. It's also a showcase of the fact that the Wii need not neccessarily be a slouch when it comes to beautiful 3D; it may not be a powerhouse but if done right games on it can look a damn sight better than many others on more hardcore machines.

The whole wind theme plays beautifully with the backgrounds; as you create gusts of wind you innevitably end up disturbing the leaves of a tree or blades of grass, or even shrubbery. Everything reacts naturally and for a large part of the game you'll find yourself sitting in one area blowing things around, admiring the background beauty, forgetting about who you're supposed to speak to next or where you're supposed to travel to.

In terms of the the actual platforming, one of the great things about LostWinds is that there is no real linear progression. The world you start out in is the world you finish in; there are a couple of distinct areas that are loaded separately (unfortunately it's not totally seamless, which admittedly is probably a hardware constraint but server as useful demarkation when you're trying to remember where to go) but for the most part you're simply not able to access all available levels in each section when you start out.

As you progress through the game and your wind spirit gains more powers you're able to reach previously unreachable platforms or open previously unopenable barriers, which lead to new subterranean or tree-/roof-top ledges in areas that you've already been. This forms a large part of the puzzle aspect; you end up backtracking a hell of a lot in order to find that one ledge you couldn't quite jump to the first time you came to it, or to that door you couldn't get past previously. And as there is no map to speak of you end up having to memorise the layout of the entire world and keep a sharp eye out for locations you haven't been to yet in order to avoid running around from end to end along the same path you've already been. Challenging, but fun (although sometimes it does border on the side of outright frustrating if you miss an area...).

Of course it is a WiiWare title so it's not exactly massive; you're able to finish the whole thing in a couple of hours so not too much memorisation is required, thankfully. Ultimately it's a very peaceful game, almost zen-like; if you're looking for something quite challening whilst simultaneously relaxing then this is something you should definitely check out. If you're looking for an innovative puzzler platformer then I'd also recommend checking it out.

Either way there's little in the game that's going to dissapoint.