refactor: make background color optional

This commit is contained in:
Jan De Dobbeleer 2020-09-21 10:20:18 +02:00 committed by Jan De Dobbeleer
parent f5482dc1da
commit bbeba938f6
17 changed files with 23 additions and 104 deletions

View file

@ -8,7 +8,6 @@
"type": "path",
"style": "plain",
"foreground": "#ffffff",
"background": "#193549",
"properties": {
"prefix": "",
"home_icon": "~",
@ -19,7 +18,6 @@
"type": "git",
"style": "plain",
"foreground": "#C2C206",
"background": "#193549",
"properties": {
"branch_icon": "",
"branch_identical_icon": "≡",
@ -34,7 +32,6 @@
"type": "root",
"style": "plain",
"foreground": "#B5B50D",
"background": "#193549",
"properties": {
"root_icon": "⚡"
}
@ -43,7 +40,6 @@
"type": "exit",
"style": "plain",
"foreground": "#C94A16",
"background": "#193549",
"properties": {
"error_icon": "x"
}
@ -61,7 +57,6 @@
"type": "text",
"style": "plain",
"foreground": "#007ACC",
"background": "#193549",
"properties": {
"prefix": "",
"text": "▶"
@ -70,6 +65,5 @@
]
}
],
"console_background_color": "#193549",
"end_space_enabled": true
}

View file

@ -8,7 +8,6 @@
"type": "session",
"style": "plain",
"foreground": "#ffffff",
"background": "#193549",
"properties": {
"user_info_separator": "",
"display_computer": false,
@ -20,7 +19,6 @@
"type": "git",
"style": "plain",
"foreground": "#ffffff",
"background": "#193549",
"properties": {
"branch_icon": "",
"branch_identical_icon": "≡",
@ -37,7 +35,6 @@
"type": "root",
"style": "plain",
"foreground": "#ffffff",
"background": "#193549",
"properties": {
"root_icon": "⚡",
"prefix": "<#CB4B16>[</>",
@ -48,7 +45,6 @@
"type": "exit",
"style": "plain",
"foreground": "#ffffff",
"background": "#193549",
"properties": {
"error_icon": "x",
"prefix": "<#CB4B16>[</>",
@ -68,7 +64,6 @@
"type": "path",
"style": "plain",
"foreground": "#ffffff",
"background": "#193549",
"properties": {
"home_icon": "~",
"style": "short",
@ -79,6 +74,5 @@
]
}
],
"console_background_color": "#193549",
"end_space_enabled": true
}

View file

@ -8,7 +8,6 @@
"type": "time",
"style": "plain",
"foreground": "#E5C07B",
"background": "#193549",
"properties": {
"time_format": "15:04:05",
"prefix": "[ ",
@ -19,7 +18,6 @@
"type": "root",
"style": "plain",
"foreground": "#B5B50D",
"background": "#193549",
"properties": {
"root_icon": "⚡"
}
@ -28,7 +26,6 @@
"type": "path",
"style": "plain",
"foreground": "#61AFEF",
"background": "#193549",
"properties": {
"home_icon": "~",
"style": "agnoster",
@ -39,7 +36,6 @@
"type": "git",
"style": "plain",
"foreground": "#F3C267",
"background": "#193549",
"properties": {
"branch_icon": "🚦 ",
"display_status": true,
@ -55,7 +51,6 @@
"type": "exit",
"style": "plain",
"foreground": "#C94A16",
"background": "#193549",
"properties": {
"error_icon": "x"
}
@ -64,7 +59,6 @@
"type": "text",
"style": "plain",
"foreground": "#E06C75",
"background": "#193549",
"properties": {
"prefix": "",
"text": " "
@ -73,6 +67,5 @@
]
}
],
"console_background_color": "#193549",
"end_space_enabled": true
}

View file

@ -9,7 +9,6 @@
"type": "exit",
"style": "plain",
"foreground": "#ffffff",
"background": "#193549",
"properties": {
"error_icon": " ",
"postfix": ""
@ -19,7 +18,6 @@
"type": "root",
"style": "plain",
"foreground": "#100e23",
"background": "#193549",
"properties": {
"root_icon": "襁"
}
@ -28,7 +26,6 @@
"type": "session",
"style": "plain",
"foreground": "#ffffff",
"background": "#193549",
"properties": {
"user_info_separator": "@"
}
@ -69,7 +66,6 @@
"type": "text",
"style": "plain",
"foreground": "#007ACC",
"background": "#193549",
"properties": {
"prefix": "",
"text": ""
@ -77,6 +73,5 @@
}
]
}
],
"console_background_color": "#193549"
]
}

View file

@ -8,7 +8,6 @@
"type": "session",
"style": "plain",
"foreground": "#FFFFFF",
"background": "#193549",
"properties": {
"user_info_separator": " <#ffffff>in</> ",
"prefix": "<#0377C8># </>",
@ -20,7 +19,6 @@
"type": "path",
"style": "plain",
"foreground": "#0973C0",
"background": "#193549",
"properties": {
"home_icon": "~",
"folder_icon": "",
@ -33,7 +31,6 @@
"type": "git",
"style": "plain",
"foreground": "#B8B80A",
"background": "#193549",
"properties": {
"branch_icon": "",
"branch_identical_icon": "≡",
@ -55,7 +52,6 @@
"type": "time",
"style": "plain",
"foreground": "#ffffff",
"background": "#193549",
"properties": {
"prefix": "[",
"postfix": "]"
@ -74,7 +70,6 @@
"type": "root",
"style": "plain",
"foreground": "#CECE04",
"background": "#193549",
"properties": {
"prefix": "",
"root_icon": "襁"
@ -84,7 +79,6 @@
"type": "virtualenv",
"style": "plain",
"foreground": "#100e23",
"background": "#193549",
"properties": {
"prefix": "",
"python_icon": ""
@ -94,7 +88,6 @@
"type": "exit",
"style": "plain",
"foreground": "#CB4B16",
"background": "#193549",
"properties": {
"prefix": "",
"error_icon": ""
@ -104,7 +97,6 @@
"type": "text",
"style": "plain",
"foreground": "#CC4B16",
"background": "#193549",
"properties": {
"prefix": "",
"text": "→"
@ -113,6 +105,5 @@
]
}
],
"console_background_color": "#193549",
"end_space_enabled": true
}

View file

@ -8,8 +8,8 @@
"type": "text",
"style": "plain",
"foreground": "#F5F5F5",
"background": "#193549",
"properties": {
"prefix": "",
"text": "ﬦ"
}
},
@ -17,7 +17,6 @@
"type": "path",
"style": "plain",
"foreground": "#B80101",
"background": "#193549",
"properties": {
"style": "agnoster"
}
@ -26,7 +25,6 @@
"type": "git",
"style": "plain",
"foreground": "#B80101",
"background": "#193549",
"properties": {
"branch_icon": "",
"branch_identical_icon": "≡",
@ -41,6 +39,5 @@
]
}
],
"console_background_color": "#193549",
"end_space_enabled": true
}

View file

@ -8,7 +8,6 @@
"type": "text",
"style": "plain",
"foreground": "#ffffff",
"background": "#193549",
"properties": {
"text": "<#C591E8>❭</><#69FF94>❭</>"
}
@ -17,7 +16,6 @@
"type": "path",
"style": "plain",
"foreground": "#56B6C2",
"background": "#193549",
"properties": {
"style": "folder"
}
@ -26,7 +24,6 @@
"type": "git",
"style": "plain",
"foreground": "#D0666F",
"background": "#193549",
"properties": {
"branch_icon": "",
"display_status": false,
@ -38,7 +35,6 @@
"type": "exit",
"style": "plain",
"foreground": "#DCB977",
"background": "#193549",
"properties": {
"error_icon": "✗",
"display_error_code": false
@ -48,7 +44,6 @@
"type": "time",
"style": "plain",
"foreground": "#66F68F",
"background": "#193549",
"properties": {
"time_format": "15:04"
}
@ -56,6 +51,5 @@
]
}
],
"console_background_color": "#193549",
"end_space_enabled": true
}

View file

@ -82,7 +82,6 @@
"type": "text",
"style": "plain",
"foreground": "#007ACC",
"background": "#193549",
"properties": {
"prefix": "",
"text": ""

View file

@ -8,7 +8,6 @@
"type": "text",
"style": "plain",
"foreground": "#ffffff",
"background": "#193549",
"properties": {
"prefix": "",
"text": "<#C591E8>❭</><#69FF94>❭</>"
@ -18,7 +17,6 @@
"type": "path",
"style": "plain",
"foreground": "#56B6C2",
"background": "#193549",
"properties": {
"style": "folder"
}
@ -27,7 +25,6 @@
"type": "git",
"style": "plain",
"foreground": "#D0666F",
"background": "#193549",
"properties": {
"branch_icon": "",
"display_status": false,
@ -39,7 +36,6 @@
"type": "exit",
"style": "plain",
"foreground": "#DCB977",
"background": "#193549",
"properties": {
"error_icon": "✗",
"display_error_code": false
@ -55,7 +51,6 @@
"type": "command",
"style": "plain",
"foreground": "#ffffff",
"background": "#193549",
"properties": {
"shell": "bash",
"command": "git log --pretty=format:%cr -1 || date +%H:%m:%S"
@ -74,15 +69,13 @@
"type": "text",
"style": "plain",
"foreground": "#ffffff",
"background": "#193549",
"properties": {
"prefix": "",
"text": " "
"text": ""
}
}
]
}
],
"console_background_color": "#193549",
"end_space_enabled": true
}

View file

@ -91,7 +91,6 @@
"type": "exit",
"style": "plain",
"foreground": "#D4E157",
"background": "#193549",
"properties": {
"prefix": "",
"error_icon": "",
@ -102,7 +101,5 @@
}
]
}
],
"console_background_color": "#193549",
"end_space_enabled": true
]
}

View file

@ -9,7 +9,6 @@
"type": "time",
"style": "plain",
"foreground": "#00C5C7",
"background": "#193549",
"properties": {
"time_format": "15:04:05"
}
@ -28,7 +27,6 @@
"type": "path",
"style": "plain",
"foreground": "#77E4F7",
"background": "#193549",
"properties": {
"prefix": "",
"home_icon": "~",
@ -39,8 +37,8 @@
"type": "git",
"style": "plain",
"foreground": "#FFE700",
"background": "#193549",
"properties": {
"prefix": "",
"branch_icon": "",
"branch_identical_icon": "≡",
"branch_ahead_icon": "↑",
@ -54,14 +52,12 @@
"type": "text",
"style": "plain",
"foreground": "#43D426",
"background": "#193549",
"properties": {
"prefix": "",
"text": ""
}
}
]
}
],
"console_background_color": "#193549",
"end_space_enabled": true
]
}

View file

@ -9,7 +9,6 @@
"type": "root",
"style": "plain",
"foreground": "#FFEE58",
"background": "#193549",
"properties": {
"root_icon": "襁"
}
@ -18,7 +17,6 @@
"type": "session",
"style": "plain",
"foreground": "#ffffff",
"background": "#193549",
"properties": {
"user_info_separator": "@"
}

View file

@ -8,16 +8,15 @@
"type": "text",
"style": "plain",
"foreground": "#98C379",
"background": "#193549",
"properties": {
"text": "→"
"text": "→",
"postfix": ""
}
},
{
"type": "path",
"style": "plain",
"foreground": "#56B6C2",
"background": "#193549",
"properties": {
"style": "folder"
}
@ -26,7 +25,6 @@
"type": "git",
"style": "plain",
"foreground": "#D0666F",
"background": "#193549",
"properties": {
"branch_icon": "",
"display_status": false,
@ -38,7 +36,6 @@
"type": "exit",
"style": "plain",
"foreground": "#DCB977",
"background": "#193549",
"properties": {
"error_icon": "✗",
"display_error_code": false
@ -47,6 +44,5 @@
]
}
],
"console_background_color": "#193549",
"end_space_enabled": true
}

View file

@ -8,7 +8,6 @@
"type": "exit",
"style": "plain",
"foreground": "#CB4B16",
"background": "#193549",
"properties": {
"error_icon": ""
}
@ -17,7 +16,6 @@
"type": "root",
"style": "plain",
"foreground": "#CECE04",
"background": "#193549",
"properties": {
"root_icon": "襁"
}
@ -26,7 +24,6 @@
"type": "session",
"style": "plain",
"foreground": "#FFFFFF",
"background": "#193549",
"properties": {
"user_info_separator": "@"
}
@ -35,7 +32,6 @@
"type": "path",
"style": "plain",
"foreground": "#0973C0",
"background": "#193549",
"properties": {
"home_icon": "",
"folder_icon": "",
@ -48,7 +44,6 @@
"type": "git",
"style": "plain",
"foreground": "#C1C106",
"background": "#193549",
"properties": {
"branch_icon": "",
"branch_identical_icon": "≡",
@ -64,7 +59,6 @@
"type": "virtualenv",
"style": "plain",
"foreground": "#100e23",
"background": "#193549",
"properties": {
"python_icon": ""
}
@ -73,14 +67,12 @@
"type": "text",
"style": "plain",
"foreground": "#ffffff",
"background": "#193549",
"properties": {
"prefix": "",
"text": "<#CB4B16>❭</><#CACA02>❭</><#4E9A06>❭</>"
}
}
]
}
],
"console_background_color": "#193549",
"end_space_enabled": true
]
}

View file

@ -8,7 +8,6 @@
"type": "path",
"style": "plain",
"foreground": "#ffffff",
"background": "#193549",
"properties": {
"prefix": "",
"home_icon": "~",
@ -20,7 +19,6 @@
"type": "git",
"style": "plain",
"foreground": "#F3C267",
"background": "#193549",
"properties": {
"branch_icon": "",
"display_status": false,
@ -31,7 +29,6 @@
"type": "command",
"style": "plain",
"foreground": "#C49EE9",
"background": "#193549",
"properties": {
"shell": "bash",
"command": "find . -name package.json -depth 1 -exec echo \" <#ffffff>via node</>\" \\;"
@ -41,7 +38,6 @@
"type": "root",
"style": "plain",
"foreground": "#B5B50D",
"background": "#193549",
"properties": {
"root_icon": "⚡"
}
@ -50,7 +46,6 @@
"type": "exit",
"style": "plain",
"foreground": "#C94A16",
"background": "#193549",
"properties": {
"error_icon": "x"
}
@ -68,7 +63,6 @@
"type": "text",
"style": "plain",
"foreground": "#63F08C",
"background": "#193549",
"properties": {
"prefix": "",
"text": "→"
@ -76,7 +70,5 @@
}
]
}
],
"console_background_color": "#193549",
"end_space_enabled": true
]
}

View file

@ -8,7 +8,6 @@
"type": "session",
"style": "plain",
"foreground": "#E36464",
"background": "#193549",
"properties": {
"user_info_separator": "",
"display_computer": false,
@ -19,7 +18,6 @@
"type": "text",
"style": "plain",
"foreground": "#62ED8B",
"background": "#193549",
"properties": {
"text": "→",
"postfix": "",
@ -30,7 +28,6 @@
"type": "path",
"style": "plain",
"foreground": "#56B6C2",
"background": "#193549",
"properties": {
"style": "folder",
"postfix": ""
@ -40,7 +37,6 @@
"type": "git",
"style": "plain",
"foreground": "#D4AAFC",
"background": "#193549",
"properties": {
"branch_icon": "",
"display_status": false,
@ -52,15 +48,14 @@
"type": "exit",
"style": "plain",
"foreground": "#DCB977",
"background": "#193549",
"properties": {
"error_icon": "✗",
"display_error_code": false
"display_error_code": false,
"postfix": ""
}
}
]
}
],
"console_background_color": "#193549",
"end_space_enabled": true
}

View file

@ -14,9 +14,15 @@ type ColorWriter struct {
}
func (w *ColorWriter) writeColoredText(background string, foreground string, text string) {
style := color.HEXStyle(foreground, background)
text = style.Sprint(text)
w.Buffer.WriteString(text)
var coloredText string
if background != "" {
style := color.HEXStyle(foreground, background)
coloredText = style.Sprint(text)
} else {
style := color.HEX(foreground)
coloredText = style.Sprint(text)
}
w.Buffer.WriteString(coloredText)
}
func (w *ColorWriter) writeAndRemoveText(background string, foreground string, text string, textToRemove string, parentText string) string {
@ -25,9 +31,6 @@ func (w *ColorWriter) writeAndRemoveText(background string, foreground string, t
}
func (w *ColorWriter) write(background string, foreground string, text string) {
style := color.HEXStyle(foreground, background)
text = style.Sprint(text)
r := regexp.MustCompile(`<\s*(?P<color>#[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})>(?P<text>.*?)<\s*/\s*>`)
match := r.FindAllStringSubmatch(text, -1)
for i := range match {