Skip to content

Commit

Permalink
fix color triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
Edru2 committed Mar 27, 2024
1 parent ca51128 commit 8f94b3e
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions TriggerFunctions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -30,6 +31,11 @@ func convertToJSONTrigger(parentDir string, trigger Trigger) JSONTrigger {
Pattern: content,
Type: patternNumberToType(trigger.RegexCodeProperties[i]),
}

if jsonPattern.Type == "colour" {
jsonPattern.Pattern = extractColorTriggerColors(content)
}

jsonTrigger.Patterns = append(jsonTrigger.Patterns, jsonPattern)
}

Expand All @@ -47,6 +53,62 @@ func convertToJSONTrigger(parentDir string, trigger Trigger) JSONTrigger {
return jsonTrigger
}

func convertToAnsiColor(colorStr string) (ansiColor string) {
switch colorStr {
case "-2":
ansiColor = "IGNORE"
case "0":
ansiColor = "DEFAULT"
case "1":
ansiColor = "8" // Light black (dark gray)
case "2":
ansiColor = "0" // Black
case "3":
ansiColor = "9" // Light red
case "4":
ansiColor = "1" // Red
case "5":
ansiColor = "10" // Light green
case "6":
ansiColor = "2" // Green
case "7":
ansiColor = "11" // Light yellow
case "8":
ansiColor = "3" // Yellow
case "9":
ansiColor = "12" // Light blue
case "10":
ansiColor = "4" // Blue
case "11":
ansiColor = "13" // Light magenta
case "12":
ansiColor = "5" // Magenta
case "13":
ansiColor = "14" // Light cyan
case "14":
ansiColor = "6" // Cyan
case "15":
ansiColor = "15" // Light white
case "16":
ansiColor = "7" // White (light gray)
default:
ansiColor = colorStr // Use color directly if it doesn't match any case
}
return ansiColor
}

func extractColorTriggerColors(colorStr string) string {
var fgColor, bgColor string
fgIndex := strings.Index(colorStr, "FG")
bgIndex := strings.Index(colorStr, "BG")

if fgIndex != -1 && bgIndex != -1 {
fgColor = colorStr[fgIndex+2 : bgIndex]
bgColor = colorStr[bgIndex+2:]
}
return fmt.Sprintf("%s,%s", convertToAnsiColor(fgColor), convertToAnsiColor(bgColor))
}

func patternNumberToType(patternNumber int) string {
typeMap := map[int]string{
0: "substring",
Expand Down

0 comments on commit 8f94b3e

Please sign in to comment.