Changeset - cf4ab3460dba
[Not reviewed]
0 1 0
Branko Majic (branko) - 2 years ago 2022-05-31 21:15:41
branko@majic.rs
Noticket: [factorio_manager.sh] Add support for forcing colour output.
1 file changed with 13 insertions and 3 deletions:
0 comments (0 inline, 0 general) First comment
games/factorio_manager.sh
Show inline comments
 
@@ -212,6 +212,8 @@ versions
 

	
 
$program accepts the following options:
 

	
 
    -C
 
        Force colour output.
 
    -q
 
        Quiet mode. Output a message only if newer packages are available.
 
    -d
 
@@ -250,10 +252,12 @@ $program, version $version
 
EOF
 
}
 

	
 
function setup_colours() {
 

	
 
    # Set-up colours for message printing if we're not piping and terminal is
 
    # capable of outputting the colors.
 
    _color_terminal=$(tput colors 2>&1)
 
if [[ -t 1 ]] && (( _color_terminal > 0 )); then
 
    if [[ -t 1 ]] && (( _color_terminal > 0 )) || (( force_colours == 1 )); then
 
        _text_black=$(tput setaf 0)
 
        _text_red=$(tput setaf 1)
 
        _text_green=$(tput setaf 2)
 
@@ -307,7 +311,7 @@ else
 
    fi
 

	
 
    # Make the colors available via an associative array as well.
 
declare -A _text_colors=()
 
    declare -g -A _text_colors=()
 

	
 
    _text_colors[black]="${_text_black}"
 
    _text_colors[blue]="${_text_blue}"
 
@@ -326,6 +330,7 @@ _text_colors[boldpurple]="${_text_bold}${_text_purple}"
 
    _text_colors[boldred]="${_text_bold}${_text_red}"
 
    _text_colors[boldwhite]="${_text_bold}${_text_white}"
 
    _text_colors[boldyellow]="${_text_bold}${_text_yellow}"
 
}
 

	
 
# Set-up functions for printing coloured messages.
 
function debug() {
 
@@ -1220,6 +1225,7 @@ ERROR_GENERAL=3
 
# Disable debug and quiet modes by default.
 
debug=0
 
quiet=0
 
force_colours=0
 

	
 
# Set-up some default paths.
 
manager_directory="$HOME/.factorio"
 
@@ -1227,13 +1233,15 @@ game_installations_directory="$manager_directory/.game_installations"
 

	
 
# If no arguments were given, just show usage help.
 
if [[ -z ${1-} ]]; then
 
    setup_colours
 
    short_usage
 
    exit "$SUCCESS"
 
fi
 

	
 
# Parse the arguments
 
while getopts "qdvh" opt; do
 
while getopts "Cqdvh" opt; do
 
    case "$opt" in
 
        C) force_colours=1;;
 
	q) # shellcheck disable=SC2034 # part of standard Bash script template.
 
           quiet=1;;
 
	d) debug=1;;
 
@@ -1248,6 +1256,8 @@ done
 
i=$OPTIND
 
shift $((i-1))
 

	
 
setup_colours
 

	
 
# Make sure the manager home directory exists.
 
if [[ ! -e $manager_directory ]]; then
 
    info "Creating Factorio Manager home directory under: $manager_directory"
0 comments (0 inline, 0 general) First comment
You need to be logged in to comment. Login now