-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c87910
commit 5d42eb7
Showing
16 changed files
with
306 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package color | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
) | ||
|
||
const colorFmt = "\x1b[%dm%s\x1b[0m" | ||
|
||
// Paint describes a terminal color. | ||
type Paint int | ||
|
||
// Colorize returns an ASCII colored string based on given color. | ||
func Colorize(s string, c Paint) string { | ||
|
||
if c == 0 { | ||
return s | ||
} | ||
return fmt.Sprintf(colorFmt, c, s) | ||
} | ||
|
||
func ColorizeAt(s string, idx int, color string) string { | ||
if len(s) <= idx { | ||
return s | ||
} | ||
//colr := color.New(c).FprintfFunc() | ||
|
||
chrs := []rune(s) | ||
left := string(chrs[:idx]) | ||
|
||
mid := fmt.Sprintf("[-:-:-][%s::b]%s[-:-:-]", color, string(chrs[idx])) | ||
right := string(chrs[idx+1:]) | ||
return fmt.Sprintf("%s%s%s", left, mid, right) | ||
} | ||
|
||
// ANSIColorize colors a string. | ||
func ANSIColorize(text string, color int) string { | ||
return "\033[38;5;" + strconv.Itoa(color) + "m" + text + "\033[0m" | ||
} | ||
|
||
// Highlight colorize bytes at given indices. | ||
func Highlight(bb []byte, ii []int, c int) []byte { | ||
b := make([]byte, 0, len(bb)) | ||
for i, j := 0, 0; i < len(bb); i++ { | ||
if j < len(ii) && ii[j] == i { | ||
b = append(b, colorizeByte(bb[i], 209)...) | ||
j++ | ||
} else { | ||
b = append(b, bb[i]) | ||
} | ||
} | ||
|
||
return b | ||
} | ||
|
||
func colorizeByte(b byte, color int) []byte { | ||
return []byte(ANSIColorize(string(b), color)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package render | ||
|
||
func runesToNum(rr []rune) int64 { | ||
var r int64 | ||
var m int64 = 1 | ||
for i := len(rr) - 1; i >= 0; i-- { | ||
v := int64(rr[i] - '0') | ||
r += v * m | ||
m *= 10 | ||
} | ||
|
||
return r | ||
} | ||
|
||
func durationToSeconds(duration string) int64 { | ||
if len(duration) == 0 { | ||
return 0 | ||
} | ||
|
||
num := make([]rune, 0, 5) | ||
var n, m int64 | ||
for _, r := range duration { | ||
switch r { | ||
case 'y': | ||
m = 365 * 24 * 60 * 60 | ||
case 'd': | ||
m = 24 * 60 * 60 | ||
case 'h': | ||
m = 60 * 60 | ||
case 'm': | ||
m = 60 | ||
case 's': | ||
m = 1 | ||
default: | ||
num = append(num, r) | ||
continue | ||
} | ||
n, num = n+runesToNum(num)*m, num[:0] | ||
} | ||
|
||
return n | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.