summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorknolax <1339802534.kk@gmail.com>2016-05-11 15:16:43 +0000
committerknolax <1339802534.kk@gmail.com>2016-05-11 15:16:43 +0000
commit0dc08076a72ae45890c3c0a12c19ee307841a574 (patch)
tree68e5c26d3cc132088443a2b53deab031574c90bc
parent813be4e516a67512ed87998e404adac138eac419 (diff)
fixed background issue and made color independent
-rw-r--r--letters.go34
1 files changed, 26 insertions, 8 deletions
diff --git a/letters.go b/letters.go
index f2a6bce..868fac1 100644
--- a/letters.go
+++ b/letters.go
@@ -65,7 +65,7 @@ func getcolor (fcolor rune , bcolor rune) (rfcolor , rbcolor []rune, err error){
rbcolor = append(rbcolor,'m');
return rfcolor , rbcolor , nil;
}
-func charadd (rchar rune ,fcolor rune, bcolor rune) (err error) {
+func charadd (rchar rune) (err error) {
var rrunedata runedata;
rrunedata , err = getrunedata(rchar);
if (err != nil) && (err != errors.New("runedata too short")) {
@@ -74,11 +74,7 @@ func charadd (rchar rune ,fcolor rune, bcolor rune) (err error) {
}
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] {
@@ -97,6 +93,18 @@ func charadd (rchar rune ,fcolor rune, bcolor rune) (err error) {
err = nil;
return err;
}
+func coloradd (fcolor rune, bcolor rune) (err error) {
+ frune , brune , err := getcolor(fcolor,bcolor);
+ errc(err);
+ var i = 0;
+ for i < len(outp) {
+ outp[i] = append(outp[i],frune...);
+ outp[i] = append(outp[i],brune...);
+ i++;
+ }
+ err = nil;
+ return err;
+}
var outp [5][]rune;
var inp []rune;
func inito () () {
@@ -117,7 +125,7 @@ func main () () {
var err error;
var frune rune = '9';
var brune rune = '9';
- inito();
+ var cover int = 0;
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 ;
@@ -135,6 +143,7 @@ func main () () {
i++;
if (inp[i] <= '9') && (inp[i] >= '0') {
frune = inp[i];
+ err = coloradd(frune,brune);
fmt.Println("setting foreground color %c",inp[i]);
}
break;
@@ -142,17 +151,26 @@ func main () () {
i++;
if (inp[i] <= '9') && (inp[i] >= '0') {
brune = inp[i];
+ err = coloradd(frune,brune);
fmt.Println("setting background color %c",inp[i]);
}
break;
default :
- err = charadd(inp[i],frune,brune);
+ if cover == 0 {
+ inito();
+ cover = 1;
+ }
+ err = charadd(inp[i]);
errc(err);
break;
}
} else {
i++;
- err = charadd(inp[i],frune,brune);
+ if cover == 0 {
+ inito();
+ cover = 1;
+ }
+ err = charadd(inp[i]);
errc(err);
}
i++;