Skip to content

Commit

Permalink
colorize cache hint
Browse files Browse the repository at this point in the history
  • Loading branch information
sbreitf1 committed Feb 13, 2024
1 parent 67621d1 commit 779f873
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Util to show current worktime and possible leave times with Matrix integration.
To download and install the utility execute the following commands:

```
go install github.com/sbreitf1/[email protected].2
go install github.com/sbreitf1/[email protected].3
```

Now start it with `gohome` from command line.
Expand Down
6 changes: 6 additions & 0 deletions colors.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type colorsDef struct {
ComeEntry string
LeaveEntry string
TripEntry string
CacheHint string
WorkTime string
BreakEntry string
BreakInfo string
Expand Down Expand Up @@ -44,6 +45,8 @@ func initColors() {
func disableColors() {
colors.ComeEntry = ""
colors.LeaveEntry = ""
colors.TripEntry = ""
colors.CacheHint = ""
colors.WorkTime = ""
colors.BreakEntry = ""
colors.BreakInfo = ""
Expand All @@ -57,6 +60,7 @@ func setDefaultColors() {
colors.ComeEntry = "\033[2;32m"
colors.LeaveEntry = "\033[2;31m"
colors.TripEntry = "\033[2;33m"
colors.CacheHint = "\033[2;37m"
colors.WorkTime = "\033[1;37m"
colors.BreakEntry = "\033[2;37m"
colors.BreakInfo = "\033[1;30m"
Expand Down Expand Up @@ -109,6 +113,7 @@ func shortenColors(colors colorsDef) colorsDef {
ComeEntry: strings.ReplaceAll(strings.ReplaceAll(colors.ComeEntry, "\033[", ""), "m", ""),
LeaveEntry: strings.ReplaceAll(strings.ReplaceAll(colors.LeaveEntry, "\033[", ""), "m", ""),
TripEntry: strings.ReplaceAll(strings.ReplaceAll(colors.TripEntry, "\033[", ""), "m", ""),
CacheHint: strings.ReplaceAll(strings.ReplaceAll(colors.TripEntry, "\033[", ""), "m", ""),
WorkTime: strings.ReplaceAll(strings.ReplaceAll(colors.WorkTime, "\033[", ""), "m", ""),
BreakEntry: strings.ReplaceAll(strings.ReplaceAll(colors.BreakEntry, "\033[", ""), "m", ""),
BreakInfo: strings.ReplaceAll(strings.ReplaceAll(colors.BreakInfo, "\033[", ""), "m", ""),
Expand All @@ -122,6 +127,7 @@ func importColors(dst *colorsDef, src colorsDef) {
importColor(&dst.ComeEntry, src.ComeEntry, "ComeEntry")
importColor(&dst.LeaveEntry, src.LeaveEntry, "LeaveEntry")
importColor(&dst.TripEntry, src.TripEntry, "TripEntry")
importColor(&dst.CacheHint, src.CacheHint, "CacheHint")
importColor(&dst.WorkTime, src.WorkTime, "WorkTime")
importColor(&dst.BreakEntry, src.BreakEntry, "BreakEntry")
importColor(&dst.BreakInfo, src.BreakInfo, "BreakInfo")
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func process() error {

console.Println("-----------------------------------------------------")
if cacheOK {
console.Printlnf("time now: %s (cache from %s)", time.Now().Format("15:04"), cacheTime.Format("15:04:05"))
console.Printlnf("time now: %s %s(cache from %s)%s", time.Now().Format("15:04"), colors.CacheHint, cacheTime.Format("15:04:05"), colorEnd)
} else {
console.Printlnf("time now: %s", time.Now().Format("15:04"))
}
Expand Down

0 comments on commit 779f873

Please sign in to comment.