| 1 | package vt10xscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/ |
| 2 | |
| 3 | import ( |
| 4 | "fmtscip-go gomod github.com/golang/go/src go1.14 fmt/" |
| 5 | "mathscip-go gomod github.com/golang/go/src go1.14 math/" |
| 6 | "regexpscip-go gomod github.com/golang/go/src go1.14 regexp/" |
| 7 | "strconvscip-go gomod github.com/golang/go/src go1.14 strconv/" |
| 8 | "stringsscip-go gomod github.com/golang/go/src go1.14 strings/" |
| 9 | ) |
| 10 | |
| 11 | // STR sequences are similar to CSI sequences, but have string arguments (and |
| 12 | // as far as I can tell, don't really have a name; STR is the name I took from |
| 13 | // suckless which I imagine comes from rxvt or xterm). |
| 14 | type strEscapescip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape# struct { |
| 15 | typscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#typ. rune |
| 16 | bufscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#buf. []rune |
| 17 | argsscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#args. []string |
| 18 | } |
| 19 | |
| 20 | func (s *strEscapescip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#) resetscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#reset().() { |
| 21 | s.typscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#typ. = 0 |
| 22 | s.bufscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#buf. = s.bufscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#buf.[:0] |
| 23 | s.argsscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#args. = nil |
| 24 | } |
| 25 | |
| 26 | func (s *strEscapescip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#) putscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#put().(c rune) { |
| 27 | // TODO: improve allocs with an array backed slice; bench first |
| 28 | if len(s.bufscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#buf.) < 256 { |
| 29 | s.bufscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#buf. = append(s.bufscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#buf., c) |
| 30 | } |
| 31 | // Going by st, it is better to remain silent when the STR sequence is not |
| 32 | // ended so that it is apparent to users something is wrong. The length sanity |
| 33 | // check ensures we don't absorb the entire stream into memory. |
| 34 | // TODO: see what rxvt or xterm does |
| 35 | } |
| 36 | |
| 37 | func (s *strEscapescip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#) parsescip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#parse().() { |
| 38 | s.argsscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#args. = stringsscip-go gomod github.com/golang/go/src go1.14 strings/.Splitscip-go gomod github.com/golang/go/src go1.14 strings/Split().(string(s.bufscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#buf.), ";") |
| 39 | } |
| 40 | |
| 41 | func (s *strEscapescip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#) argscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#arg().(i, def int) int { |
| 42 | if i >= len(s.argsscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#args.) || i < 0 { |
| 43 | return def |
| 44 | } |
| 45 | i, err := strconvscip-go gomod github.com/golang/go/src go1.14 strconv/.Atoiscip-go gomod github.com/golang/go/src go1.14 strconv/Atoi().(s.argsscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#args.[i]) |
| 46 | if err != nil { |
| 47 | return def |
| 48 | } |
| 49 | return i |
| 50 | } |
| 51 | |
| 52 | func (s *strEscapescip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#) argStringscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#argString().(i int, def string) string { |
| 53 | if i >= len(s.argsscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#args.) || i < 0 { |
| 54 | return def |
| 55 | } |
| 56 | return s.argsscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#args.[i] |
| 57 | } |
| 58 | |
| 59 | func (t *Statescip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/State#) handleSTRscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/State#handleSTR().() { |
| 60 | s := &t.strscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/State#str. |
| 61 | s.parsescip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#parse().() |
| 62 | |
| 63 | switch s.typscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#typ. { |
| 64 | case ']': // OSC - operating system command |
| 65 | var p *string |
| 66 | switch d := s.argscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#arg().(0, 0); d { |
| 67 | case 0, 1, 2: |
| 68 | title := s.argStringscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#argString().(1, "") |
| 69 | if title != "" { |
| 70 | t.setTitlescip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/State#setTitle().(title) |
| 71 | } |
| 72 | case 10: |
| 73 | if len(s.argsscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#args.) < 2 { |
| 74 | break |
| 75 | } |
| 76 | |
| 77 | c := s.argStringscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#argString().(1, "") |
| 78 | p := &c |
| 79 | if p != nil && *p == "?" { |
| 80 | t.oscColorResponsescip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/State#oscColorResponse().(int(DefaultFGscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/DefaultFG.), 10) |
| 81 | } else if err := t.setColorNamescip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/State#setColorName().(int(DefaultFGscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/DefaultFG.), p); err != nil { |
| 82 | t.logfscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/State#logf().("invalid foreground color: %s\n", maybescip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/maybe().(p)) |
| 83 | } else { |
| 84 | // TODO: redraw |
| 85 | } |
| 86 | case 11: |
| 87 | if len(s.argsscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#args.) < 2 { |
| 88 | break |
| 89 | } |
| 90 | |
| 91 | c := s.argStringscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#argString().(1, "") |
| 92 | p := &c |
| 93 | if p != nil && *p == "?" { |
| 94 | t.oscColorResponsescip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/State#oscColorResponse().(int(DefaultBGscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/DefaultBG.), 11) |
| 95 | } else if err := t.setColorNamescip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/State#setColorName().(int(DefaultBGscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/DefaultBG.), p); err != nil { |
| 96 | t.logfscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/State#logf().("invalid cursor color: %s\n", maybescip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/maybe().(p)) |
| 97 | } else { |
| 98 | // TODO: redraw |
| 99 | } |
| 100 | // case 12: |
| 101 | // if len(s.args) < 2 { |
| 102 | // break |
| 103 | // } |
| 104 | |
| 105 | // c := s.argString(1, "") |
| 106 | // p := &c |
| 107 | // if p != nil && *p == "?" { |
| 108 | // t.oscColorResponse(int(DefaultCursor), 12) |
| 109 | // } else if err := t.setColorName(int(DefaultCursor), p); err != nil { |
| 110 | // t.logf("invalid background color: %s\n", p) |
| 111 | // } else { |
| 112 | // // TODO: redraw |
| 113 | // } |
| 114 | case 4: // color set |
| 115 | if len(s.argsscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#args.) < 3 { |
| 116 | break |
| 117 | } |
| 118 | |
| 119 | c := s.argStringscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#argString().(2, "") |
| 120 | p = &c |
| 121 | fallthrough |
| 122 | case 104: // color reset |
| 123 | j := -1 |
| 124 | if len(s.argsscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#args.) > 1 { |
| 125 | j = s.argscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#arg().(1, 0) |
| 126 | } |
| 127 | if p != nil && *p == "?" { // report |
| 128 | t.osc4ColorResponsescip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/State#osc4ColorResponse().(j) |
| 129 | } else if err := t.setColorNamescip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/State#setColorName().(j, p); err != nil { |
| 130 | if !(d == 104 && len(s.argsscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#args.) <= 1) { |
| 131 | t.logfscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/State#logf().("invalid color j=%d, p=%s\n", j, maybescip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/maybe().(p)) |
| 132 | } |
| 133 | } else { |
| 134 | // TODO: redraw |
| 135 | } |
| 136 | default: |
| 137 | t.logfscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/State#logf().("unknown OSC command %d\n", d) |
| 138 | // TODO: s.dump() |
| 139 | } |
| 140 | case 'k': // old title set compatibility |
| 141 | title := s.argStringscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#argString().(0, "") |
| 142 | if title != "" { |
| 143 | t.setTitlescip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/State#setTitle().(title) |
| 144 | } |
| 145 | default: |
| 146 | // TODO: Ignore these codes instead of complain? |
| 147 | // 'P': // DSC - device control string |
| 148 | // '_': // APC - application program command |
| 149 | // '^': // PM - privacy message |
| 150 | |
| 151 | t.logfscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/State#logf().("unhandled STR sequence '%c'\n", s.typscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/strEscape#typ.) |
| 152 | // t.str.dump() |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | func (t *Statescip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/State#) setColorNamescip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/State#setColorName().(j int, p *string) error { |
| 157 | if !betweenscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/between().(j, 0, 1<<24) { |
| 158 | return fmtscip-go gomod github.com/golang/go/src go1.14 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.14 fmt/Errorf().("invalid color value %d", j) |
| 159 | } |
| 160 | |
| 161 | if p == nil { |
| 162 | // restore color |
| 163 | delete(t.colorOverridescip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/State#colorOverride., Colorscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/Color#(j)) |
| 164 | } else { |
| 165 | // set color |
| 166 | r, g, b, err := parseColorscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/parseColor().(*p) |
| 167 | if err != nil { |
| 168 | return err |
| 169 | } |
| 170 | t.colorOverridescip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/State#colorOverride.[Colorscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/Color#(j)] = Colorscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/Color#(r<<16 | g<<8 | b) |
| 171 | } |
| 172 | |
| 173 | return nil |
| 174 | } |
| 175 | |
| 176 | func (t *Statescip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/State#) oscColorResponsescip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/State#oscColorResponse().(j, num int) { |
| 177 | if j < 0 { |
| 178 | t.logfscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/State#logf().("failed to fetch osc color %d\n", j) |
| 179 | return |
| 180 | } |
| 181 | |
| 182 | k, ok := t.colorOverridescip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/State#colorOverride.[Colorscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/Color#(j)] |
| 183 | if ok { |
| 184 | j = int(k) |
| 185 | } |
| 186 | |
| 187 | r, g, b := rgbscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/rgb().(j) |
| 188 | t.wscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/State#w..Writescip-go gomod github.com/golang/go/src go1.14 io/Writer#Write().([]byte(fmtscip-go gomod github.com/golang/go/src go1.14 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.14 fmt/Sprintf().("\033]%d;rgb:%02x%02x/%02x%02x/%02x%02x\007", num, r, r, g, g, b, b))) |
| 189 | } |
| 190 | |
| 191 | func (t *Statescip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/State#) osc4ColorResponsescip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/State#osc4ColorResponse().(j int) { |
| 192 | if j < 0 { |
| 193 | t.logfscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/State#logf().("failed to fetch osc4 color %d\n", j) |
| 194 | return |
| 195 | } |
| 196 | |
| 197 | k, ok := t.colorOverridescip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/State#colorOverride.[Colorscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/Color#(j)] |
| 198 | if ok { |
| 199 | j = int(k) |
| 200 | } |
| 201 | |
| 202 | r, g, b := rgbscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/rgb().(j) |
| 203 | t.wscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/State#w..Writescip-go gomod github.com/golang/go/src go1.14 io/Writer#Write().([]byte(fmtscip-go gomod github.com/golang/go/src go1.14 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.14 fmt/Sprintf().("\033]4;%d;rgb:%02x%02x/%02x%02x/%02x%02x\007", j, r, r, g, g, b, b))) |
| 204 | } |
| 205 | |
| 206 | func rgbscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/rgb().(j int) (r, g, b int) { |
| 207 | return (j >> 16) & 0xff, (j >> 8) & 0xff, j & 0xff |
| 208 | } |
| 209 | |
| 210 | var ( |
| 211 | RGBPatternscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/RGBPattern. = regexpscip-go gomod github.com/golang/go/src go1.14 regexp/.MustCompilescip-go gomod github.com/golang/go/src go1.14 regexp/MustCompile().(`^([\da-f]{1})\/([\da-f]{1})\/([\da-f]{1})$|^([\da-f]{2})\/([\da-f]{2})\/([\da-f]{2})$|^([\da-f]{3})\/([\da-f]{3})\/([\da-f]{3})$|^([\da-f]{4})\/([\da-f]{4})\/([\da-f]{4})$`) |
| 212 | HashPatternscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/HashPattern. = regexpscip-go gomod github.com/golang/go/src go1.14 regexp/.MustCompilescip-go gomod github.com/golang/go/src go1.14 regexp/MustCompile().(`[\da-f]`) |
| 213 | ) |
| 214 | |
| 215 | func parseColorscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/parseColor().(p string) (r, g, b int, err error) { |
| 216 | if len(p) == 0 { |
| 217 | err = fmtscip-go gomod github.com/golang/go/src go1.14 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.14 fmt/Errorf().("empty color spec") |
| 218 | return |
| 219 | } |
| 220 | |
| 221 | low := stringsscip-go gomod github.com/golang/go/src go1.14 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.14 strings/ToLower().(p) |
| 222 | if stringsscip-go gomod github.com/golang/go/src go1.14 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.14 strings/HasPrefix().(low, "rgb:") { |
| 223 | low = low[4:] |
| 224 | sm := RGBPatternscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/RGBPattern..FindAllStringSubmatchscip-go gomod github.com/golang/go/src go1.14 regexp/Regexp#FindAllStringSubmatch().(low, -1) |
| 225 | if len(sm) != 1 || len(sm[0]) == 0 { |
| 226 | err = fmtscip-go gomod github.com/golang/go/src go1.14 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.14 fmt/Errorf().("invalid rgb color spec: %s", p) |
| 227 | return |
| 228 | } |
| 229 | m := sm[0] |
| 230 | |
| 231 | var base float64 |
| 232 | if len(m[1]) > 0 { |
| 233 | base = 15 |
| 234 | } else if len(m[4]) > 0 { |
| 235 | base = 255 |
| 236 | } else if len(m[7]) > 0 { |
| 237 | base = 4095 |
| 238 | } else { |
| 239 | base = 65535 |
| 240 | } |
| 241 | |
| 242 | r64, err := strconvscip-go gomod github.com/golang/go/src go1.14 strconv/.ParseIntscip-go gomod github.com/golang/go/src go1.14 strconv/ParseInt().(firstNonEmptyscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/firstNonEmpty().(m[1], m[4], m[7], m[10]), 16, 0) |
| 243 | if err != nil { |
| 244 | return r, g, b, err |
| 245 | } |
| 246 | |
| 247 | g64, err := strconvscip-go gomod github.com/golang/go/src go1.14 strconv/.ParseIntscip-go gomod github.com/golang/go/src go1.14 strconv/ParseInt().(firstNonEmptyscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/firstNonEmpty().(m[2], m[5], m[8], m[11]), 16, 0) |
| 248 | if err != nil { |
| 249 | return r, g, b, err |
| 250 | } |
| 251 | |
| 252 | b64, err := strconvscip-go gomod github.com/golang/go/src go1.14 strconv/.ParseIntscip-go gomod github.com/golang/go/src go1.14 strconv/ParseInt().(firstNonEmptyscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/firstNonEmpty().(m[3], m[6], m[9], m[12]), 16, 0) |
| 253 | if err != nil { |
| 254 | return r, g, b, err |
| 255 | } |
| 256 | |
| 257 | r = int(mathscip-go gomod github.com/golang/go/src go1.14 math/.Roundscip-go gomod github.com/golang/go/src go1.14 math/Round().(float64(r64) / base * 255)) |
| 258 | g = int(mathscip-go gomod github.com/golang/go/src go1.14 math/.Roundscip-go gomod github.com/golang/go/src go1.14 math/Round().(float64(g64) / base * 255)) |
| 259 | b = int(mathscip-go gomod github.com/golang/go/src go1.14 math/.Roundscip-go gomod github.com/golang/go/src go1.14 math/Round().(float64(b64) / base * 255)) |
| 260 | return r, g, b, nil |
| 261 | } else if stringsscip-go gomod github.com/golang/go/src go1.14 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.14 strings/HasPrefix().(low, "#") { |
| 262 | low = low[1:] |
| 263 | m := HashPatternscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/HashPattern..FindAllStringscip-go gomod github.com/golang/go/src go1.14 regexp/Regexp#FindAllString().(low, -1) |
| 264 | if !oneOfscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/oneOf().(len(m), []int{3, 6, 9, 12}) { |
| 265 | err = fmtscip-go gomod github.com/golang/go/src go1.14 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.14 fmt/Errorf().("invalid hash color spec: %s", p) |
| 266 | return |
| 267 | } |
| 268 | |
| 269 | adv := len(low) / 3 |
| 270 | for i := 0; i < 3; i++ { |
| 271 | c, err := strconvscip-go gomod github.com/golang/go/src go1.14 strconv/.ParseIntscip-go gomod github.com/golang/go/src go1.14 strconv/ParseInt().(low[adv*i:adv*i+adv], 16, 0) |
| 272 | if err != nil { |
| 273 | return r, g, b, err |
| 274 | } |
| 275 | |
| 276 | var v int64 |
| 277 | switch adv { |
| 278 | case 1: |
| 279 | v = c << 4 |
| 280 | case 2: |
| 281 | v = c |
| 282 | case 3: |
| 283 | v = c >> 4 |
| 284 | default: |
| 285 | v = c >> 8 |
| 286 | } |
| 287 | |
| 288 | switch i { |
| 289 | case 0: |
| 290 | r = int(v) |
| 291 | case 1: |
| 292 | g = int(v) |
| 293 | case 2: |
| 294 | b = int(v) |
| 295 | } |
| 296 | } |
| 297 | return |
| 298 | } else { |
| 299 | err = fmtscip-go gomod github.com/golang/go/src go1.14 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.14 fmt/Errorf().("invalid color spec: %s", p) |
| 300 | return |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | func maybescip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/maybe().(p *string) string { |
| 305 | if p == nil { |
| 306 | return "<nil>" |
| 307 | } |
| 308 | return *p |
| 309 | } |
| 310 | |
| 311 | func firstNonEmptyscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/firstNonEmpty().(strs ...string) string { |
| 312 | if len(strs) == 0 { |
| 313 | return "" |
| 314 | } |
| 315 | for _, str := range strs { |
| 316 | if len(str) > 0 { |
| 317 | return str |
| 318 | } |
| 319 | } |
| 320 | return strs[len(strs)-1] |
| 321 | } |
| 322 | |
| 323 | func oneOfscip-go gomod github.com/hinshun/vt10x . `github.com/hinshun/vt10x`/oneOf().(v int, is []int) bool { |
| 324 | for _, i := range is { |
| 325 | if v == i { |
| 326 | return true |
| 327 | } |
| 328 | } |
| 329 | return false |
| 330 | } |