A UTF-8 Console
A few people have asked about this in ##slackware lately so
I thought I'd put down a few notes on how I got UTF-8 up and
running. This howto applies to Slackware but you should be
able to follow these directions on any *nix with a few path
adjustments.
In these days of high powered X desktop environments with
all their flashy bells and whistles it may seem strange to
worry about how the plain Linux console behaves outside of
X, but we need to remember that there are some very nice
applications that live in the console and can be just as (or
even more) productive than the X Windows counterparts. I'm
thinking of screen, irssi, mutt, (e)links, lynx, vim/vi,
mplayer (using svga), zgv and slrn to name but a few. Some
linux folks like to use the console permanently and only
delve into X for the rare occasions when they need to.
The Kernel
The first thing to do is configure the kernel so that it
creates a UTF-8 enabled console at boot. There is a kernel
parameter we can add to /etc/lilo.conf to do this:
append=" vt.default_utf8=1"
In fact, when you install slackware you are asked if you
want a unicode enabled terminal, and if you confirm then
this is the line that gets added to lilo.conf at the top.
This makes it a global setting.
Here's an example from mine for a single boot entry:
# Linux bootable partition config begins
image = /boot/vmlinuz-4.18.5-custom
root = /dev/hda1
label = Linux-custom
append="vt.default_utf8=1"
read-only
# Linux bootable partition config ends
Once you have saved lilo.conf and ran 'lilo', a reboot is
needed.
For grub, append the parameter to the end of the kernel line
in grub.conf or menu.lst
Fonts
After that we need to find a font that actually contains the
characters you want to see. My 'font of the moment' is
lat9w-16 (actually now Terminus since writing the original
version of this howto.) This contains the British £ (pound)
and € (euro) symbols that I need, plus a lot of useful
accented characters. It is also important to have the
correct drawing characters so that curses programs like
pkgtool and sbopkg are printed on the screen correctly. If
you experiment with the setconsolefont command you
will find that some fonts draw curses box borders as squares
or question marks, so check out some fonts and see which
ones work and which don't. The setconsolefont
command will put your chosen font into /etc/rc.d/rc.font so
it will load at bootup.
Keyboard
Ok, great you can now see characters correctly, but you need
the correct keymap to be able to type them. That's a little
harder. If you can find a UTF-8 keymap for your
locale/hardware then that's fine. Personally I didn't find
any of the installed keymaps suitable so I looked around for
an alternative. I found a uk-utf8 keymap on the intertubes,
but this was unfortunately missing all the Ctrl+[a-z] keys
so I edited it and added my own. I also added some
AltGr+[a-z] for accented and other characters. You may find
this keymap useful as a starting point to create your own if
you cannot find a more suitable one. Have a look through
the comments and the codes and you should pick up the
method. To add your own combinations you will need to know
the correct codes for the characters you need. You can find
a table of UTF-8 characters here:
http://unicode-table.com" title="http://unicode-table.com">http://unicode-table.com">http://unicode-table.com">http://unicode-table.com
Look up the ascii code in that table and convert it to hex.
E.G. è is 232 in decimal, E8 in hex; é is ascii 233 in
decimal, E9 in hex, so the entry in your keymap for 'e'
would be:
# key normal shifted AltGr+e AltGr+shift+e
keycode 18 = e E U+00E8 U+00E9
# prints: e E è é
You can find the keycodes with the 'showkey' program. Once
edited you can load the map with 'loadkeys'. Loadkeys will
update /etc/rc.d/rc.keymap but you will need to copy the
keymap to /usr/share/kbd/keymaps/i386/qwerty/ so it is
accessible during bootup (assuming you are using a qwerty
keymap).You can load this ungzipped but it's better to gzip
it back after editing to keep things consistent.
Conclusion
By now you should have a fully usable keyboard/console
correctly printing unicode characters. You will probably
need to tell some programs like mutt and irrsi that you are
using a UTF-8 system.
Note: There exist two shell scripts - 'unicode_start' and
'unicode_stop'. Typing 'unicode_start <font>' will
load the required font and set up keyboard correctly for
unicode input. You can add the command to your rc.local to
activate it on boot.
|