First commit

This commit is contained in:
2024-08-09 19:20:42 -05:00
commit 025ec775ca
14 changed files with 543 additions and 0 deletions

36
colorunit.go Normal file
View File

@@ -0,0 +1,36 @@
package main
import (
"os"
)
// A colorunit represents a unit in a file. It consists of the character,
// and the color that the character should be printed out in.
type colorunit struct {
ch byte
clr color
}
// loadInputFile loads the given file and returns a slice of colorunits,
// and a slice of bytes (which just contains all the text in the file).
// The slice of colorunits is used to fill in the color for each character.
// The slice of bytes is used to perform the regex matching.
// The color will be set to the current terminal foreground color.
func loadInputFile(fileName string) ([]colorunit, []byte) {
data, err := os.ReadFile(fileName)
if err != nil {
panic(err)
}
units := make([]colorunit, len(data))
for idx, c := range data {
units[idx] = colorunit{byte(c), newColorMust("NONE")}
}
return units, data
}
// print is used to print out the character in the given colorunit, according to
// its color.
func (unit colorunit) print() {
unit.clr.colorObj.Printf("%c", unit.ch)
return
}