aboutsummaryrefslogtreecommitdiffstats
path: root/utils.go
diff options
context:
space:
mode:
Diffstat (limited to 'utils.go')
-rw-r--r--utils.go53
1 files changed, 52 insertions, 1 deletions
diff --git a/utils.go b/utils.go
index e09456e..6bf0015 100644
--- a/utils.go
+++ b/utils.go
@@ -1,6 +1,11 @@
package main
-import "github.com/lrstanley/girc"
+import (
+ "fmt"
+ "strings"
+
+ "github.com/lrstanley/girc"
+)
func IrcJoin(irc *girc.Client, channel []string) {
if len(channel) > 1 && channel[1] != "" {
@@ -9,3 +14,49 @@ func IrcJoin(irc *girc.Client, channel []string) {
irc.Cmd.Join(channel[0])
}
}
+
+func chunker(inputString string, chromaFormatter string) []string {
+ chunks := strings.Split(inputString, "\n")
+
+ switch chromaFormatter {
+ case "terminal":
+ fallthrough
+ case "terminal8":
+ fallthrough
+ case "terminal16":
+ fallthrough
+ case "terminal256":
+ for count, chunk := range chunks {
+ lastColorCode, err := extractLast256ColorEscapeCode(chunk)
+ if err != nil {
+ continue
+ }
+
+ if count <= len(chunks)-2 {
+ chunks[count+1] = fmt.Sprintf("\033[38;5;%sm", lastColorCode) + chunks[count+1]
+ }
+ }
+ case "terminal16m":
+ fallthrough
+ default:
+ }
+
+ return chunks
+}
+
+func SendToIRC(
+ client *girc.Client,
+ event girc.Event,
+ message string,
+ chromaFormatter string,
+) {
+ chunks := chunker(message, chromaFormatter)
+
+ for _, chunk := range chunks {
+ if len(strings.TrimSpace(chunk)) == 0 {
+ continue
+ }
+
+ client.Cmd.Reply(event, chunk)
+ }
+}