3 ms·
I sorta cleaned up the giant if tree there. It was on my todo list :)
by benjojo12 12y ago
I sorta cleaned up the giant if tree there. It was on my todo list :)
- dbaupp 12y agoCan't it at least be something like high := code / 16; low := code % 16; switch high { case 0: template += "40" case 1: template += "44" case 2: template += "42" // ... case 15: template += "43" } switch low { case 0: template += ";30" case 1: template += ";34" // ... case 15: template += ";33" } Or even s := [...]string{"0", "4", "2", ..., "3"} template := "\x1B[4" + s[code / 16] + ";3" + s[code % 16] + "m" (I don't know Go, so you will have to adjust to be valid, and I'm sure there's some sort of string formatting or something that makes the last suggestion more efficient.)
- lunixbochs 12y agoI'd probably do something like this: colors := []string{"0", "4", "2", "6", "1", "5", "3", "7", "0", "4", "2", "6", "1", "5", "3"} bg := colors[(b & 0xF0) >> 8] fg := colors[b & 0x0F] fmt.Sprintf("\x1B[4%d;3%dm", bg, fg)
- benjojo12 12y agoYup! Thats much better, Thanks