mirror of https://github.com/Rudi9719/kbtui.git
Browse Source
- Created new file colors.go - Added color options to the UserConfig - Possible to disable colors (in UserConfig) - Fixed a bug where the login screen says `/j` and not `{cmdChar}j` - Changed how attachments look - so it's clear it isn't just a message saying that - Changed how formatOutput works (to be more DRY) - Colored unread messages Changes to be committed: new file: colors.go modified: main.go modified: userConfigs.gopull/5/head
Casper Weiss Bang
5 years ago
3 changed files with 89 additions and 29 deletions
@ -0,0 +1,42 @@ |
|||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
"regexp" |
||||||
|
) |
||||||
|
|
||||||
|
// TODO maybe datastructure
|
||||||
|
// BASH-like PS1 variable equivalent (without colours)
|
||||||
|
// TODO bold? cursive etc?
|
||||||
|
func color(c int) string { |
||||||
|
if colorless { |
||||||
|
return "" |
||||||
|
} |
||||||
|
if c < 0 { |
||||||
|
return "\033[0m" |
||||||
|
} else { |
||||||
|
return fmt.Sprintf("\033[0;%dm", 29+c) |
||||||
|
} |
||||||
|
} |
||||||
|
// TODO maybe make the text into some datastructure which remembers the color
|
||||||
|
func colorText(text string, color string, offColor string) string { |
||||||
|
return fmt.Sprintf("%s%s%s", color, text, offColor) |
||||||
|
} |
||||||
|
|
||||||
|
func colorUsername(username string, offColor string) string { |
||||||
|
var color = messageSenderDefaultColor |
||||||
|
if username == k.Username { |
||||||
|
color = mentionColor |
||||||
|
} |
||||||
|
return colorText(username, color, offColor) |
||||||
|
} |
||||||
|
func colorRegex(msg string, match string, color string, offColor string) string { |
||||||
|
var re = regexp.MustCompile(match) |
||||||
|
return re.ReplaceAllString(msg, colorText(`$1`, color, offColor)) |
||||||
|
} |
||||||
|
|
||||||
|
func colorReplaceMentionMe(msg string, offColor string) string { |
||||||
|
//var coloredOwnName = colorText(k.Username, mentionColor, offColor)
|
||||||
|
//return strings.Replace(msg, k.Username, coloredOwnName, -1)
|
||||||
|
return colorRegex(msg, "(@?"+k.Username+")", mentionColor, offColor) |
||||||
|
} |
Loading…
Reference in new issue