GNU/Linux >> Tutoriels Linux >  >> Linux

Comment changer la forme, la couleur et le taux de clignotement du curseur de la console Linux ?

GitHub Gist :comment modifier la forme, la couleur et le taux de clignotement du curseur de la console Linux

Je définis les paramètres de formatage du curseur suivants dans mon .bashrc fichier (ou /etc/bashrc ):

##############
# pretty prompt and font colors
##############

# alter the default colors to make them a bit prettier
echo -en "\e]P0000000" #black
echo -en "\e]P1D75F5F" #darkred
echo -en "\e]P287AF5F" #darkgreen
echo -en "\e]P3D7AF87" #brown
echo -en "\e]P48787AF" #darkblue
echo -en "\e]P5BD53A5" #darkmagenta
echo -en "\e]P65FAFAF" #darkcyan
echo -en "\e]P7E5E5E5" #lightgrey
echo -en "\e]P82B2B2B" #darkgrey
echo -en "\e]P9E33636" #red
echo -en "\e]PA98E34D" #green
echo -en "\e]PBFFD75F" #yellow
echo -en "\e]PC7373C9" #blue
echo -en "\e]PDD633B2" #magenta
echo -en "\e]PE44C9C9" #cyan
echo -en "\e]PFFFFFFF" #white
clear #for background artifacting

# set the default text color. this only works in tty (eg $TERM == "linux"), not pts (eg $TERM == "xterm")
setterm -background black -foreground green -store

# http://linuxgazette.net/137/anonymous.html
cursor_style_default=0 # hardware cursor (blinking)
cursor_style_invisible=1 # hardware cursor (blinking)
cursor_style_underscore=2 # hardware cursor (blinking)
cursor_style_lower_third=3 # hardware cursor (blinking)
cursor_style_lower_half=4 # hardware cursor (blinking)
cursor_style_two_thirds=5 # hardware cursor (blinking)
cursor_style_full_block_blinking=6 # hardware cursor (blinking)
cursor_style_full_block=16 # software cursor (non-blinking)

cursor_background_black=0 # same color 0-15 and 128-infinity
cursor_background_blue=16 # same color 16-31
cursor_background_green=32 # same color 32-47
cursor_background_cyan=48 # same color 48-63
cursor_background_red=64 # same color 64-79
cursor_background_magenta=80 # same color 80-95
cursor_background_yellow=96 # same color 96-111
cursor_background_white=112 # same color 112-127

cursor_foreground_default=0 # same color as the other terminal text
cursor_foreground_cyan=1
cursor_foreground_black=2
cursor_foreground_grey=3
cursor_foreground_lightyellow=4
cursor_foreground_white=5
cursor_foreground_lightred=6
cursor_foreground_magenta=7
cursor_foreground_green=8
cursor_foreground_darkgreen=9
cursor_foreground_darkblue=10
cursor_foreground_purple=11
cursor_foreground_yellow=12
cursor_foreground_white=13
cursor_foreground_red=14
cursor_foreground_pink=15

cursor_styles="\e[?${cursor_style_full_block};${cursor_foreground_black};${cursor_background_green};c" # only seems to work in tty

# http://www.bashguru.com/2010/01/shell-colors-colorizing-shell-scripts.html
prompt_foreground_black=30
prompt_foreground_red=31
prompt_foreground_green=32
prompt_foreground_yellow=33
prompt_foreground_blue=34
prompt_foreground_magenta=35
prompt_foreground_cyan=36
prompt_foreground_white=37

prompt_background_black=40
prompt_background_red=41
prompt_background_green=42
prompt_background_yellow=43
prompt_background_blue=44
prompt_background_magenta=45
prompt_background_cyan=46
prompt_background_white=47

prompt_chars_normal=0
prompt_chars_bold=1
prompt_chars_underlined=4 # doesn't seem to work in tty
prompt_chars_blinking=5 # doesn't seem to work in tty
prompt_chars_reverse=7

prompt_reset=0

#start_prompt_coloring="\e[${prompt_chars_bold};${prompt_foreground_black};${prompt_background_green}m"
start_prompt_styles="\e[${prompt_chars_bold}m" # just use default background and foreground colors
end_prompt_styles="\e[${prompt_reset}m"

PS1="${start_prompt_styles}[\[email protected]\h \W] \$${end_prompt_styles}${cursor_styles} "

##############
# end pretty prompt and font colors
##############

La plupart des applications utilisent la fonctionnalité cnorm pour remettre le curseur à l'état "normal". Par défaut, il s'agit du soulignement clignotant. Mais vous pouvez remplacer cela dans votre terminfo. Cela devrait corriger la plupart des applications (vim, tmux, etc.). Lancez ces commandes :

infocmp -A /usr/share/terminfo linux > linux
patch -lp1 <<EOF
--- a/linux
+++ b/linux
@@ -4,7 +4,7 @@ linux|linux console,
    colors#8, it#8, ncv#18, pairs#64,
    acsc=+\020\,\021-\030.^Y0\333\`\004a\261f\370g\361h\260i\316j\331k\277l\332m\300n\305o~p\304q\304r\304s_t\303u\264v\301w\302x\263y\363z\362{\343|\330}\234~\376,
    bel=^G, blink=\E[5m, bold=\E[1m, civis=\E[?25l\E[?1c,
-   clear=\E[H\E[J, cnorm=\E[?25h\E[?0c, cr=^M,
+   clear=\E[H\E[J, cnorm=\E[?25h\E[?48;0;32c, cr=^M,
    csr=\E[%i%p1%d;%p2%dr, cub=\E[%p1%dD, cub1=^H,
    cud=\E[%p1%dB, cud1=^J, cuf=\E[%p1%dC, cuf1=\E[C,
    cup=\E[%i%p1%d;%p2%dH, cuu=\E[%p1%dA, cuu1=\E[A,
EOF
tic linux
rm linux

Modifiez le patch ci-dessus selon vos besoins. Cela devrait créer ~/.terminfo/l/linux qui devrait être récupéré par la plupart des applications de terminal.


Si vous utilisez bash, vous pouvez utiliser PROMPT_COMMAND qui exécutera une commande après chaque commande. Mettez ce qui suit dans votre .bashrc

PROMPT_COMMAND='echo -e "\e[?16;0;200c"'

Linux
  1. Comment changer un nom d'hôte sous Linux

  2. Comment changer la couleur de votre terminal Linux

  3. Comment changer de shell sous Linux

  4. Comment zoomer et dézoomer la console du terminal sous Linux

  5. Comment changer le keymap de la console sous Linux ?

Comment changer l'adresse IP sous Linux

Comment installer et configurer la console Web Cockpit sur le système Linux

Schémas de couleurs dans Vim :comment les modifier et les utiliser

Comment changer la date, l'heure et le fuseau horaire dans Linux Mint 20

Comment changer le nom d'hôte et l'adresse IP dans CentOS / RedHat Linux

Comment changer le nom d'utilisateur et le nom d'hôte sur le système Linux