3 ms·
Looks awesome, could do with a write up though. Also there must be a 'nicer' way to do this[1] in Go, rather than a huge bunch of if statements? 1. https://git
by orf 12y ago
Looks awesome, could do with a write up though. Also there must be a 'nicer' way to do this[1] in Go, rather than a huge bunch of if statements?
1. https://github.com/benjojo/dos_ssh/blob/master/data.go https://github.com/benjojo/dos_ssh/blob/master/data.go
- raverbashing 12y agoYes, with table driven logic Not a lot prettier, though...
- benjojo12 12y agoI 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