assaultcube / AC

AssaultCube
824 stars 213 forks source link

Colorful stdout #146

Open GreenLunar opened 8 years ago

GreenLunar commented 8 years ago

When starting AssaultCube from a terminal emulator, the entire stdout output is in the same color.

Example output from Weed Lounge:

connected: player01
Player player01 connected from Germany
player05 has the CLA flag
player03 sprayed player04
player02 punctured player06
player01: Awesome!
Respect everybody

In terminal emulator, it would look as follows:

tput bold; echo -n 'connected: player01'; tput sgr0; echo
tput bold; echo -n 'Player '; tput sgr0; tput setaf 2; echo -n 'player01'; tput sgr0; tput bold; echo -n ' connected from '; tput sgr0; tput setaf 2; echo -n 'Germany'; tput sgr0; echo
tput bold; tput setaf 3; echo -n 'player05 has the CLA flag'; tput sgr0; echo
tput bold; tput setaf 3; echo -n 'player03 sprayed player04'; tput sgr0; echo
tput bold; tput setaf 3; echo -n 'player02 punctured player06'; tput sgr0; echo
tput bold; echo -n 'player01: '; tput setaf 2; echo -n 'Awesome!'; tput sgr0; echo
tput bold; tput setaf 1; echo -n 'Respect everybody'; tput sgr0; echo

In AssaultCube, it would look as follows:

[white]connected: player01[/white]
[white]Player[/white] [green]player01[/green] [white]connected from[/white] [green]Germany[/green]
[yellow]player05 has the CLA flag[/yellow]
[yellow]player03 sprayed player04[/yellow]
[yellow]player02 punctured player06[/yellow]
[white]player01:[/white] [brightgreen]Awesome![/brightgreen]
[red]Respect everybody[/red]
GreenLunar commented 7 years ago

Example in Bash

tput bold; echo -n 'connected: player01'; tput sgr0; echo
tput bold; echo -n 'Player '; tput sgr0; tput setaf 2; echo -n 'player01'; tput sgr0; tput bold; echo -n ' connected from '; tput sgr0; tput setaf 2; echo -n 'Germany'; tput sgr0; echo
tput bold; tput setaf 3; echo -n 'player05 has the CLA flag'; tput sgr0; echo
tput bold; tput setaf 3; echo -n 'player03 sprayed player04'; tput sgr0; echo
tput bold; tput setaf 3; echo -n 'player02 punctured player06'; tput sgr0; echo
tput bold; echo -n 'player01: '; tput setaf 2; echo -n 'Awesome!'; tput sgr0; echo
tput bold; tput setaf 1; echo -n 'Respect everybody'; tput sgr0; echo

Edit: Line 2 may also be:

tput bold; echo -n 'Player '; tput setaf 0; echo -n 'player01'; tput sgr0; tput bold; echo -n ' connected from '; tput setaf 0; echo -n 'Germany'; tput sgr0; echo

Edit: Alternative

tput bold
echo -n 'connected: player01'; tput setaf 9 ; echo
echo -n 'Player '; tput setaf 0; echo -n 'player01'; tput setaf 9; echo -n ' connected from '; tput setaf 0; echo -n 'Germany'; tput setaf 9; echo
tput setaf 3; echo -n 'player05 has the CLA flag'; tput setaf 9; echo
tput setaf 3; echo -n 'player03 sprayed player04'; tput setaf 9; echo
tput setaf 3; echo -n 'player02 punctured player06'; tput setaf 9; echo
echo -n 'player01: '; tput setaf 2; echo -n 'Awesome!'; tput setaf 9; echo
tput setaf 1; echo -n 'Respect everybody'; tput setaf 9; echo
tput sgr0
for i in {0..7} 9; do tput setaf $i; echo tput setaf $i; done
tput bold; for i in {0..7} 9; do tput setaf $i; echo tput setaf $i; done

How can I print text in various colors?