1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
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);
}
|