9 Commits

6 changed files with 24 additions and 13 deletions

View File

@@ -38,13 +38,13 @@ var possibleColors map[string]color = map[string]color{
"GREEN": {"GREEN", colorData.New(colorData.FgGreen)},
"YELLOW": {"YELLOW", colorData.New(colorData.FgYellow)},
"BLUE": {"BLUE", colorData.New(colorData.FgBlue)},
"MAGENTA": {"MAGENTA", colorData.New(38, 2, 254, 141, 255)},
"MAGENTA": {"MAGENTA", colorData.New(colorData.FgMagenta)},
"CYAN": {"CYAN", colorData.New(colorData.FgCyan)},
"WHITE": {"WHITE", colorData.New(colorData.FgWhite)},
"GRAY": {"GRAY", colorData.New(colorData.FgWhite, colorData.Faint)},
// Last three numbers are RGB. Reference https://en.wikipedia.org/wiki/ANSI_escape_code for what the first two numbers mean.
"ORANGE": {"ORANGE", colorData.New(38, 2, 255, 153, 28)},
"DARKBLUE": {"DARKBLUE", colorData.New(38, 2, 0, 112, 255)},
// "ORANGE": {"ORANGE", colorData.New(38, 2, 255, 153, 28)},
// "DARKBLUE": {"DARKBLUE", colorData.New(38, 2, 0, 112, 255)},
"NONE": {"NONE", colorData.New()},
}
@@ -157,7 +157,7 @@ func stringToRGB(rgbString string) (*RGB, error) {
func loadColorsFromFile(filepath string) error {
data, err := os.ReadFile(filepath)
if err != nil {
panic(err)
return err
}
// Read color config file into a MapSlice
tempMapSlice := yaml.MapSlice{}

View File

@@ -3,6 +3,7 @@ package main
import (
"embed"
"errors"
"fmt"
"io/fs"
"os"
"path/filepath"
@@ -88,7 +89,10 @@ func loadConfig(configFilename string) (stack.Stack[regColor], error) {
// returned.
regColorStack := stack.NewStack[regColor](len(strings.Split(string(configFile), "\n"))) // The stack will have the same size as the number of lines in the file
for _, item := range tempMapSlice {
re := regex.MustCompile(item.Key.(string), regex.RE_MULTILINE, regex.RE_SINGLE_LINE)
re, err := regex.Compile(item.Key.(string), regex.RE_MULTILINE, regex.RE_SINGLE_LINE)
if err != nil {
return *stack.NewStack[regColor](0), fmt.Errorf("%v: '%s'", err, item.Key.(string))
}
clr, err := newColor(item.Value.(string))
if err != nil {
return *stack.NewStack[regColor](0), err

View File

@@ -5,3 +5,4 @@
PINK: 38 244 211 244 22
BOLD_WHITE: 38 -1 -1 -1 1
ITALIC_WHITE: 38 -1 -1 -1 3
UNDERLINE_WHITE: 38 -1 -1 -1 4

View File

@@ -18,11 +18,9 @@
'(&&)|(\|\|)': CYAN
# Keywords
'\b(if|else|for|range|go|func|return|break|continue)\b': CYAN
'\b(import|var|const|type|struct)\b': CYAN
'\b(package|import|var|const|type|struct)\b': CYAN
# Built-in Functions
'\b(panic|len)\b': DARKBLUE
# Functions from packages (package name and function name separated by dot)
'\b(\w*\.\w*)\b': DARKBLUE
'\b(panic|len)\b': GREEN
# Data Types
'\b(bool|byte|rune|string|interface|map|chan)\b': YELLOW
'\b(u?int)(8|16|32|64)?\b': YELLOW

View File

@@ -1,13 +1,21 @@
# Priority decreases going downward ie. If two regexes match the same piece of
# text, the one defined earlier will take precedence over the one defined later.
# Headings
'##?#?#?#?#?.*': MAGENTA
'^#{1,6}.*?$': MAGENTA
# Link text
'\[.*?\](?=\(.*?\))': UNDERLINE_WHITE
# Link URL
'https?://\w+\.\w+.*?(?=\))': RED
# Code blocks
'```(.|\n)+?```': YELLOW
# Bold text
'\b__[^_]+?__\b': BOLD_WHITE
'\*\*[^*]+?\*\*': BOLD_WHITE
# Italic text
'\b_[^_]+?_\b': ITALIC_WHITE
'\*[^*\n]+?\*': ITALIC_WHITE

View File

@@ -79,7 +79,7 @@ func main() {
// Check if config exists. If it doesn't, generate the config files.
userHomeDir, err := os.UserHomeDir() // Get current user's home directory, to construct config path
if err != nil {
panic(err)
printErrAndExit("Unable to retrieve user home directory")
}
configPath := filepath.Join(userHomeDir + "/.config/ccat/")
if _, err := os.Stat(configPath); os.IsNotExist(err) {
@@ -107,7 +107,7 @@ func main() {
// the program.
finfo, err := os.Stat(fileName)
if err != nil {
panic(err)
printErrAndExit("Unable to read file")
}
if finfo.Size() == 0 {
os.Exit(0)