Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using ansi character codes for terminal emulator #2570

Closed
sailnfool opened this issue Apr 2, 2024 · 3 comments
Closed

Using ansi character codes for terminal emulator #2570

sailnfool opened this issue Apr 2, 2024 · 3 comments
Labels
suggestion New feature or request

Comments

@sailnfool
Copy link

sailnfool commented Apr 2, 2024

Cool ideas?

Reading your source code, it is difficult to intuitively know the meaning of the various ansi codes that are used for clearing the screen, changing colors of output, etc.

I suggest using mnemonic names that are self-explanatory to describe the codes as Bash variables. I realize that this has a minuscule effect on Bash processing speeds to build the internal lookup tables, but it makes the challenge of maintaing the code simpler.

Here is a sample header file that I include using the "source" command in Bash that has SOME (not all) ansi mnemonics:

#!/bin/bash
scriptname=${0##*/}
########################################################################
#copyright      :(C) 2023
#copyrightholder:Robert E. Novak  All Rights Reserved
#location       :Cebu, Philippines 6000
########################################################################
#scriptname     :ansi_colors
#description    :Define BASH local/GLOBAL variables to define colors
#args           :
#author         :Robert E. Novak
#authorinitials :REN
#email          :[email protected]
#license        :CC by Sea2Cloud Storage, Inc.
#licensesource  :https://creativecommons.org/licenses/by/4.0/legalcode
#licensename    :Creative Commons Attribution license
#NOTE           :attributions were split to live within 72 columns
#attribution01  :https://stackoverflow.com
#attribution02  :/questions
#attribution03  :/10466749/bash-colored-output-with-a-variable
#_____________________________________________________________________
# Rev.|Aut| Date     | Notes
#_____________________________________________________________________
# 1.0 |REN|08/05/2022| Initial Release
#_____________________________________________________________________

ansi_RESTORE='\033[0m'

ansi_RED='\033[00;31m'
ansi_GREEN='\033[00;32m'
ansi_YELLOW='\033[00;33m'
ansi_BLUE='\033[00;34m'
ansi_PURPLE='\033[00;35m'
ansi_CYAN='\033[00;36m'
ansi_LIGHTGRAY='\033[00;37m'

ansi_BRIGHT_RED='\033[00;91m'
ansi_BRIGHT_GREEN='\033[00;92m'
ansi_BRIGHT_YELLOW='\033[00;93m'
ansi_BRIGHT_BLUE='\033[00;94m'
ansi_BRIGHT_PURPLE='\033[00;95m'
ansi_BRIGHT_CYAN='\033[00;96m'
ansi_BRIGHT_LIGHTGRAY='\033[00;97m'

ansi_BG_BRIGHT_RED='\033[00;101m'
ansi_BG_BRIGHT_GREEN='\033[00;102m'
ansi_BG_BRIGHT_YELLOW='\033[00;103m'
ansi_BG_BRIGHT_BLUE='\033[00;104m'
ansi_BG_BRIGHT_PURPLE='\033[00;105m'
ansi_BG_BRIGHT_CYAN='\033[00;106m'
ansi_BG_BRIGHT_WHITE='\033[00;107m'

ansi_LRED='\033[01;31m'
ansi_LGREEN='\033[01;32m'
ansi_LYELLOW='\033[01;33m'
ansi_LBLUE='\033[01;34m'
ansi_LPURPLE='\033[01;35m'
ansi_LCYAN='\033[01;36m'
ansi_WHITE='\033[01;37m'

ansi_passstring="[${ansi_GREEN}PASS${ansi_RESTORE}]"
ansi_failstring="[${ansi_RED}${ansi_BG_BRIGHTWHITE}FAIL${ansi_RESTORE}]"
ansi_warnstring="[${ansi_BRIGHT_YELLOW}${ansi_BG_BRIGHTWHITE}WARN${ansi_RESTORE}]"
#
export ansi_RESTORE
export ansi_RED
export ansi_GREEN
export ansi_YELLOW
export ansi_BLUE
export ansi_PURPLE
export ansi_CYAN
export ansi_LIGHTGRAY
export ansi_BRIGHT_RED
export ansi_BRIGHT_GREEN
export ansi_BRIGHT_YELLOW
export ansi_BRIGHT_BLUE
export ansi_BRIGHT_PURPLE
export ansi_BRIGHT_CYAN
export ansi_BRIGHT_LIGHTGRAY
export ansi_BG_BRIGHT_RED
export ansi_BG_BRIGHT_GREEN
export ansi_BG_BRIGHT_YELLOW
export ansi_BG_BRIGHT_BLUE
export ansi_BG_BRIGHT_PURPLE
export ansi_BG_BRIGHT_CYAN
export ansi_BG_BRIGHT_WHITE
export ansi_LRED
export ansi_LGREEN
export ansi_LYELLOW
export ansi_LBLUE
export ansi_LPURPLE
export ansi_LCYAN
export ansi_WHITE
export ansi_passstring
export ansi_failstring
export ansi_warnstring
@sailnfool sailnfool added the suggestion New feature or request label Apr 2, 2024
@Botspot
Copy link
Owner

Botspot commented Apr 2, 2024

I've edited your post to format the code as bash script.

Likely the part of Pi-Apps source code you were looking at was the first few functions in api. Is that correct? Specifically, was it the generate_logo function, the error function, the status and status_green functions?
Or was there some other place where you saw unknown ansi escape codes?

@sailnfool
Copy link
Author

sailnfool commented Apr 2, 2024 via email

@theofficialgman
Copy link
Collaborator

It was in etc/terminal-run

terminal-run only has two instances of escape code usage and both are already clearly documented and neither of them are covered by your sample header file

pi-apps/etc/terminal-run

Lines 24 to 25 in f86137e

#add a line to the terminal's command-to-run that sets the title. This method allows it to be changed later, while specifying the title using a flag does not.
commands="echo -ne '\e]0;${title}\a'

pi-apps/etc/terminal-run

Lines 11 to 14 in f86137e

function error {
echo -e "\e[91m$1\e[39m"
exit 1
}

@theofficialgman theofficialgman closed this as not planned Won't fix, can't repro, duplicate, stale Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
suggestion New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants