From fb9472131aa5f8ca53129d211f147231f58ca32d Mon Sep 17 00:00:00 2001 From: xnacly <47723417+xNaCly@users.noreply.github.com> Date: Tue, 4 Apr 2023 08:13:58 +0200 Subject: [PATCH] feat: new opt config.OnlyColorPrefix BREAKING CHANGE: this commit introduces the OnlyColorPrefix option, which allows the user to specify wheter or not to color the whole line of stdout+stderr of the process in its color. If it is set to true only the prefix (xx |) is highlighted in the processes color, if it is set to false the whole line is colored. By default this option is enabled to keep the output simple and clean, therefore this commit introduces a breaking change and requires a major version increment in the next release --- .gleichzeitig/config.json | 29 +++++++++++++++-------------- README.md | 2 ++ config.go | 12 +++++++----- util.go | 4 ++++ 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/.gleichzeitig/config.json b/.gleichzeitig/config.json index 35f6f67..19504f4 100644 --- a/.gleichzeitig/config.json +++ b/.gleichzeitig/config.json @@ -1,15 +1,16 @@ { - "color_output": true, - "commands": [ - { - "cwd": "", - "cmd": "echo 'Hello World from command 1!'" - }, - { - "cwd": "", - "cmd": "echo 'Hello World from command 2!'" - } - ], - "log_file": "gleich.log", - "surpress_output": false -} + "only_color_prefix": true, + "color_output": true, + "commands": [ + { + "cwd": "", + "cmd": "echo 'Hello World from command 1!'" + }, + { + "cwd": "", + "cmd": "echo 'Hello World from command 2!'" + } + ], + "log_file": "gleich.log", + "surpress_output": false +} \ No newline at end of file diff --git a/README.md b/README.md index a386ce4..fc21991 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,7 @@ The configuration is located at `.gleichzeitig/config.json` in the current worki ```json { + "only_color_prefix": true, "color_output": true, "commands": [], "log_file": "", @@ -67,6 +68,7 @@ The configuration is located at `.gleichzeitig/config.json` in the current worki } ``` +- `only_color_prefix`: wheter to color the full stdout and stderr prints or only the prefixes: `0x |` - `color_output`: whether the output of the individual commands should be coloured different to allow the user to differentiate between them - `commands`: array of instructions _gleichzeitig_ executes, of the following format: ```json diff --git a/config.go b/config.go index 0e49129..f106343 100644 --- a/config.go +++ b/config.go @@ -6,10 +6,11 @@ import ( ) type Config struct { - ColorOutput bool `json:"color_output"` - Commands []Command `json:"commands"` - LogFile string `json:"log_file"` - SurpressOutput bool `json:"surpress_output"` + OnlyColorPrefix bool `json:"only_color_prefix"` + ColorOutput bool `json:"color_output"` + Commands []Command `json:"commands"` + LogFile string `json:"log_file"` + SurpressOutput bool `json:"surpress_output"` } type Command struct { @@ -20,7 +21,8 @@ type Command struct { const CONFIG_PATH = ".gleichzeitig/config.json" var DEFAULT_CONFIG = Config{ - ColorOutput: true, + OnlyColorPrefix: true, + ColorOutput: true, Commands: []Command{ { Cmd: "echo 'Hello World from command 1!'", diff --git a/util.go b/util.go index 08a3b7d..de0b28f 100644 --- a/util.go +++ b/util.go @@ -45,6 +45,10 @@ func commandPrint(index int, text string) { } if CONFIG.ColorOutput { + if CONFIG.OnlyColorPrefix { + log.Printf("%s%s |%s %s\n", colors[index%len(colors)], i, ANSI_RESET, text) + return + } log.Printf("%s%s | %s%s\n", colors[index%len(colors)], i, text, ANSI_RESET) } else { log.Printf("%s | %s\n", i, text)