Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Can'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.)


I'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)


Yup! Thats much better, Thanks




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: