Tags de Cores e formatação no Terminal
Publicado por Maxwell Aguiar Silva (última atualização em 03/12/2021)
[ Hits: 1.030 ]
Esse script permite utilizar tags para formata a saída de texto no terminal.
Verifique o código para ver todas as tags disponíveis.
Utilização:
# Importa a função.
. lib-simple-tags
# Exemplo 1
cat <<EOF | simple-tags
[b]Bold[/b]
[i]Italic[/i]
[u]Underline[/u]
Normal [negative]Negativo[/negative] Normal
[red]Vermelho[reset]
[red][#white]Vermelho fundo branco[reset]
[blink]Piscando[/blink]
[reset]
EOF
# Exemplo 2
simple-tags "[strike]Traçado[/strike]"
#!/bin/bash
function simple-tags( )
{
# Tabela de substituição das tags ( ECMA-48 ).
local tags_table
tags_table=$( cat <<-EOF
"[reset]" "\\e[0m"
"[b]" "\\e[1m"
"[bold]" "\\e[1m"
"[faint]" "\\e[2m"
"[i]" "\\e[3m"
"[italic]" "\\e[3m"
"[u]" "\\e[4m"
"[underline]" "\\e[4m"
"[blink]" "\\e[5m"
"[fast-blink]" "\\e[6m"
"[negative]" "\\e[7m"
"[hidden]" "\\e[8m"
"[strike]" "\\e[9m"
"[primary-font]" "\\e[10m"
"[default-font]" "\\e[10m"
"[font-1]" "\\e[11m"
"[font-2]" "\\e[12m"
"[font-3]" "\\e[13m"
"[font-4]" "\\e[14m"
"[font-5]" "\\e[15m"
"[font-6]" "\\e[16m"
"[font-7]" "\\e[17m"
"[font-8]" "\\e[18m"
"[font-9]" "\\e[19m"
"[fraktur]" "\\e[20m"
"[du]" "\\e[21m"
"[double-underline]" "\\e[21m"
"[/b]" "\\e[22m"
"[/bold]" "\\e[22m"
"[/faint]" "\\e[22m"
"[/i]" "\\e[23m"
"[/italic]" "\\e[23m"
"[/fraktur]" "\\e[23m"
"[/u]" "\\e[24m"
"[/underline]" "\\e[24m"
"[/du]" "\\e[24m"
"[/double-underline]" "\\e[24m"
"[/blink]" "\\e[25m"
"[/negative]" "\\e[27m"
"[/hidden]" "\\e[28m"
"[/strike]" "\\e[29m"
"[black]" "\\e[30m"
"[red]" "\\e[31m"
"[green]" "\\e[32m"
"[yellow]" "\\e[33m"
"[blue]" "\\e[34m"
"[magenta]" "\\e[35m"
"[cyan]" "\\e[36m"
"[white]" "\\e[37m"
"[custom-color]" "\\e[38m"
"[default-color]" "\\e[39m"
"[#black]" "\\e[40m"
"[#red]" "\\e[41m"
"[#green]" "\\e[42m"
"[#yellow]" "\\e[43m"
"[#blue]" "\\e[44m"
"[#magenta]" "\\e[45m"
"[#cyan]" "\\e[46m"
"[#white]" "\\e[47m"
"[#custom-color" "\\e[48m"
"[#default-color]" "\\e[49m"
"[br]" "\\n"
EOF
)
# Troca as tags pelos códigos do terminal.
function replace-tags()
{
# Dados de entrada.
local result=$*
while IFS=$'\t' read -r str_from str_to;
do
str_from=${str_from//\"/}
str_to=${str_to//\"/}
result=${result//"$str_from"/"$str_to"}
done <<< "$tags_table"
echo -e "$result"
}
# Lê a entrada de dados.
local result=$*
if [[ "$#" -ge 1 ]];
then
replace-tags "$*"
else
while read -r line;
do
replace-tags "$line"
done
fi
}
ebook-cli - gerencia livros digitais entre PC e leitores ebooks
Instalação do BrOffice.org 3.2.1 em distros Debian-like
Script para listar tentativas de acessos
LazyDocker – Interface de Usuário em Tempo Real para o Docker
Instalando COSMIC no Linux Mint
Turbinando o Linux Mint: o poder das Nemo Actions
Inteligência Artificial no desenvolvimento de software: quando começar a usar?
[Resolvido] Algo deu errado ao abrir seu perfil
Usando o VNSTAT para medir o seu consumo de internet
Habilitando clipboard manager no ambiente COSMIC
Problema com som no laptop (5)
Quando vocês pararam de testar distros? (11)
Não estou conseguindo fazer funcionar meu Postfix na versão 2.4 no Deb... (2)









