65 lines
1.2 KiB
Go
65 lines
1.2 KiB
Go
package utilities
|
|
|
|
import (
|
|
"strings"
|
|
"time"
|
|
"unicode"
|
|
|
|
"golang.org/x/net/html"
|
|
)
|
|
|
|
const (
|
|
reset = "\033[0m"
|
|
boldblue = "\033[34;1m"
|
|
)
|
|
|
|
func StripHTMLTags(text string) string {
|
|
token := html.NewTokenizer(strings.NewReader(text))
|
|
|
|
var builder strings.Builder
|
|
|
|
for {
|
|
tt := token.Next()
|
|
switch tt {
|
|
case html.ErrorToken:
|
|
return builder.String()
|
|
case html.TextToken:
|
|
builder.WriteString(token.Token().Data + " ")
|
|
}
|
|
}
|
|
}
|
|
|
|
func WrapLine(line, separator string, charLimit int) string {
|
|
if len(line) <= charLimit {
|
|
return line
|
|
}
|
|
|
|
leftcursor, rightcursor := 0, 0
|
|
|
|
var builder strings.Builder
|
|
|
|
for rightcursor < (len(line) - charLimit) {
|
|
rightcursor += charLimit
|
|
for !unicode.IsSpace(rune(line[rightcursor-1])) {
|
|
rightcursor--
|
|
}
|
|
builder.WriteString(line[leftcursor:rightcursor] + separator)
|
|
leftcursor = rightcursor
|
|
}
|
|
|
|
builder.WriteString(line[rightcursor:])
|
|
|
|
return builder.String()
|
|
}
|
|
|
|
func Header(text string) string {
|
|
return boldblue + text + reset
|
|
}
|
|
|
|
func FormatDate(date time.Time) string {
|
|
return date.Local().Format("02 Jan 2006")
|
|
}
|
|
|
|
func FormatTime(date time.Time) string {
|
|
return date.Local().Format("02 Jan 2006, 15:04 (MST)")
|
|
}
|