Added '-no-colors' flag

main
lcomrade 12 months ago
parent 561c5438f7
commit 62c03bcd2b
  1. 2
      build/unix-like/share/bash-completion/completions/horizon
  2. 9
      cmd/horizon.go
  3. 3
      docs/man/man1/horizon.1
  4. 2
      internal/locale/locale.go
  5. 9
      internal/logger/logger.go
  6. 7
      internal/settings/settings.go
  7. 11
      pkg/colors/colors.go

@ -19,7 +19,7 @@ _horizon_completions(){
done
COMPREPLY=($(compgen -W "-config-dir -dir -info -version" -- "${COMP_WORDS[COMP_CWORD]}"))
COMPREPLY=($(compgen -W "-config-dir -dir -no-colors -info -version -help" -- "${COMP_WORDS[COMP_CWORD]}"))
}
complete -o nospace -F _horizon_completions horizon

@ -77,7 +77,7 @@ func ConvertFileSize(size int64) string {
}
sizeStr1, sizeStr2 := filesize.HumanReadable(size)
if sizeStr2 == "TB" {
return sizeStr1 + " " + locale.TB
}
@ -93,7 +93,7 @@ func ConvertFileSize(size int64) string {
if sizeStr2 == "KB" {
return sizeStr1 + " " + locale.KB
}
return sizeStr1 + " " + sizeStr2
}
@ -205,6 +205,11 @@ func main() {
//Logging
logger.SetLevel(settings.Config.Logging.Level)
//Console setup
if *settings.ArgNoColors != true {
logger.UseColors()
}
//## WEB SERVER ##
//Handlers assignment
http.HandleFunc("/", MainHandler)

@ -17,6 +17,9 @@ horizon [OPTIONS]...
-dir
Specifies the custom root directory of the WEB server. Default: "."
.PP
-no-colors
Disable colorized console output
.PP
-info
Display build info and exit
.PP

@ -39,6 +39,7 @@ var Load_file = "Load file"
var Env_var_is_empty = "environment variable is empty"
var Dir_flag = "Specifies the custom directory"
var Config_dir_flag = "Specifies the custom directory with configuration files"
var No_colors_flag = "Disable colorized console output"
var Info_flag = "Display build info and exit"
var Version_flag = "Display version and exit"
var Help_flag = "Help version and exit"
@ -69,6 +70,7 @@ func getTranslate() {
Env_var_is_empty = "переменная окружения пуста"
Dir_flag = "Указывает директорию"
Config_dir_flag = "Указывает директорию с конфигурационными файлами"
No_colors_flag = "Отключает цветной вывод в консоль"
Info_flag = "Напечатать информацию о сборке и выйти"
Version_flag = "Напечатать версию и выйти"
Help_flag = "Напечатать справку и выйти"

@ -20,6 +20,7 @@
package logger
import (
"../../pkg/colors"
"io/ioutil"
"log"
"os"
@ -49,3 +50,11 @@ func SetLevel(level string) {
return
}
func UseColors() {
Info.SetPrefix(colors.Green + "INFO" + colors.Normal + "\t")
Warning.SetPrefix(colors.Yellow + "WARNING" + colors.Normal + "\t")
Error.SetPrefix(colors.Red + "ERROR" + colors.Normal + "\t")
Request.SetPrefix(colors.Blue + "REQUEST" + colors.Normal + "\t")
}

@ -172,6 +172,7 @@ func GetHtmlPageTemplate(indexHtmlFilePath string) *template.Template {
//Global vars
var ArgDir *string
var ArgConfigDir *string
var ArgNoColors *bool
var Config ConfigType
var HtmlTemplate *template.Template
var ResourcesDir string
@ -183,11 +184,17 @@ func Main() {
//Flags
ArgDir = flag.String("dir", ".", locale.Dir_flag)
ArgConfigDir = flag.String("config-dir", "", locale.Config_dir_flag)
ArgNoColors = flag.Bool("no-colors", false, locale.No_colors_flag)
argInfo := flag.Bool("info", false, locale.Info_flag)
argVersion := flag.Bool("version", false, locale.Version_flag)
argHelp := flag.Bool("help", false, locale.Help_flag)
flag.Parse()
//Console setup
if *ArgNoColors != true {
logger.UseColors()
}
//Displaying the build information
if *argInfo == true {
fmt.Println("Name:", build.Name)

@ -0,0 +1,11 @@
package colors
// Console colors
const (
Red = "\033[1;31m"
Green = "\033[1;32m"
Yellow = "\033[1;33m"
Blue = "\033[1;34m"
Normal = "\033[0m"
)
Loading…
Cancel
Save