Tags de Cores e formatação no Terminal
Publicado por Maxwell Aguiar Silva (última atualização em 03/12/2021)
[ Hits: 1.015 ]
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
}
Script para Remover Ascentos em arquivos HTML
Startando jboss e serviços necessários
Script em bash para compilação do kernel 3.3.2 para Ubuntu 11.10 com patch 3.3.0-ck1
Script de instalação para Firefox e Thunderbird
Cirurgia para acelerar o openSUSE em HD externo via USB
Void Server como Domain Control
Modo Simples de Baixar e Usar o bash-completion
Monitorando o Preço do Bitcoin ou sua Cripto Favorita em Tempo Real com um Widget Flutuante
Atualizar Linux Mint 22.2 para 22.3 beta
Jogar games da Battle.net no Linux com Faugus Launcher
Como fazer a Instalação de aplicativos para acesso remoto ao Linux
Conky, alerta de temperatura alta (10)
Assisti Avatar 3: Fogo e Cinzas (3)
Duas Pasta Pessoal Aparecendo no Ubuntu 24.04.3 LTS (42)









