How do I change the default colors of a running Xterm? - colors

When you start an xterm, its default colors are determined by .Xdefaults OR --fg and --bg options. Those are the defaults for this particular xterm process. If you then change colors with ansi sequences, when you send the ansi reset sequence, you get back to the colors it started up with.
What I want to change is the defaults for this particular xterm process. I want to, in effect, re-exec the xterm command with a new set of --fg and --bg options.
Is there an option to reset the default colors, not the current colors?

The dynamic colors feature does that (does not get "reset" in the normal escape sequences, which use "ANSI" escapes):
The 10 colors (below) which may be set or queried using 1 0
through 1 9 are denoted dynamic colors, since the
corresponding control sequences were the first means for
setting xterm's colors dynamically, i.e., after it was
started. They are not the same as the ANSI colors (however,
the dynamic text foreground and background colors are used
when ANSI colors are reset using SGR 3 9 and 4 9 ,
respectively).
Change VT100 text background color (OSC 11)
Change VT100 text foreground color (OSC 10)

Related

Syntax highlighting in zsh using 256 colors?

I'm using prezto with zsh, and my difficulty is with the syntax highlighting, of which a sample line is
'function' 'bg=green'
I could also have here, for example
'function' 'bg=blue,fg=yellow'
However, I want to take advantage of my 256 color terminal (konsole in my case), in which case I would have thought that something like
'function' 'bg=$FG[021],fg=$FG[196]'
for example, would work, given that I have previously loaded the spectrum module.
But I can't get this to work. I've checked that tput colors returns 256, and that the command
echo "$FG[214]Hello, World"
gives me an orange output.
Anyway, whether I use spectrum or not, I'd like more control over my syntax highlighting, and to be able to use 256 colors. Any advice would be very welcome!
You could specify the color index here like below:
'function' 'bg=21,fg=196'
zsh-syntax-highlighting gets the ability to specify colors from the zsh's Character Highlighting rather than ANSI escape sequences directly. This zsh manual describes a 'fg=colour' as below:
fg=colour
 The foreground colour should be set to colour, a decimal integer or the name of one of the eight most widely-supported colours.
We can use the color index rather than ANSI escpape sequences which spectrum module stores on $FG[...].
You can try:
export TERM='xterm-256color'

Strange escape sequence sent by vim to terminal

vim appears to send several strange (i.e. undocumented) escape sequences to the underlying terminal when using the inkpot scheme. I have been unable to match them to any VT-100 or ANSI escape codes; does anyone know what these sequences are?
^[[3231m
^[[4232m
^[[3130m
These sequences show up as invalid tokens in a terminal emulator I am responsible for, and I would like to add support for these sequences if I can find proper documentation for them.
The following terminal-related environment variables are set on the affected systems:
TERM=xterm
COLORTERM=
I have not tried any other settings for those two variables.
vim is version 7.2, but I have tried newer versions with same effect.
Thanks!
Does your terminal support 88- or 256-color mode? If so, you should probably use a TERM value like xterm-88color or xterm-256color instead of plain xterm.
inkpot specifically disclaims support for terminals that only support 8/16 colors. From the top of the inkpot source:
" This should work in the GUI, rxvt-unicode (88 colour mode) and xterm (256
" colour mode). It won't work in 8/16 colour terminals.
The code that sets up the syntax coloring assumes that if the terminal does not support 88 colors, then it must support 256 colors. It does not try to provide fallback values for the case of 8 colors (e.g. when TERM=xterm). Maybe it would be nice if inkpot issued an error message (and did not modify the color settings) if the terminal did not appear to have appropriate color support.
The control sequences you are seeing result from trying to generate an 8-color terminal color control sequence for a color number that is outside the 0–7 range of acceptable inputs for that type of terminal. So, these sequences are probably not valid, but they are not entirely intentional either (arising because inkpot assumes 256-color support, but the xterm terminfo entry only knows how to handle basic 8-color support).
For example, inkpot sets the Normal syntax foreground color to 79 on 88-color terminals; this is translated to 231 for non-88-color terminals (i.e. for 256-color terminals, but also for your 8-color xterm).
When you try to format this out-of-range color number with TERM=xterm, you get the result ^[[3231m that you found:
% tput -T xterm setaf 231 | od -a
0000000 esc [ 3 2 3 1 m
0000007
(i.e. inserting 231 between ^[[3 and m)
If you use xterm-256color, you get a more normal looking result:
% tput -T xterm-256color setaf 231 | od -a
0000000 esc [ 3 8 ; 5 ; 2 3 1 m
0000013
(i.e. inserting 231 between ^[[38;5; and m)
Similarly, the Normal syntax 88-color background color of 80 is translated to a 256-color value of 232 and produces the errant ^[[4232m sequence for xterm (but would produce the more reasonable ^[[48;5;232m under xterm-256color).
^[[3231m
looks a lot like a color definition done/gone wrong:
^[[32;31m
which wouldn't make much sense anyway.
Does it happen with a specific value for $TERM or for any value? What Vim version? What terminal emulator are we talking about?

Setting linespace in gVim

When setting linespace to some value greater than zero, the characters in the line are vertically top-aligned. I want the characters to be vertically centered (in the middle of the line).
The 'linespace' setting allows to slightly adapt the visual spacing of lines to the used font (so that text is neither too dense nor too much apart). It is not meant to be used for the "widely-spaced lines" effect shown in your screenshot.
If you really need something like that, you'd need to patch Vim's source code, or use another editor, or what I would attempt is modifying the used font to include more vertical padding in all glyphs.

terminal escape sequences for fonts

What I want to develop:
Terminal which can use at least 2 fonts in the same time. One font I will use for shell input lines, another font for command output. For example:
user#host$ ls /home
user user1 user2 user3
Why:
More readable terminal/shell
How: Here I have problem. Probably shell needs to generate some new escape sequences. And terminal need to load different fonts and handle those sequences. Where to start? How to define new escaping sequence, where are standards?
Future: Maybe somebody want to join me in this project?
The standard for control sequences is pretty much the Xterm Control Sequences document ctlseqs.ms in the XTerm source code. (You can turn it into a PDF with the command groff -ms -Tps ctlseqs.ms | ps2pdf - ctlseqs.pdf, though the -ms option seems to be broken on Ubuntu 12.04).
XTerm already supports control sequences to change the font, but for the entire terminal at once. Open xterm and type into your shell—
echo -e "\033[?35h\033]50;#+1^G\033\\" # aka CSI ? 35 h OSC 50 ; #+1 BEL ST
the font for the entire terminal should change. This control sequence actually supports the names of True-Type fonts as well; see page 21.
If you'd like to change an existing terminal to support changing the font inline, you're
welcome to choose pretty much any control sequences not already allocated in ctrlseqs.ms and use them. However, it's a good idea to choose new control sequences similar to the control sequences for functionality that already exists.
Your next step is to get the source code for an existing terminal and start digging. What terminal do you use right now? The source code for Konsole or gnome-terminal is probably going to be easier to work with than that for XTerm.
There is a standard sequence for swapping fonts.
SGR 11
Also known as
CSI 11m
ESC [ 11m
Similarly
SGR 10
will switch back to the default font.
However, as has been commented, almost no terminal actually supports this. You'd likely be better off using some other rendering attribute, such as bold/underline/italics. Though note also not many terminals support italics.
For reference
SGR 1 = bold
SGR 4 = underline
SGR 3 = italics
If you are happy with just different font attributes (and not different fonts) you can even implement something similar without writing your own terminal emulator if you use zsh. You can just set up your shell to emit the right escape sequences to set the correct terminal attribute (italics, bold, color, ...) before and after the prompt and before command execution.
Let's assume you use Xterm and want your prompt to be bold, the typed command line to be italics and the command output to be normal.
Then the setup looks like this:
# bold is \e[1m and italics is \e[3m , \e[0m resets the attributes
PS1=$'\e[1m'$PS1$'\e[0;3m' # I assume you have set PS1 already
function reset-terminal-attributes { printf '\e[0m'; }
autoload add-zsh-hook
add-zsh-hook preexec reset-terminal-attributes

How to color a prompt on FreeBSD/cshrc?

I'm being put in charge of managing a bunch of servers, I want to set up my prompts on each of them so that I don't get confused as to where I am logged in to.
I've edited my .cshrc files and put this in them:
set prompt=`whoami`#`hostname -s`:$cwd'$ '
But I'd like to color that prompt so it stands out a bit more. Maybe green with white text or something. How can I do that? I'm not very familiar with the shell syntax.
I'm SSH-ing in from the standard terminal that comes with Ubuntu, if that's relevant.
This page has a pretty good explanation, although the syntax is a bit different in csh. Here's what I came up with:
set prompt="%{\e[32;1m%}%n%{\e[37m%}#%{\e[33m%}%m%{\e[37m%}:%{\e[36m%}%~%{\e[37m%}"\$"%{\e[0m%} "
# root variation:
set prompt="%{\e[31;1m%}root%{\e[37m%}#%{\e[33m%}%m%{\e[37m%}:%{\e[36m%}%/%{\e[37m%}#%{\e[0m%} "
update: the previous prompt I had here didn't actually update when you changed directories. using %n, %~ and %m instead of $cwd or pwd actually update. see here.
%{ ... %} means the stuff between should take 0-width
\e[ ... m specifies the colors and bolding. \e escapes the [ which seems to be necessary (I believe it's equivalent to \033), the m signifies the end.
Use 0 as your color to reset to default.
If you want to set a color and background, simply separate the numbers with semi-colons. Use 1 to enable bolding.
Consult this table to choose your colors:
(source: funtoo.org)
So for example, "Hello World" in bold, cyan on a red background would be %{\e[36;41;1m%}Hello World%{\e[0m%}
To my knowledge FreeBSD comes with tcsh by default. Have a look at the examples.
Another list for other shells as well (bash, csh, tcsh, ksh, etc.) is available. Taken from that link and tested with tcsh (I do not have csh installed):
To color the prompt you will want to place this symbol in your prompt. %{\033[Xm%}.
Certain colors need a semicolon in order to appear. Yellow […] is 1;33 do not use just 33 or it will come out brown. If you have a 0;31 you don't need to place the 0.
The colours are ANSI. Have a look at the ANSI colours list; simply replace X with the colour code.
X = 0 resets the colours: %{\033[0m%}.
# Add these lines to your ~/.cshrc.mine file on the linux grace machines...
# Colors!
set red="%{\033[1;31m%}"
set green="%{\033[0;32m%}"
set yellow="%{\033[1;33m%}"
set blue="%{\033[1;34m%}"
set magenta="%{\033[1;35m%}"
set cyan="%{\033[1;36m%}"
set white="%{\033[0;37m%}"
set end="%{\033[0m%}" # This is needed at the end... :(
# Setting the actual prompt
set prompt="${green}%n${blue}#%m ${white}%~ ${green}%%${end} "
# Clean up
unset red green yellow blue magenta cyan yellow white end

Resources