Wednesday 13 March 2019

character encoding - Why don't ANSI symbols work in PuTTY/Debian?


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:



├── coffee-script@1.2.0
├─┬ eco@1.1.0-rc-3
│ └── strscan@1.0.1
├─┬ express@2.5.5
│ ├─┬ connect@1.8.5
│ │ └── formidable@1.0.8
│ ├── mime@1.2.4
│ ├── mkdirp@0.0.7
│ └── qs@0.4.0
...

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

Answer



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.)


No comments:

Post a Comment

How can I VLOOKUP in multiple Excel documents?

I am trying to VLOOKUP reference data with around 400 seperate Excel files. Is it possible to do this in a quick way rather than doing it m...