summaryrefslogtreecommitdiff
path: root/letters.go
diff options
context:
space:
mode:
Diffstat (limited to 'letters.go')
-rw-r--r--letters.go176
1 files changed, 176 insertions, 0 deletions
diff --git a/letters.go b/letters.go
new file mode 100644
index 0000000..c62cfa4
--- /dev/null
+++ b/letters.go
@@ -0,0 +1,176 @@
+package main
+import (
+ "fmt"
+ "bufio"
+ "os"
+ "io/ioutil"
+ "errors"
+ "strconv"
+)
+type runedata struct {
+ Field [5][5]bool;
+}
+func errc (err error) {
+ if err != nil {
+ panic(err);
+ }
+}
+var charA runedata;
+func getrunedata (rrune rune)(rrunedata runedata, err error){
+ tmpstring := strconv.Itoa(int(rrune));
+ _, err = os.Stat("/home/knolax/go/src/letters/chardata/" +tmpstring);
+ if os.IsNotExist(err) {
+ tmpstring = strconv.Itoa(int('#'));
+ err = errors.New("runedata not found");
+ } else {
+ err = nil;
+ }
+ var tmpbytes []byte;
+ tmpbytes ,err = ioutil.ReadFile("/home/knolax/go/src/chardata/"+tmpstring);
+ errc(err);
+ tmpstring = string(tmpbytes);
+ var i = 0;
+ var v = 0;
+ var n = 0;
+ for i < len(rrunedata.Field) {
+ v = 0;
+ for v < len(rrunedata.Field[i]) {
+ if n < len(tmpstring) {
+ if tmpstring[n] == '1' {
+ rrunedata.Field[i][v] = true;
+ v++;
+ } else {
+ if tmpstring[n] == '0' {
+ rrunedata.Field[i][v] = false;
+ v++;
+ }
+ }
+ } else {
+ err = errors.New("runedata too short");
+ return rrunedata, err;
+ }
+ n++;
+ }
+ i++;
+ }
+ return rrunedata, err;
+
+}
+func getcolor (fcolor rune , bcolor rune) (rfcolor , rbcolor []rune, err error){
+ rfcolor = []rune{'\033','[','3'};
+ rbcolor = []rune{'\033','[','4'};
+ rfcolor = append(rfcolor,fcolor);
+ rbcolor = append(rbcolor,bcolor);
+ rfcolor = append(rfcolor,'m');
+ rbcolor = append(rbcolor,'m');
+ return rfcolor , rbcolor , nil;
+}
+func charadd (rchar rune ,fcolor rune, bcolor rune) (err error) {
+ var rrunedata runedata;
+ rrunedata , err = getrunedata(rchar);
+ if (err != nil) && (err != errors.New("runedata too short")) {
+ } else {
+ errc(err);
+ }
+ var i = 0;
+ var v = 0;
+ frune , brune , err := getcolor(fcolor,bcolor);
+ errc(err);
+ for i < len(outp) {
+ outp[i] = append(outp[i],frune...);
+ outp[i] = append(outp[i],brune...);
+ v = 0;
+ for v < len(rrunedata.Field[i]) {
+ if rrunedata.Field[i][v] {
+ outp[i] = append(outp[i],'_');
+ outp[i] = append(outp[i],'/');
+ } else {
+ outp[i] = append(outp[i],' ');
+ outp[i] = append(outp[i],' ');
+ }
+ v++;
+ }
+ outp[i] = append(outp[i],' ');
+ outp[i] = append(outp[i],' ');
+ i++;
+ }
+ err = nil;
+ return err;
+}
+var outp [5][]rune;
+var inp []rune;
+func inito () () {
+ var v = len(outp);
+ var i = 0;
+ var n = 0;
+ for i < v {
+ n = 0;
+ for n < (v-i-1) {
+ outp[i] = append(outp[i],' ');
+ n++;
+ }
+ i++;
+ }
+
+}
+func main () () {
+ var err error;
+ var frune rune = '9';
+ var brune rune = '9';
+ inito();
+ inpreader := bufio.NewReader(os.Stdin);
+ fmt.Println("%[0-9] for foreground color, $[0-9] for background color, / to replace using $9%9 returns the terminal to defaults");
+ var trune rune ;
+ trune , _ ,_ = inpreader.ReadRune()
+ for trune != '\n' {
+ inp = append(inp,trune);
+ trune , _ ,_ = inpreader.ReadRune();
+ }
+ var i = 0;
+ for i < len(inp) {
+ if inp[i] != '[' {
+
+ switch inp[i] {
+ case '%':
+ i++;
+ if (inp[i] <= '9') && (inp[i] >= '0') {
+ frune = inp[i];
+ fmt.Println("setting foreground color %c",inp[i]);
+ }
+ break;
+ case '$':
+ i++;
+ if (inp[i] <= '9') && (inp[i] >= '0') {
+ brune = inp[i];
+ fmt.Println("setting background color %c",inp[i]);
+ }
+ break;
+ default :
+ err = charadd(inp[i],frune,brune);
+ errc(err);
+ break;
+ }
+ } else {
+ i++;
+ err = charadd(inp[i],frune,brune);
+ errc(err);
+ }
+ i++;
+ }
+ i = 0;
+ var v = 0;
+ var tmpstring string;
+ for i < len(outp) {
+ v = 0;
+ for v < len(outp[i]) {
+ fmt.Printf("%c",outp[i][v]);
+ v++;
+ }
+ tmpstring = tmpstring + string(outp[i]);
+ tmpstring = tmpstring + "\n";
+ fmt.Printf("\n");
+ i++;
+ }
+ err = ioutil.WriteFile(string(inp),[]byte(tmpstring),0777);
+ errc(err);
+}