6

The awesome application tree, which I installed in Debian with apt-get install tree, has the option of drawing its output using ANSI graphics. Its output looks like this now:

.
tqq node_modules
x   tqq coffee-script
x   tqq eco
x   tqq express
x   tqq forever
x   mqq stylus
tqq package.json
mqq src
    mqq daemontest.coffee

This is obviously wrong. These are my LANG=en_GB.UTF-8 UTF-8 and LC_ALL=C env variables. PuTTY is set to expect UTF-8 as well. If I change PuTTY to "Use font encoding" then tree -A looks right, however npm list will then break and look like this:

├── [email protected]
├─┬ [email protected]
│ └── [email protected]
├─┬ [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ └── [email protected]
...

All of this stuff should work correctly, so I'm guessing my settings are wrong somewhere. Could anyone help me tune in on exactly where?


EDIT: My env now looks like this. Problem is still there

root@chu:~# env
TERM=putty
SHELL=/bin/bash
SSH_CLIENT=**Censored**
SSH_TTY=/dev/pts/1
USER=root
LS_COLORS=rs=**Removed because wall of text**
PYTHONBREW_ROOT=/usr/local/pythonbrew
MAIL=/var/mail/root
PATH=/usr/local/pythonbrew/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/root
LANG=en_GB.UTF-8
SHLVL=1
HOME=/root
LANGUAGE=en_US:en
LS_OPTIONS=--color=auto
PYTHONPATH=:/root/pymodules
LOGNAME=root
SSH_CONNECTION=**Censored**
_=/usr/bin/env
mfg
  • 627
  • 2
  • 8
  • 27
Hubro
  • 5,716
  • 14
  • 61
  • 87

1 Answers1

10

The first problem is that you have $LC_ALL set to C. If you set $LC_ALL, it will override all other locale settings, including $LANG. Since the "C" locale uses ISO-8859-1, tree will not know about Unicode availability and will attempt to switch to the VT100 graphics codepage (there are four switchable codepages), which PuTTY refuses to do when expecting UTF-8. To fix this, stop setting LC_ALL in your environ and tree will use Unicode graphics.

The second problem is that your $LANG variable is incorrect – you don't need to specify the charset twice. Set LANG=en_GB.UTF-8 to fix this.

The third problem is that you are forcing tree to use VT100 graphics. Do not use the -A option.

Keep PuTTY configured for UTF-8 as well.

(npm is unaffected by this because it is hardcoded to use Unicode graphics regardless of locale.)

u1686_grawity
  • 426,297
  • 64
  • 894
  • 966
  • Hey thanks for a brilliant answer, but I have a few problems with it. First of all, I've never touched the LC_ALL or LANG variables. I don't know where they're set and I don't know how to unset them or change them. Could you elaborate just a bit on that? Thanks! – Hubro Jan 13 '12 at 20:34
  • @Codemonkey: Check your shell startup scripts first. If you are using *bash*, then `grep LC_ALL ~/.profile ~/.bash_profile ~/.bash_login ~/.bashrc /etc/profile /etc/profile.d/* /etc/*bashrc /etc/environ* /etc/default/locale` -- copy/paste that :) – u1686_grawity Jan 13 '12 at 20:39
  • Yeah I found the LC_ALL declaration as well at the LANG one. I removed the LC_ALL and edited LANG. The env output is edited into my question, because tree still just writes "tqq" and "mqq" instead of ANSI graphics – Hubro Jan 13 '12 at 20:41
  • @Codemonkey: 1) Are you running `tree` or `tree -A`? Do *not* use the ANSI mode; just run `tree` and let it use Unicode instead. 2) Does `locale -a` show `en_GB.UTF-8` in the list? – u1686_grawity Jan 13 '12 at 20:58
  • `locale -a`: http://pastebin.com/Kzttvgm2. But why can't I use the ANSI characters? `npm` can use them, why can't tree? – Hubro Jan 14 '12 at 01:52
  • @Codemonkey: You need to generate the locale data, then; in Debian `sudo dpkg-reconfigure locales` should work, or you can manually uncomment the "`en_GB.UTF-8 UTF-8`" line in /etc/locale.gen, then run `sudo locale-gen`. And like I already said: **`npm` does *not* use ANSI graphics. It uses their Unicode (UTF-8) equivalents, and only that.** – u1686_grawity Jan 14 '12 at 03:38
  • Note that PuTTY is somewhat unusual in not supporting the [ANSI/VT100 graphics in UTF-8 mode](http://www.chiark.greenend.org.uk/~sgtatham/putty/wishlist/utf8-plus-vt100.html). Xterm and others such as Cygwin's mintty do support both at the same time. – ak2 Jan 14 '12 at 10:16
  • So to summarize, the problem is with `tree` because it can't display UTF-8 ANSI-looking graphics like `npm` can? – Hubro Jan 14 '12 at 18:14
  • @Codemonkey: `tree` *can* display UTF-8 graphics, but you're telling it not to. **1)** Make sure you have your locale settings correct; "`locale -a`" must have `en_GB.utf8` in the list. **2)** Set your $LANG to `en_GB.UTF-8`. (Yes, $LANG must end with `UTF-8`, not `utf8`.) **3)** Do *not* run "`tree -A`"; just "`tree`" will suffice. – u1686_grawity Jan 14 '12 at 18:18
  • Here is my working setup: http://sprunge.us/VSSc – u1686_grawity Jan 14 '12 at 18:25
  • [Here is my not working setup](http://pastebin.com/g5nb5qWF). Technically all your requirements are being met, but I do have some errors popping up. Notice that `tree` is using ASCII symbols only, not pretty UTF-8 graphics. Can you see why? – Hubro Jan 14 '12 at 18:36
  • @Codemonkey: The errors are saying that `en_GB.UTF-8` *does not exist* on your system. I already told you how to add it -- either a) run `sudo dpkg-reconfigure locales` and enable the locale, or b) manually edit `/etc/locale.gen`, uncomment the required line, then run `sudo locale-gen`. – u1686_grawity Jan 14 '12 at 18:49
  • Oh god, my bad. I thought I had already done that, but I had the en_US locale installed, not the en_GB. It works now. Thanks a lot for your help – Hubro Jan 14 '12 at 18:54