Reply to topic

Within Konsole, sudo vim doesn't show proper coloring

Adriano M
Registered Member
Posts
13
Karma
0
OS
Hey there KDE users.

I'm currently experiencing a minor problem.

Every time I use vim within sudo and Konsole, the coloring seems to switch to bright backgrounds, but without a white background. Or else some kind of alternative coloring. NOTE that it still uses the same color scheme, but instead of cyan it uses blue, and so on.

This puzzles me because everything else works as is intended for. Editing with su or with my own user works normally (in Konsole). Xterm and the Virtual Consoles out of the X sessions displays proper colors even with sudo.

Also, this only seems to affect vim, within konsole and with sudo. Tryed to rum some color table script, and it renders properly in any case.

By digging this up, I found that If I switch the TERM variable from xterm to linux, vim within sudo and konsole will render the correct colors.

As the say, a single picture equals a million words:

Image

Image

Anyone else with the same behaviour?
User avatar bcooksley
Administrator
Posts
19763
Karma
87
OS
This is probably caused by "sudo" clearing environment variables and resetting them back to defaults.


KDE Sysadmin
[img]http://forum.kde.org/content/bcooksley_sig.png[/img]
Adriano M
Registered Member
Posts
13
Karma
0
OS
Well, sudo echo $TERM returns the same value that was set before issuing it.

But what makes me think that something is wrong in Konsole, is that it only happens with it! I can't reproduce it anywhere else.
pansz
Registered Member
Posts
113
Karma
0
OS
don't know why you say this only happens with konsole.

Do you have xterm? (type Alt-F2 then you got krunner, launch the app named xterm)

do you mean sudo vim foobar works without problem in xterm?

or do you have gnome-terminal or xfce4-terminal to try in?
User avatar bcooksley
Administrator
Posts
19763
Karma
87
OS
"sudo echo $TERM" will produce the same result because your current shell will resolve $TERM before executing the command.

"sudo export | grep TERM" will show the correct results.


KDE Sysadmin
[img]http://forum.kde.org/content/bcooksley_sig.png[/img]
Adriano M
Registered Member
Posts
13
Karma
0
OS
oddly enough, I can't do export in sudo!

$sudo export
sudo: export: command not found

but I can use env:

$sudo env | grep TERM
TERM=xterm
$TERM=linux
$sudo env | grep TERM
TERM=linux

This is getting somewhat distant to konsole itself, and many of my own information are dubious or misleading.

So, let's start this again. There is something strange by the way Konsole (or something else) handles which color to use. Let's for now, forget about sudo too.

It seems that the color pallete is divided into two parts, the intense colors and the normal ones. From what I am seeing now, the TERM can instruct applications to use one or another "set" of colors.

If I'm right, TERM=xterm is inteded for the normal colors, and TERM=linux is suposed to indicate Intense colors.

As vim is the only program that is consistently keeping track of this input, I will do my "benchmark" with it.

Gnome-terminal:
TERM=xterm
vim uses the normal colors
TERM=linux
vim uses the intense colors


Xterm:
TERM=xterm
vim uses the normal colors
TERM=linux
vim uses the intense colors


Framebuffer Terminal:
TERM=xterm
vim uses the normal colors
TERM=linux
vim uses the intese colors

Up to this point everything is consistent :P

Konsole:
TERM=xterm
vim uses the intense colors
TERM=linux
vim uses the intense colors

Konsole with bright theme/background + restart:
TERM=xterm
vim uses the normal colors
TERM=linux
vim uses the intense colors

Konsole changed back to dark theme,but WITHOUT restart:
TERM=xterm
vim uses the normal colors
TERM=linux
vim uses the intense colors

What puzzles me is that, this may not be a bug at all. I like the intense colors (mainly because I use dark backgrounds) and this could be some nice hack or something else built into the terminal emulator.

Now... what I don't like is that this comes with some quirks (as seem in the "benchmark") and konsole + sudo won't somehow propagate it (which is the whole point of this topic!)

I would appreciate if you all could verify this kind of behaviour. In the end this could be a bug.
pansz
Registered Member
Posts
113
Karma
0
OS
I cannot reproduce your "bug" in my Kubuntu9.10+KDE4.3 and Arch+KDE4.3. (Arch by default clears the environment, Kubuntu don't, which is more a distribution-specific issue than the KDE issue)

I always get the so called "intense" colors. If all you want is to use vim. then I've got some suggestions:

1. try set background=dark then set t_Co=8 or t_Co=16 or t_Co=256 in your ~/.vimrc, which should work for most cases.
i.e. If you had hard-coded your background and t_Co (try 3 color options and one of them should work) in your .vimrc then there won't be any further problem. (just make sure sudo uses the same .vimrc)

2. try use sudo -e foobar instead of sudo vi foobar, the previous version uses the normal user to edit the file.
Coolmax
Registered Member
Posts
4
Karma
0
OS
Hi all,
I've got openSUSE 11.2, KDE v. 4.3.5 (Konsole v. 2.3.1) and I can reproduce this bug. Are there any solutions?

 
Reply to topic

Bookmarks



Who is online

Registered users: Baidu [Spider], bartoloni, Bing [Bot], boudewijn, Google [Bot], gui-m, ipwizard, jbutcher, Majestic-12 [Bot], skylerjett, Sogou [Bot], YaCy [Bot]