why yes, i attempt unfinished projects in multiple languages, why do you ask?
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
4.0 KiB

package main
import (
"bufio"
"fmt"
"os"
"regexp"
)
//// Ripping the band-aid off and compiling regexps immediately
var (
// hex values of the colors themselves
hex_re = regexp.MustCompile("#......")
// special colors
fg_re = regexp.MustCompile("..fore.+:")
bg_re = regexp.MustCompile("..back.+:")
cursor_re = regexp.MustCompile("..cursorColor:")
// numeric colors...
black_d_re = regexp.MustCompile("..color0:")
black_l_re = regexp.MustCompile("..color8:")
red_d_re = regexp.MustCompile("..color1:")
red_l_re = regexp.MustCompile("..color9:")
green_d_re = regexp.MustCompile("..color2:")
green_l_re = regexp.MustCompile("..color10:")
yellow_d_re = regexp.MustCompile("..color3:")
yellow_l_re = regexp.MustCompile("..color11:")
blue_d_re = regexp.MustCompile("..color4:")
blue_l_re = regexp.MustCompile("..color12:")
magenta_d_re = regexp.MustCompile("..color5:")
magenta_l_re = regexp.MustCompile("..color13:")
cyan_d_re = regexp.MustCompile("..color6:")
cyan_l_re = regexp.MustCompile("..color14:")
white_d_re = regexp.MustCompile("..color7:")
white_l_re = regexp.MustCompile("..color15:")
)
func seek_Xrsrc() []string {
//// Step 1: Find and open .Xresources
Xrsrc, err := os.Open(".Xresources")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer Xrsrc.Close()
//// Step 2: Manipulate .Xresources
var color_slice []string
scanner := bufio.NewScanner(Xrsrc)
for scanner.Scan() {
if scanner.Text() != "" && scanner.Text()[0:1] != "!" { // is uncommented
fmt.Println("LINE:\t", scanner.Text())
color := proc_Xrsrc(scanner.Text())
if color != "" {
fmt.Println("VALUE:\t", color) // not really a feature atm
color_slice = append(color_slice, color)
}
}
}
if err := scanner.Err(); err != nil {
fmt.Println(err)
}
fmt.Println(color_slice) // debug
for _, i := range color_slice {
fmt.Println(i)
}
return color_slice
}
func proc_Xrsrc(text string) string { //// NOTE: this function is intended to run once per line; no loops here
//// special colors
if fg_re.Match([]byte(text)) == true {
text = "fg_" + hex_re.FindString(text)
} else if bg_re.Match([]byte(text)) == true {
text = "bg_" + hex_re.FindString(text)
} else if cursor_re.Match([]byte(text)) == true {
text = "cursor_" + hex_re.FindString(text)
//// numeric colors
} else if black_d_re.Match([]byte(text)) == true { // black
text = "black_d_" + hex_re.FindString(text)
} else if black_l_re.Match([]byte(text)) == true {
text = "black_l_" + hex_re.FindString(text)
} else if red_d_re.Match([]byte(text)) == true { // red
text = "red_d_" + hex_re.FindString(text)
} else if red_l_re.Match([]byte(text)) == true {
text = "red_l_" + hex_re.FindString(text)
} else if green_d_re.Match([]byte(text)) == true { // green
text = "green_d_" + hex_re.FindString(text)
} else if green_l_re.Match([]byte(text)) == true {
text = "green_l_" + hex_re.FindString(text)
} else if yellow_d_re.Match([]byte(text)) == true { // yellow
text = "yellow_d_" + hex_re.FindString(text)
} else if yellow_l_re.Match([]byte(text)) == true {
text = "yellow_l_" + hex_re.FindString(text)
} else if blue_d_re.Match([]byte(text)) == true { // blue
text = "blue_d_" + hex_re.FindString(text)
} else if blue_l_re.Match([]byte(text)) == true {
text = "blue_l_" + hex_re.FindString(text)
} else if magenta_d_re.Match([]byte(text)) == true { // magenta
text = "magenta_d_" + hex_re.FindString(text)
} else if magenta_l_re.Match([]byte(text)) == true {
text = "magenta_l_" + hex_re.FindString(text)
} else if cyan_d_re.Match([]byte(text)) == true { // cyan
text = "cyan_d_" + hex_re.FindString(text)
} else if cyan_l_re.Match([]byte(text)) == true {
text = "cyan_l_" + hex_re.FindString(text)
} else if white_d_re.Match([]byte(text)) == true { // white
text = "white_d_" + hex_re.FindString(text)
} else if cyan_l_re.Match([]byte(text)) == true {
text = "white_l_" + hex_re.FindString(text)
} else {
text = ""
} // not a color; don't care
return text
}