diff options
-rw-r--r-- | letters.go | 34 |
1 files changed, 26 insertions, 8 deletions
@@ -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++; |