Skip to content

Commit

Permalink
Help: update getVersion()
Browse files Browse the repository at this point in the history
  • Loading branch information
soimort committed May 8, 2015
1 parent e31eb64 commit 467a56d
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 139 deletions.
269 changes: 139 additions & 130 deletions include/Help.awk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,145 @@

# Return version as a string.
function getVersion() {
return Name " " Version
return sprintf(ansi("bold", "%-22s%s") "\n\n", Name, Version) \
sprintf("%-22s%s\n", "gawk (GNU Awk)", PROCINFO["version"]) \
sprintf("%s\n", FriBidi ? FriBidi : "fribidi (GNU FriBidi) [NOT INSTALLED]") \
sprintf("%-22s%s\n", "terminal type", ENVIRON["TERM"]) \
sprintf("%-22s%s (%s)\n", "user locale", UserLocale, getName(UserLang)) \
sprintf("%-22s%s\n", "home language", Option["hl"]) \
sprintf("%-22s%s\n", "source language", Option["sl"]) \
sprintf("%-22s%s\n", "target language", join(Option["tl"], "+")) \
sprintf("%-22s%s\n", "theme", Option["theme"]) \
sprintf("\n%-22s%s", "Report bugs to:", "https://github.com/soimort/translate-shell/issues")
}

# Return help message as a string.
function getHelp() {
return "Usage: " ansi("bold", Command " " ansi("negative", "[OPTIONS]") \
" " ansi("negative", "[SOURCE]") \
":" ansi("negative", "[TARGET(S)]") \
" " ansi("negative", "[TEXT]") " ...") RS \
"Example: " ansi("underline", "trans -brief la:en 'per aspera ad astra'") RS \
RS "Information Options:" RS \
ins(1, ansi("bold", "-V, -version")) RS \
ins(2, "Print version and exit.") RS \
ins(1, ansi("bold", "-H, -help")) RS \
ins(2, "Print help message and exit.") RS \
ins(1, ansi("bold", "-M, -manual")) RS \
ins(2, "Show man page and exit.") RS \
ins(1, ansi("bold", "-T, -reference")) RS \
ins(2, "Print a reference table of languages and exit.") RS \
ins(1, ansi("bold", "-R, -reference-english")) RS \
ins(2, "Print a reference table of languages (in English names) and exit.") RS \
RS "Display Options:" RS \
ins(1, ansi("bold", "-verbose")) RS \
ins(2, "Verbose mode. (default)") RS \
ins(1, ansi("bold", "-b, -brief")) RS \
ins(2, "Brief mode.") RS \
ins(1, ansi("bold", "-d, -dictionary")) RS \
ins(2, "Dictionary mode.") RS \
ins(1, ansi("bold", "-show-original " ansi("negative", "Y|n"))) RS \
ins(2, "Show original text or not.") RS \
ins(1, ansi("bold", "-show-original-phonetics " ansi("negative", "Y|n"))) RS \
ins(2, "Show phonetic notation of original text or not.") RS \
ins(1, ansi("bold", "-show-translation " ansi("negative", "Y|n"))) RS \
ins(2, "Show translation or not.") RS \
ins(1, ansi("bold", "-show-translation-phonetics " ansi("negative", "Y|n"))) RS \
ins(2, "Show phonetic notation of translation or not.") RS \
ins(1, ansi("bold", "-show-prompt-message " ansi("negative", "Y|n"))) RS \
ins(2, "Show prompt message or not.") RS \
ins(1, ansi("bold", "-show-languages " ansi("negative", "Y|n"))) RS \
ins(2, "Show source and target languages or not.") RS \
ins(1, ansi("bold", "-show-original-dictionary " ansi("negative", "y|N"))) RS \
ins(2, "Show dictionary entry of original text or not.") RS \
ins(1, ansi("bold", "-show-dictionary " ansi("negative", "Y|n"))) RS \
ins(2, "Show dictionary entry of translation or not.") RS \
ins(1, ansi("bold", "-show-alternatives " ansi("negative", "Y|n"))) RS \
ins(2, "Show alternative translations or not.") RS \
ins(1, ansi("bold", "-w " ansi("negative", "NUM") \
", -width " ansi("negative", "NUM"))) RS \
ins(2, "Specify the screen width for padding.") RS \
ins(1, ansi("bold", "-indent " ansi("negative", "NUM"))) RS \
ins(2, "Specify the size of indent (number of spaces).") RS \
ins(1, ansi("bold", "-no-ansi")) RS \
ins(2, "Do not use ANSI escape codes.") RS \
ins(1, ansi("bold", "-no-theme")) RS \
ins(2, "Do not use any other theme than default.") RS \
ins(1, ansi("bold", "-theme " ansi("negative", "FILENAME"))) RS \
ins(2, "Specify the theme to use.") RS \
RS "Audio Options:" RS \
ins(1, ansi("bold", "-no-play")) RS \
ins(2, "Do not listen to the translation.") RS \
ins(1, ansi("bold", "-p, -play")) RS \
ins(2, "Listen to the translation.") RS \
ins(1, ansi("bold", "-player " ansi("negative", "PROGRAM"))) RS \
ins(2, "Specify the audio player to use, and listen to the translation.") RS \
RS "Terminal Paging and Web Options:" RS \
ins(1, ansi("bold", "-no-view")) RS \
ins(2, "Do not view the translation in a terminal pager.") RS \
ins(1, ansi("bold", "-v, -view")) RS \
ins(2, "View the translation in a terminal pager.") RS \
ins(1, ansi("bold", "-pager " ansi("negative", "PROGRAM"))) RS \
ins(2, "Specify the terminal pager to use, and view the translation.") RS \
ins(1, ansi("bold", "-browser " ansi("negative", "PROGRAM"))) RS \
ins(2, "Specify the web browser to use.") RS \
RS "Networking Options:" RS \
ins(1, ansi("bold", "-x " ansi("negative", "HOST:PORT") \
", -proxy " ansi("negative", "HOST:PORT"))) RS \
ins(2, "Use HTTP proxy on given port.") RS \
ins(1, ansi("bold", "-u " ansi("negative", "STRING") \
", -user-agent " ansi("negative", "STRING"))) RS \
ins(2, "Specify the User-Agent to identify as.") RS \
RS "Interactive Shell Options:" RS \
ins(1, ansi("bold", "-no-rlwrap")) RS \
ins(2, "Do not invoke rlwrap when starting an interactive shell.") RS \
ins(1, ansi("bold", "-I, -interactive, -shell")) RS \
ins(2, "Start an interactive shell.") RS \
ins(1, ansi("bold", "-E, -emacs")) RS \
ins(2, "Start the GNU Emacs front-end for an interactive shell.") RS \
RS "I/O Options:" RS \
ins(1, ansi("bold", "-i " ansi("negative", "FILENAME") \
", -input " ansi("negative", "FILENAME"))) RS \
ins(2, "Specify the input file.") RS \
ins(1, ansi("bold", "-o " ansi("negative", "FILENAME") \
", -output " ansi("negative", "FILENAME"))) RS \
ins(2, "Specify the output file.") RS \
RS "Language Preference Options:" RS \
ins(1, ansi("bold", "-l " ansi("negative", "CODE") \
", -lang " ansi("negative", "CODE"))) RS \
ins(2, "Specify your home language.") RS \
ins(1, ansi("bold", "-s " ansi("negative", "CODE") \
", -source " ansi("negative", "CODE"))) RS \
ins(2, "Specify the source language.") RS \
ins(1, ansi("bold", "-t " ansi("negative", "CODE(S)") \
", -target " ansi("negative", "CODE(S)"))) RS \
ins(2, "Specify the target language(s), joined by '+'.") RS \
RS "Other Options:" RS \
ins(1, ansi("bold", "-no-init")) RS \
ins(2, "Do not load any initialization script.") RS \
RS "See the man page " Command "(1) for more information."
}

# Display man page.
function showMan( temp) {
if (ENVIRON["TRANS_MANPAGE"]) {
initPager()
temp = "echo -E \"${TRANS_MANPAGE}\""
temp = temp PIPE \
"groff -Wall -mtty-char -mandoc -Tutf8 -rLL=${COLUMNS}n -rLT=${COLUMNS}n"
switch (Pager) {
case "less":
temp = temp PIPE Pager " -s -P\"\\ \\Manual page " Command "(1) line %lt (press h for help or q to quit)\""
break
case "most":
temp = temp PIPE Pager " -Cs"
break
default: # more
temp = temp PIPE Pager
}
system(temp)
} else if (system("man " Command SUPERR))
print getHelp()
}

# Return a list of language codes as a string.
Expand Down Expand Up @@ -204,132 +342,3 @@ function getReference(displayName) {
"" RS \
"└──────────────────────┴───────────────────────┴─────────────────────┘"
}

# Return help message as a string.
function getHelp() {
return "Usage: " ansi("bold", Command " " ansi("negative", "[OPTIONS]") \
" " ansi("negative", "[SOURCE]") \
":" ansi("negative", "[TARGET(S)]") \
" " ansi("negative", "[TEXT]") " ...") RS \
"Example: " ansi("underline", "trans -brief la:en 'per aspera ad astra'") RS \
RS "Information Options:" RS \
ins(1, ansi("bold", "-V, -version")) RS \
ins(2, "Print version and exit.") RS \
ins(1, ansi("bold", "-H, -help")) RS \
ins(2, "Print help message and exit.") RS \
ins(1, ansi("bold", "-M, -manual")) RS \
ins(2, "Show man page and exit.") RS \
ins(1, ansi("bold", "-T, -reference")) RS \
ins(2, "Print a reference table of languages and exit.") RS \
ins(1, ansi("bold", "-R, -reference-english")) RS \
ins(2, "Print a reference table of languages (in English names) and exit.") RS \
RS "Display Options:" RS \
ins(1, ansi("bold", "-verbose")) RS \
ins(2, "Verbose mode. (default)") RS \
ins(1, ansi("bold", "-b, -brief")) RS \
ins(2, "Brief mode.") RS \
ins(1, ansi("bold", "-d, -dictionary")) RS \
ins(2, "Dictionary mode.") RS \
ins(1, ansi("bold", "-show-original " ansi("negative", "Y|n"))) RS \
ins(2, "Show original text or not.") RS \
ins(1, ansi("bold", "-show-original-phonetics " ansi("negative", "Y|n"))) RS \
ins(2, "Show phonetic notation of original text or not.") RS \
ins(1, ansi("bold", "-show-translation " ansi("negative", "Y|n"))) RS \
ins(2, "Show translation or not.") RS \
ins(1, ansi("bold", "-show-translation-phonetics " ansi("negative", "Y|n"))) RS \
ins(2, "Show phonetic notation of translation or not.") RS \
ins(1, ansi("bold", "-show-prompt-message " ansi("negative", "Y|n"))) RS \
ins(2, "Show prompt message or not.") RS \
ins(1, ansi("bold", "-show-languages " ansi("negative", "Y|n"))) RS \
ins(2, "Show source and target languages or not.") RS \
ins(1, ansi("bold", "-show-original-dictionary " ansi("negative", "y|N"))) RS \
ins(2, "Show dictionary entry of original text or not.") RS \
ins(1, ansi("bold", "-show-dictionary " ansi("negative", "Y|n"))) RS \
ins(2, "Show dictionary entry of translation or not.") RS \
ins(1, ansi("bold", "-show-alternatives " ansi("negative", "Y|n"))) RS \
ins(2, "Show alternative translations or not.") RS \
ins(1, ansi("bold", "-w " ansi("negative", "NUM") \
", -width " ansi("negative", "NUM"))) RS \
ins(2, "Specify the screen width for padding.") RS \
ins(1, ansi("bold", "-indent " ansi("negative", "NUM"))) RS \
ins(2, "Specify the size of indent (number of spaces).") RS \
ins(1, ansi("bold", "-no-ansi")) RS \
ins(2, "Do not use ANSI escape codes.") RS \
ins(1, ansi("bold", "-no-theme")) RS \
ins(2, "Do not use any other theme than default.") RS \
ins(1, ansi("bold", "-theme " ansi("negative", "FILENAME"))) RS \
ins(2, "Specify the theme to use.") RS \
RS "Audio Options:" RS \
ins(1, ansi("bold", "-no-play")) RS \
ins(2, "Do not listen to the translation.") RS \
ins(1, ansi("bold", "-p, -play")) RS \
ins(2, "Listen to the translation.") RS \
ins(1, ansi("bold", "-player " ansi("negative", "PROGRAM"))) RS \
ins(2, "Specify the audio player to use, and listen to the translation.") RS \
RS "Terminal Paging and Web Options:" RS \
ins(1, ansi("bold", "-no-view")) RS \
ins(2, "Do not view the translation in a terminal pager.") RS \
ins(1, ansi("bold", "-v, -view")) RS \
ins(2, "View the translation in a terminal pager.") RS \
ins(1, ansi("bold", "-pager " ansi("negative", "PROGRAM"))) RS \
ins(2, "Specify the terminal pager to use, and view the translation.") RS \
ins(1, ansi("bold", "-browser " ansi("negative", "PROGRAM"))) RS \
ins(2, "Specify the web browser to use.") RS \
RS "Networking Options:" RS \
ins(1, ansi("bold", "-x " ansi("negative", "HOST:PORT") \
", -proxy " ansi("negative", "HOST:PORT"))) RS \
ins(2, "Use HTTP proxy on given port.") RS \
ins(1, ansi("bold", "-u " ansi("negative", "STRING") \
", -user-agent " ansi("negative", "STRING"))) RS \
ins(2, "Specify the User-Agent to identify as.") RS \
RS "Interactive Shell Options:" RS \
ins(1, ansi("bold", "-no-rlwrap")) RS \
ins(2, "Do not invoke rlwrap when starting an interactive shell.") RS \
ins(1, ansi("bold", "-I, -interactive, -shell")) RS \
ins(2, "Start an interactive shell.") RS \
ins(1, ansi("bold", "-E, -emacs")) RS \
ins(2, "Start the GNU Emacs front-end for an interactive shell.") RS \
RS "I/O Options:" RS \
ins(1, ansi("bold", "-i " ansi("negative", "FILENAME") \
", -input " ansi("negative", "FILENAME"))) RS \
ins(2, "Specify the input file.") RS \
ins(1, ansi("bold", "-o " ansi("negative", "FILENAME") \
", -output " ansi("negative", "FILENAME"))) RS \
ins(2, "Specify the output file.") RS \
RS "Language Preference Options:" RS \
ins(1, ansi("bold", "-l " ansi("negative", "CODE") \
", -lang " ansi("negative", "CODE"))) RS \
ins(2, "Specify your home language.") RS \
ins(1, ansi("bold", "-s " ansi("negative", "CODE") \
", -source " ansi("negative", "CODE"))) RS \
ins(2, "Specify the source language.") RS \
ins(1, ansi("bold", "-t " ansi("negative", "CODE(S)") \
", -target " ansi("negative", "CODE(S)"))) RS \
ins(2, "Specify the target language(s), joined by '+'.") RS \
RS "Other Options:" RS \
ins(1, ansi("bold", "-no-init")) RS \
ins(2, "Do not load any initialization script.") RS \
RS "See the man page " Command "(1) for more information."
}

# Display man page.
function showMan( temp) {
if (ENVIRON["TRANS_MANPAGE"]) {
initPager()
temp = "echo -E \"${TRANS_MANPAGE}\""
temp = temp PIPE \
"groff -Wall -mtty-char -mandoc -Tutf8 -rLL=${COLUMNS}n -rLT=${COLUMNS}n"
switch (Pager) {
case "less":
temp = temp PIPE Pager " -s -P\"\\ \\Manual page " Command "(1) line %lt (press h for help or q to quit)\""
break
case "most":
temp = temp PIPE Pager " -Cs"
break
default: # more
temp = temp PIPE Pager
}
system(temp)
} else if (system("man " Command SUPERR))
print getHelp()
}
10 changes: 5 additions & 5 deletions include/Languages.awk
Original file line number Diff line number Diff line change
Expand Up @@ -1395,12 +1395,12 @@ function parseLang(lang, code, group) {
}

# Initialize `UserLang`.
function initUserLang( locale) {
locale = ENVIRON["LANGUAGE"] ? ENVIRON["LANGUAGE"] :
function initUserLang() {
UserLocale = ENVIRON["LANGUAGE"] ? ENVIRON["LANGUAGE"] :
(ENVIRON["LC_ALL"] ? ENVIRON["LC_ALL"] :
(ENVIRON["LANG"] ? ENVIRON["LANG"] : "en_US.UTF-8"))
if (tolower(locale) !~ /utf-?8$/)
w("[WARNING] Your locale codeset (" locale ") is not UTF-8.")
if (tolower(UserLocale) !~ /utf-?8$/)
w("[WARNING] Your locale codeset (" UserLocale ") is not UTF-8.")

UserLang = parseLang(locale)
UserLang = parseLang(UserLocale)
}
4 changes: 0 additions & 4 deletions include/Main.awk
Original file line number Diff line number Diff line change
Expand Up @@ -539,10 +539,6 @@ BEGIN {
switch (InfoOnly) {
case "version":
print getVersion()
print
printf("%-22s%s\n", "gawk (GNU Awk)", PROCINFO["version"])
printf("%s\n", FriBidi ? FriBidi : "fribidi (GNU FriBidi) [NOT INSTALLED]")
printf("%-22s%s\n", "User Language", getName(UserLang) " (" getDisplay(UserLang) ")")
exit
case "help":
print getHelp()
Expand Down

0 comments on commit 467a56d

Please sign in to comment.