Skip to content

Commit

Permalink
feat: new opt config.OnlyColorPrefix
Browse files Browse the repository at this point in the history
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
  • Loading branch information
xNaCly committed Apr 4, 2023
1 parent 6d525fc commit fb94721
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
29 changes: 15 additions & 14 deletions .gleichzeitig/config.json
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ The configuration is located at `.gleichzeitig/config.json` in the current worki

```json
{
"only_color_prefix": true,
"color_output": true,
"commands": [],
"log_file": "",
"surpress_output": false
}
```

- `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
Expand Down
12 changes: 7 additions & 5 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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!'",
Expand Down
4 changes: 4 additions & 0 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit fb94721

Please sign in to comment.