From Fedora Project Wiki
(20 intermediate revisions by 3 users not shown)
Line 15: Line 15:
== Current status ==
== Current status ==
* Targeted release: [[Releases/18 | Fedora 18 ]]  
* Targeted release: [[Releases/18 | Fedora 18 ]]  
* Last updated: 2012-06-16
* Last updated: 2012-08-01
* Percentage of completion: 50%
* Percentage of completion: 100%
* Tracker bug: [https://bugzilla.redhat.com/show_bug.cgi?id=849429 bz849429]
* In Fedora 18 as of [https://admin.fedoraproject.org/updates/initscripts-9.41-2.fc18 initscripts 9.41-2]


== Detailed Description ==
== Detailed Description ==
Line 41: Line 43:
== Scope ==
== Scope ==
This will be mainly configuration changes.
This will be mainly configuration changes.
I think the most easily configurable/maintainable option is to have a new '''/etc/profile.d/256color.sh''' file.
That will keep the config central, and set things up in a standard way such that LS_COLORS will
be set appropriately.


Here is my current version:
After some discussion around whether it was best to update each terminal to adjust the TERM environment variable,
or whether to have a central config file, it was initially decided to update each terminal.
But after looking more deeply into this I thought of a way to use
the simple centralized config, without causing an issue for remote
terminals logging into the system. By keying on $COLORTERM rather than $TERM
we both get accurate identification of the terminal, and
non propagation by ssh. I.E. we get to easily and centrally
configure this feature for particular terminals and
also avoid having to add config options to each terminal
some of which discourage new config options on principle.


<pre>[ "$TERM" = 'xterm' ] && TERM=xterm-256color
Here are [http://vim.wikia.com/wiki/256_colors_in_vim setting notes on setting $TERM on various terminals]:
[ "$TERM" = 'screen' ] && TERM=screen-256color
Noted there was the fact that it's not configurable in gnome-terminal (vte) yet.
[ "$TERM" = 'rxvt-unicode' ] && TERM=rxvt-unicode-256color
export TERM


if [ ! -z "$TERMCAP" ] && [ "$TERM" = "screen-256color" ]; then
There is a [https://bugzilla.redhat.com/show_bug.cgi?id=230682 related bug] to set $TERM to 'gnome' 'gnome-256color',
  TERMCAP=$(echo $TERMCAP | sed -e 's/Co#8/Co#256/g')
though we probably should stick to 'xterm' to reduce remote interop issues
  export TERMCAP
(ubuntu precise for example doesn't support TERM=gnome)
fi</pre>
 
Here are notes on the xfce bug where it doesn't set the specified TERM correctly:
http://forums.opensuse.org/english/get-technical-help-here/how-faq-forums/unreviewed-how-faq/459826-setting-term-xfce-terminal-bug-description-workaround.html
https://bugs.archlinux.org/task/21007#comment94595
 
Here is the current version of the '''/etc/profile.d/256color.sh''' file.
 
<pre># Enable 256 color capabilities for appropriate terminals
 
# Set this variable in your local shell config if you want remote
# xterms connecting to this system, to be sent 256 colors.
# This can be done in /etc/csh.cshrc, or in an earlier profile.d script.
#  SEND_256_COLORS_TO_REMOTE=1
 
# Terminals with any of the following set, support 256 colors (and are local)
local256="$COLORTERM$XTERM_VERSION$ROXTERM_ID$KONSOLE_DBUS_SESSION"
 
if [ -n "$local256" ] || [ -n "$SEND_256_COLORS_TO_REMOTE" ]; then
 
  case "$TERM" in
    'xterm') TERM=xterm-256color;;
    'screen') TERM=screen-256color;;
    'Eterm') TERM=Eterm-256color;;
  esac
  export TERM
 
  if [ -n "$TERMCAP" ] && [ "$TERM" = "screen-256color" ]; then
    TERMCAP=$(echo "$TERMCAP" | sed -e 's/Co#8/Co#256/g')
    export TERMCAP
  fi
fi
 
unset local256</pre>


As an optional additional improvement, we could adjust the 256 color values used in '''ls''' by
As an optional additional improvement, we could adjust the 256 color values used in '''ls''' by
Line 83: Line 121:
Better default colors with less tweaking required.
Better default colors with less tweaking required.


== Dependencies ==
== Dependencies / Affected packages ==
None
The following packages could be updated in order to auto enable or improve the 256 colors usage:
 
* coreutils (for the ls color schem)
* vim-common (to improve the vim color scheme)
* [[Features/256_Color_Terminals#May_auto_support_256_colors_in_future]] (to add COLORTERM to the env)


== Contingency Plan ==
== Contingency Plan ==
Line 91: Line 133:
== Documentation ==
== Documentation ==
=== Caveats ===
=== Caveats ===
* The linux terminal (i.e. those on virtual consoles) doesn't support 256 colors and will break if applications send 256 color codes to it. This is handled in the config file above.
* When connecting using 256 color xterms to other systems with SSH (which propagates the TERM environment variable), they will have to support the $TERM, or otherwise you will have a degraded experience. Debian for example traditionally didn't support ''xterm-256color'' unless the '''ncurses-term''' package was installed. Note ubuntu 12.04 at least does support '''xterm-256color''' so this is improving. Also as noted above Mac OS X 10.7 defaults to xterm-256color and so they're paving the way somewhat in this regard, so there should be less issues in connecting to older systems going forward. These points are mentioned in the release notes.
* Local xterms support this feature fine, though once you connect to other systems with SSH (which propagates the TERM environment variable), they will have to support the $TERM, or otherwise you will have a degraded experience. Debian for example traditionally didn't support ''xterm-256color'' unless the '''ncurses-term''' package was installed. Note ubuntu 12.04 at least does support '''xterm-256color''' so this is improving. Also as noted above Mac OS X 10.7 defaults to xterm-256color and so they're paving the way somewhat in this regard, so there should be less issues in connecting to older systems going forward.
 
=== Terminal 256 color support list ===
 
==== Will be enabled with 256 colors automatically ====
* gnome-terminal
* konsole [https://bugzilla.redhat.com/show_bug.cgi?id=845583 could be improved slightly]
* mate-terminal
* Terminal
* eterm
* xterm
* roxterm
* terminator
* rxvt256c (already defaults to 256 color)
* urxvt256c (already defaults to 256 color)
* st (already defaults to 256 color)
* screen
* tmux (uses screen env settings)
 
==== Don't support 256 colors ====
* linux virtual console
* tn5250
* x3270
* rxvt (8)
* urxvt (88)
* aterm
 
==== May auto support 256 colors in future ====
 
These terminals can support 256 colors but are not identifiable
using env variables. It would make sense to modify these to set COLORTERM
 
* lxterminal
* termit
* tilda
* sakura
* yakuake
* guake
* mrxvt


== Release Notes ==
== Release Notes ==
Probably worth mentioning the case where users may need to reset their TERM to 'xterm' etc. when sshing to older systems.
256 color terminals are enabled by default, which may causes minor issues when sshing to certain older systems.
This issue is well known and similar to where you need to reset TERM on some systems when using the rxvt-unicode terminal for example.
 
Something simple like this should suffice:
This is because ssh will propagate the '''TERM''' environment variable which the remote system may not support,
in which case you could receive "unknown" or "not fully functional" terminal status messages.
 
=== Unsetting 256 color on the remote system ===
The simplest way to address this issue is by setting the '''TERM''' variable back to
the widely supported '''xterm''' value.
 
This could be done for example by adding
the following to your ~/.profile on the remote system:
test "SSH_CONNECTION" && export TERM=xterm
 
=== Adjusting the remote system to support 256 colors ===
There are often only small adjustments needed to get a remote system to support 256 colors.
On older debian systems for example you just need to install the '''ncurses-term''' package.


If you receive "unknown" or "not fully functional" terminal status messages when using remote systems over ssh,
Another option is to copy the terminfo to the remote system as documented at
when you didn't before, then reset the TERM environment variable to 'xterm' for the remote system.
[https://wiki.archlinux.org/index.php/Rxvt-unicode#Remote_Hosts 'running rxvt-unicode with remotes hosts']


== Comments and Discussion ==
== Comments and Discussion ==
Line 106: Line 198:




[[Category:FeatureReadyForFesco]]
[[Category:FeatureAcceptedF18]]
<!-- When your feature page is completed and ready for review -->
<!-- When your feature page is completed and ready for review -->
<!-- remove Category:FeaturePageIncomplete and change it to Category:FeatureReadyForWrangler -->
<!-- remove Category:FeaturePageIncomplete and change it to Category:FeatureReadyForWrangler -->
<!-- After review, the feature wrangler will move your page to Category:FeatureReadyForFesco... if it still needs more work it will move back to Category:FeaturePageIncomplete-->
<!-- After review, the feature wrangler will move your page to Category:FeatureReadyForFesco... if it still needs more work it will move back to Category:FeaturePageIncomplete-->
<!-- A pretty picture of the page category usage is at: https://fedoraproject.org/wiki/Features/Policy/Process -->
<!-- A pretty picture of the page category usage is at: https://fedoraproject.org/wiki/Features/Policy/Process -->

Revision as of 23:17, 9 October 2012

256 Color Terminals

Summary

Enable terminal programs to use the enhanced color capabilities of modern terminals by default.

I.E. increase their color options from the 8 colors at the top of this picture, to the other 256 displayed.

16 to 256.png

Owner

Current status

Detailed Description

Many terminal programs (like vim and ls for example) can take advantage of 256 color terminals, and all xterms I know of support at least 256 colors and sometimes more.
So let's break through the artificial 8 color limit!

Also when preparing this page, while searching the net I noticed that Mac OS X Terminal's default $TERM value is xterm-256color since Lion 10.7 That will ease some of the compatibility issues noted below.

You can see vim's default appearance using the above expanded palette at:

http://www.pixelbeat.org/docs/terminal_colours/#256

Benefit to Fedora

By having 32 times more colors available gives much better scope for using more appropriate default colors. For example, users could set their terminal backgrounds to dark or light and have ls use colors that are appropriate to either.

Also more subtle and considered coloring can be used as discussed and depicted at: https://github.com/seebi/dircolors-solarized

Scope

This will be mainly configuration changes.

After some discussion around whether it was best to update each terminal to adjust the TERM environment variable, or whether to have a central config file, it was initially decided to update each terminal. But after looking more deeply into this I thought of a way to use the simple centralized config, without causing an issue for remote terminals logging into the system. By keying on $COLORTERM rather than $TERM we both get accurate identification of the terminal, and non propagation by ssh. I.E. we get to easily and centrally configure this feature for particular terminals and also avoid having to add config options to each terminal some of which discourage new config options on principle.

Here are setting notes on setting $TERM on various terminals: Noted there was the fact that it's not configurable in gnome-terminal (vte) yet.

There is a related bug to set $TERM to 'gnome' 'gnome-256color', though we probably should stick to 'xterm' to reduce remote interop issues (ubuntu precise for example doesn't support TERM=gnome)

Here are notes on the xfce bug where it doesn't set the specified TERM correctly: http://forums.opensuse.org/english/get-technical-help-here/how-faq-forums/unreviewed-how-faq/459826-setting-term-xfce-terminal-bug-description-workaround.html https://bugs.archlinux.org/task/21007#comment94595

Here is the current version of the /etc/profile.d/256color.sh file.

# Enable 256 color capabilities for appropriate terminals

# Set this variable in your local shell config if you want remote
# xterms connecting to this system, to be sent 256 colors.
# This can be done in /etc/csh.cshrc, or in an earlier profile.d script.
#   SEND_256_COLORS_TO_REMOTE=1

# Terminals with any of the following set, support 256 colors (and are local)
local256="$COLORTERM$XTERM_VERSION$ROXTERM_ID$KONSOLE_DBUS_SESSION"

if [ -n "$local256" ] || [ -n "$SEND_256_COLORS_TO_REMOTE" ]; then

  case "$TERM" in
    'xterm') TERM=xterm-256color;;
    'screen') TERM=screen-256color;;
    'Eterm') TERM=Eterm-256color;;
  esac
  export TERM

  if [ -n "$TERMCAP" ] && [ "$TERM" = "screen-256color" ]; then
    TERMCAP=$(echo "$TERMCAP" | sed -e 's/Co#8/Co#256/g')
    export TERMCAP
  fi
fi

unset local256

As an optional additional improvement, we could adjust the 256 color values used in ls by editing the /etc/DIR_COLORS.256color file in the coreutils package, as it doesn't take as much advantage of the color range as it could.

As the default vim color scheme has some issues in 256 colors, we should also provide updates on this. Search, SpellLocal, ColorColumn and MatchParen are hardly readable (see :hi under vim). We should also avoid uses of bold attribute in vim highlighting as it can look bad especially at smaller font sizes. There are only a couple of uses of bold in the 256 color scheme so they can be easily avoided. Bold should be left in the vim 8 color scheme due to the effective doubling of colors that provides.

How To Test

Test as many colored terminal apps as possible under as many terminals as possible. Ensure screen works as expected too. There are screen testing notes at: http://www.robmeerman.co.uk/unix/256colours

To get the color numbers of your actual TERM, use the following:

$ tput colors
256

For testing any ls color changes you can use this command:

eval $(dircolors /etc/DIR_COLORS.256color)
echo $LS_COLORS | tr : '\n' | sed 's/\(.*\)=\(.*\)/\x1b[\2m\1\t\2\x1b[0m/'

User Experience

Better default colors with less tweaking required.

Dependencies / Affected packages

The following packages could be updated in order to auto enable or improve the 256 colors usage:

Contingency Plan

None necessary, revert to previous release behaviour

Documentation

Caveats

  • When connecting using 256 color xterms to other systems with SSH (which propagates the TERM environment variable), they will have to support the $TERM, or otherwise you will have a degraded experience. Debian for example traditionally didn't support xterm-256color unless the ncurses-term package was installed. Note ubuntu 12.04 at least does support xterm-256color so this is improving. Also as noted above Mac OS X 10.7 defaults to xterm-256color and so they're paving the way somewhat in this regard, so there should be less issues in connecting to older systems going forward. These points are mentioned in the release notes.

Terminal 256 color support list

Will be enabled with 256 colors automatically

  • gnome-terminal
  • konsole could be improved slightly
  • mate-terminal
  • Terminal
  • eterm
  • xterm
  • roxterm
  • terminator
  • rxvt256c (already defaults to 256 color)
  • urxvt256c (already defaults to 256 color)
  • st (already defaults to 256 color)
  • screen
  • tmux (uses screen env settings)

Don't support 256 colors

  • linux virtual console
  • tn5250
  • x3270
  • rxvt (8)
  • urxvt (88)
  • aterm

May auto support 256 colors in future

These terminals can support 256 colors but are not identifiable using env variables. It would make sense to modify these to set COLORTERM

  • lxterminal
  • termit
  • tilda
  • sakura
  • yakuake
  • guake
  • mrxvt

Release Notes

256 color terminals are enabled by default, which may causes minor issues when sshing to certain older systems.

This is because ssh will propagate the TERM environment variable which the remote system may not support, in which case you could receive "unknown" or "not fully functional" terminal status messages.

Unsetting 256 color on the remote system

The simplest way to address this issue is by setting the TERM variable back to the widely supported xterm value.

This could be done for example by adding the following to your ~/.profile on the remote system:

test "SSH_CONNECTION" && export TERM=xterm

Adjusting the remote system to support 256 colors

There are often only small adjustments needed to get a remote system to support 256 colors. On older debian systems for example you just need to install the ncurses-term package.

Another option is to copy the terminfo to the remote system as documented at 'running rxvt-unicode with remotes hosts'

Comments and Discussion