Projects STRLCPY termdash Commits add3cff4
🤬
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
  • ■ ■ ■ ■ ■
    CHANGELOG.md
    skipped 12 lines
    13 13   
    14 14  ### Changed
    15 15   
    16  -- `tcell` dependency was upgraded 1.4.0.
     16 +- `tcell` dependency was upgraded to v2.0.0.
     17 +- aligned the definition of the first 16 colors with the definition used by
     18 + Xterm and `tcell`. Defined two non-standard colors `ColorMagenta` and
     19 + `ColorCyan` to make this change backward compatible for users that use
     20 + `termbox-go`.
    17 21  - made `tcell` terminal implementation the default in examples, demos and
    18 22   documentation.
    19 23  - upgrading versions on all dependencies.
    skipped 365 lines
  • ■ ■ ■ ■ ■
    cell/color.go
    skipped 47 lines
    48 48  const (
    49 49   ColorDefault Color = iota
    50 50   
    51  - // 8 "system" colors.
     51 + // The 16 Xterm colors.
     52 + // See https://jonasjacek.github.io/colors/
    52 53   ColorBlack
     54 + ColorMaroon
     55 + ColorGreen
     56 + ColorOlive
     57 + ColorNavy
     58 + ColorPurple
     59 + ColorTeal
     60 + ColorSilver
     61 + ColorGray
    53 62   ColorRed
    54  - ColorGreen
     63 + ColorLime
    55 64   ColorYellow
    56 65   ColorBlue
    57  - ColorMagenta
    58  - ColorCyan
     66 + ColorFuchsia
     67 + ColorAqua
    59 68   ColorWhite
     69 +)
     70 + 
     71 +// Colors defined for backward compatibility with termbox-go.
     72 +const (
     73 + ColorMagenta Color = ColorPurple
     74 + ColorCyan Color = ColorTeal
    60 75  )
    61 76   
    62 77  // ColorNumber sets a color using its number.
    skipped 23 lines
    86 101   return ColorDefault
    87 102   }
    88 103   }
     104 + // Explanation:
     105 + // https://stackoverflow.com/questions/27159322/rgb-values-of-the-colors-in-the-ansi-extended-colors-index-17-255
    89 106   return Color(0x10 + 36*r + 6*g + b + 1) // Colors are off-by-one due to ColorDefault being zero.
    90 107  }
    91 108   
    skipped 16 lines
  • ■ ■ ■ ■
    go.mod
    skipped 2 lines
    3 3  go 1.14
    4 4   
    5 5  require (
    6  - github.com/gdamore/tcell v1.4.0
     6 + github.com/gdamore/tcell/v2 v2.0.0
    7 7   github.com/kylelemons/godebug v1.1.0
    8 8   github.com/mattn/go-runewidth v0.0.9
    9 9   github.com/nsf/termbox-go v0.0.0-20201107200903-9b52a5faed9e
    skipped 4 lines
  • ■ ■ ■ ■ ■ ■
    go.sum
    skipped 5 lines
    6 6  github.com/gdamore/tcell v1.3.0/go.mod h1:Hjvr+Ofd+gLglo7RYKxxnzCBmev3BzsS67MebKS4zMM=
    7 7  github.com/gdamore/tcell v1.4.0 h1:vUnHwJRvcPQa3tzi+0QI4U9JINXYJlOz9yiaiPQ2wMU=
    8 8  github.com/gdamore/tcell v1.4.0/go.mod h1:vxEiSDZdW3L+Uhjii9c3375IlDmR05bzxY404ZVSMo0=
     9 +github.com/gdamore/tcell/v2 v2.0.0 h1:GRWG8aLfWAlekj9Q6W29bVvkHENc6hp79XOqG4AWDOs=
     10 +github.com/gdamore/tcell/v2 v2.0.0/go.mod h1:vSVL/GV5mCSlPC6thFP5kfOFdM9MGZcalipmpTxTgQA=
    9 11  github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
    10 12  github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
    11 13  github.com/lucasb-eyer/go-colorful v1.0.2 h1:mCMFu6PgSozg9tDNMMK3g18oJBX7oYGrC09mS6CXfO4=
    skipped 21 lines
  • ■ ■ ■ ■ ■ ■
    terminal/tcell/cell_options.go
    skipped 14 lines
    15 15  package tcell
    16 16   
    17 17  import (
    18  - "github.com/gdamore/tcell"
     18 + tcell "github.com/gdamore/tcell/v2"
    19 19   "github.com/mum4k/termdash/cell"
    20 20   "github.com/mum4k/termdash/terminal/terminalapi"
    21 21  )
    22 22   
    23 23  // cellColor converts termdash cell color to the tcell format.
    24 24  func cellColor(c cell.Color) tcell.Color {
    25  - return tcell.Color(c&0x1ff) - 1
     25 + if c == cell.ColorDefault {
     26 + return tcell.ColorDefault
     27 + }
     28 + // Subtract one, because cell.ColorBlack has value one instead of zero.
     29 + // Zero is used for cell.ColorDefault instead.
     30 + return tcell.Color(c-1) + tcell.ColorValid
    26 31  }
    27 32   
    28  -// fixColor converts the target color for the current color mode
    29  -func fixColor(c tcell.Color, colorMode terminalapi.ColorMode) tcell.Color {
    30  - if c == tcell.ColorDefault {
     33 +// colorToMode adjusts the color to the color mode.
     34 +func colorToMode(c cell.Color, colorMode terminalapi.ColorMode) cell.Color {
     35 + if c == cell.ColorDefault {
    31 36   return c
    32 37   }
    33 38   switch colorMode {
    34 39   case terminalapi.ColorModeNormal:
    35  - c %= tcell.Color(16)
     40 + c %= 16 + 1 // Add one for cell.ColorDefault.
    36 41   case terminalapi.ColorMode256:
    37  - c %= tcell.Color(256)
     42 + c %= 256 + 1 // Add one for cell.ColorDefault.
    38 43   case terminalapi.ColorMode216:
    39  - c %= tcell.Color(216)
    40  - c += tcell.Color(16)
     44 + if c <= 216 { // Add one for cell.ColorDefault.
     45 + return c + 16
     46 + }
     47 + c = c%216 + 16
    41 48   case terminalapi.ColorModeGrayscale:
    42  - c %= tcell.Color(24)
    43  - c += tcell.Color(232)
     49 + if c <= 24 { // Add one for cell.ColorDefault.
     50 + return c + 232
     51 + }
     52 + c = c%24 + 232
    44 53   default:
    45  - c = tcell.ColorDefault
     54 + c = cell.ColorDefault
    46 55   }
    47 56   return c
    48 57  }
    skipped 2 lines
    51 60  func cellOptsToStyle(opts *cell.Options, colorMode terminalapi.ColorMode) tcell.Style {
    52 61   st := tcell.StyleDefault
    53 62   
    54  - fg := cellColor(opts.FgColor)
    55  - bg := cellColor(opts.BgColor)
    56  - 
    57  - fg = fixColor(fg, colorMode)
    58  - bg = fixColor(bg, colorMode)
     63 + fg := cellColor(colorToMode(opts.FgColor, colorMode))
     64 + bg := cellColor(colorToMode(opts.BgColor, colorMode))
    59 65   
    60 66   // FIXME: tcell doesn't have a strikethrough style option until #254 is resolved.
    61 67   st = st.Foreground(fg).Background(bg).Bold(opts.Bold).Italic(opts.Italic).Underline(opts.Underline)
    skipped 3 lines
  • ■ ■ ■ ■ ■ ■
    terminal/tcell/cell_options_test.go
    skipped 14 lines
    15 15  package tcell
    16 16   
    17 17  import (
     18 + "reflect"
    18 19   "testing"
    19 20   
    20  - "github.com/gdamore/tcell"
     21 + tcell "github.com/gdamore/tcell/v2"
     22 + "github.com/kylelemons/godebug/pretty"
    21 23   "github.com/mum4k/termdash/cell"
    22 24   "github.com/mum4k/termdash/terminal/terminalapi"
    23 25  )
    24 26   
    25  -func TestCellColor(t *testing.T) {
    26  - tests := []struct {
    27  - color cell.Color
    28  - want tcell.Color
    29  - }{
    30  - {cell.ColorDefault, tcell.ColorDefault},
    31  - {cell.ColorBlack, tcell.ColorBlack},
    32  - {cell.ColorRed, tcell.ColorMaroon},
    33  - {cell.ColorGreen, tcell.ColorGreen},
    34  - {cell.ColorYellow, tcell.ColorOlive},
    35  - {cell.ColorBlue, tcell.ColorNavy},
    36  - {cell.ColorMagenta, tcell.ColorPurple},
    37  - {cell.ColorCyan, tcell.ColorTeal},
    38  - {cell.ColorWhite, tcell.ColorSilver},
    39  - {cell.ColorNumber(42), tcell.Color(42)},
    40  - }
    41  - 
    42  - for _, tc := range tests {
    43  - t.Run(tc.color.String(), func(t *testing.T) {
    44  - got := cellColor(tc.color)
    45  - if got != tc.want {
    46  - t.Errorf("cellColor(%v) => got %v, want %v", tc.color, got, tc.want)
    47  - }
    48  - })
    49  - }
    50  -}
    51  - 
    52  -func TestFixColor(t *testing.T) {
    53  - tests := []struct {
    54  - colorMode terminalapi.ColorMode
    55  - color cell.Color
    56  - want tcell.Color
    57  - }{
    58  - // See https://jonasjacek.github.io/colors/ for a good reference of all 256 xterm colors
    59  - // All 256 colors
    60  - {terminalapi.ColorMode256, cell.ColorDefault, tcell.ColorDefault},
    61  - {terminalapi.ColorMode256, cell.ColorBlack, tcell.ColorBlack},
    62  - {terminalapi.ColorMode256, cell.ColorRed, tcell.ColorMaroon},
    63  - {terminalapi.ColorMode256, cell.ColorGreen, tcell.ColorGreen},
    64  - {terminalapi.ColorMode256, cell.ColorYellow, tcell.ColorOlive},
    65  - {terminalapi.ColorMode256, cell.ColorBlue, tcell.ColorNavy},
    66  - {terminalapi.ColorMode256, cell.ColorMagenta, tcell.ColorPurple},
    67  - {terminalapi.ColorMode256, cell.ColorCyan, tcell.ColorTeal},
    68  - {terminalapi.ColorMode256, cell.ColorWhite, tcell.ColorSilver},
    69  - {terminalapi.ColorMode256, cell.ColorNumber(42), tcell.Color(42)},
    70  - // 8 system colors
    71  - {terminalapi.ColorModeNormal, cell.ColorDefault, tcell.ColorDefault},
    72  - {terminalapi.ColorModeNormal, cell.ColorBlack, tcell.ColorBlack},
    73  - {terminalapi.ColorModeNormal, cell.ColorRed, tcell.ColorMaroon},
    74  - {terminalapi.ColorModeNormal, cell.ColorGreen, tcell.ColorGreen},
    75  - {terminalapi.ColorModeNormal, cell.ColorYellow, tcell.ColorOlive},
    76  - {terminalapi.ColorModeNormal, cell.ColorBlue, tcell.ColorNavy},
    77  - {terminalapi.ColorModeNormal, cell.ColorMagenta, tcell.ColorPurple},
    78  - {terminalapi.ColorModeNormal, cell.ColorCyan, tcell.ColorTeal},
    79  - {terminalapi.ColorModeNormal, cell.ColorWhite, tcell.ColorSilver},
    80  - {terminalapi.ColorModeNormal, cell.ColorNumber(42), tcell.Color(10)},
    81  - // Grayscale colors (all the grey colours from 231 to 255)
    82  - {terminalapi.ColorModeGrayscale, cell.ColorDefault, tcell.ColorDefault},
    83  - {terminalapi.ColorModeGrayscale, cell.ColorBlack, tcell.Color232},
    84  - {terminalapi.ColorModeGrayscale, cell.ColorRed, tcell.Color233},
    85  - {terminalapi.ColorModeGrayscale, cell.ColorGreen, tcell.Color234},
    86  - {terminalapi.ColorModeGrayscale, cell.ColorYellow, tcell.Color235},
    87  - {terminalapi.ColorModeGrayscale, cell.ColorBlue, tcell.Color236},
    88  - {terminalapi.ColorModeGrayscale, cell.ColorMagenta, tcell.Color237},
    89  - {terminalapi.ColorModeGrayscale, cell.ColorCyan, tcell.Color238},
    90  - {terminalapi.ColorModeGrayscale, cell.ColorWhite, tcell.Color239},
    91  - {terminalapi.ColorModeGrayscale, cell.ColorNumber(42), tcell.Color(250)},
    92  - // 216 colors (16 to 231)
    93  - {terminalapi.ColorMode216, cell.ColorDefault, tcell.ColorDefault},
    94  - {terminalapi.ColorMode216, cell.ColorBlack, tcell.Color16},
    95  - {terminalapi.ColorMode216, cell.ColorRed, tcell.Color17},
    96  - {terminalapi.ColorMode216, cell.ColorGreen, tcell.Color18},
    97  - {terminalapi.ColorMode216, cell.ColorYellow, tcell.Color19},
    98  - {terminalapi.ColorMode216, cell.ColorBlue, tcell.Color20},
    99  - {terminalapi.ColorMode216, cell.ColorMagenta, tcell.Color21},
    100  - {terminalapi.ColorMode216, cell.ColorCyan, tcell.Color22},
    101  - {terminalapi.ColorMode216, cell.ColorWhite, tcell.Color23},
    102  - {terminalapi.ColorMode216, cell.ColorNumber(42), tcell.Color(58)},
    103  - // Unknown color mode
    104  - {-1, cell.ColorRed, tcell.ColorDefault},
    105  - }
    106  - 
    107  - for _, tc := range tests {
    108  - t.Run(tc.colorMode.String()+"_"+tc.color.String(), func(t *testing.T) {
    109  - color := cellColor(tc.color)
    110  - got := fixColor(color, tc.colorMode)
    111  - if got != tc.want {
    112  - t.Errorf("fixColor(%v_%v), => got %v, want %v", tc.colorMode, tc.color, got, tc.want)
    113  - }
    114  - })
    115  - }
    116  -}
    117  - 
    118 27  func TestCellOptsToStyle(t *testing.T) {
    119 28   tests := []struct {
     29 + desc string
    120 30   colorMode terminalapi.ColorMode
    121 31   opts cell.Options
    122 32   want tcell.Style
    123 33   }{
    124 34   {
     35 + desc: "ColorMode256: ColorDefault and ColorBlack",
    125 36   colorMode: terminalapi.ColorMode256,
    126  - opts: cell.Options{FgColor: cell.ColorWhite, BgColor: cell.ColorBlack},
    127  - want: tcell.StyleDefault.Foreground(tcell.ColorSilver).Background(tcell.ColorBlack),
     37 + opts: cell.Options{
     38 + FgColor: cell.ColorDefault,
     39 + BgColor: cell.ColorBlack,
     40 + },
     41 + want: tcell.StyleDefault.
     42 + Foreground(tcell.ColorDefault).
     43 + Background(tcell.ColorBlack),
     44 + },
     45 + {
     46 + desc: "ColorMode256: ColorMaroon and ColorGreen",
     47 + colorMode: terminalapi.ColorMode256,
     48 + opts: cell.Options{
     49 + FgColor: cell.ColorMaroon,
     50 + BgColor: cell.ColorGreen,
     51 + },
     52 + want: tcell.StyleDefault.
     53 + Foreground(tcell.ColorMaroon).
     54 + Background(tcell.ColorGreen),
     55 + },
     56 + {
     57 + desc: "ColorMode256: ColorOlive and ColorNavy",
     58 + colorMode: terminalapi.ColorMode256,
     59 + opts: cell.Options{
     60 + FgColor: cell.ColorOlive,
     61 + BgColor: cell.ColorNavy,
     62 + },
     63 + want: tcell.StyleDefault.
     64 + Foreground(tcell.ColorOlive).
     65 + Background(tcell.ColorNavy),
     66 + },
     67 + {
     68 + desc: "ColorMode256: ColorPurple and ColorTeal",
     69 + colorMode: terminalapi.ColorMode256,
     70 + opts: cell.Options{
     71 + FgColor: cell.ColorPurple,
     72 + BgColor: cell.ColorTeal,
     73 + },
     74 + want: tcell.StyleDefault.
     75 + Foreground(tcell.ColorPurple).
     76 + Background(tcell.ColorTeal),
     77 + },
     78 + {
     79 + desc: "ColorMode256: ColorSilver and ColorGray",
     80 + colorMode: terminalapi.ColorMode256,
     81 + opts: cell.Options{
     82 + FgColor: cell.ColorSilver,
     83 + BgColor: cell.ColorGray,
     84 + },
     85 + want: tcell.StyleDefault.
     86 + Foreground(tcell.ColorSilver).
     87 + Background(tcell.ColorGray),
     88 + },
     89 + {
     90 + desc: "ColorMode256: ColorRed and ColorLime",
     91 + colorMode: terminalapi.ColorMode256,
     92 + opts: cell.Options{
     93 + FgColor: cell.ColorRed,
     94 + BgColor: cell.ColorLime,
     95 + },
     96 + want: tcell.StyleDefault.
     97 + Foreground(tcell.ColorRed).
     98 + Background(tcell.ColorLime),
     99 + },
     100 + {
     101 + desc: "ColorMode256: ColorYellow and ColorBlue",
     102 + colorMode: terminalapi.ColorMode256,
     103 + opts: cell.Options{
     104 + FgColor: cell.ColorYellow,
     105 + BgColor: cell.ColorBlue,
     106 + },
     107 + want: tcell.StyleDefault.
     108 + Foreground(tcell.ColorYellow).
     109 + Background(tcell.ColorBlue),
     110 + },
     111 + {
     112 + desc: "ColorMode256: ColorFuchsia and ColorAqua",
     113 + colorMode: terminalapi.ColorMode256,
     114 + opts: cell.Options{
     115 + FgColor: cell.ColorFuchsia,
     116 + BgColor: cell.ColorAqua,
     117 + },
     118 + want: tcell.StyleDefault.
     119 + Foreground(tcell.ColorFuchsia).
     120 + Background(tcell.ColorAqua),
     121 + },
     122 + {
     123 + desc: "ColorMode256: ColorWhite and ColorDefault",
     124 + colorMode: terminalapi.ColorMode256,
     125 + opts: cell.Options{
     126 + FgColor: cell.ColorWhite,
     127 + BgColor: cell.ColorDefault,
     128 + },
     129 + want: tcell.StyleDefault.
     130 + Foreground(tcell.ColorWhite).
     131 + Background(tcell.ColorDefault),
     132 + },
     133 + {
     134 + desc: "ColorMode256: termbox compatibility colors ColorMagenta and ColorCyan",
     135 + colorMode: terminalapi.ColorMode256,
     136 + opts: cell.Options{
     137 + FgColor: cell.ColorMagenta,
     138 + BgColor: cell.ColorCyan,
     139 + },
     140 + want: tcell.StyleDefault.
     141 + Foreground(tcell.ColorPurple).
     142 + Background(tcell.ColorTeal),
     143 + },
     144 + {
     145 + desc: "ColorMode256: first(0) and last(255) numbered color",
     146 + colorMode: terminalapi.ColorMode256,
     147 + opts: cell.Options{
     148 + FgColor: cell.ColorNumber(0),
     149 + BgColor: cell.ColorNumber(255),
     150 + },
     151 + want: tcell.StyleDefault.
     152 + Foreground(tcell.ColorBlack).
     153 + Background(tcell.Color255),
     154 + },
     155 + {
     156 + desc: "ColorMode256: two numbered colors",
     157 + colorMode: terminalapi.ColorMode256,
     158 + opts: cell.Options{
     159 + FgColor: cell.ColorNumber(33),
     160 + BgColor: cell.ColorNumber(200),
     161 + },
     162 + want: tcell.StyleDefault.
     163 + Foreground(tcell.Color33).
     164 + Background(tcell.Color200),
     165 + },
     166 + {
     167 + desc: "ColorMode256: first and last RGB6 color",
     168 + colorMode: terminalapi.ColorMode256,
     169 + opts: cell.Options{
     170 + FgColor: cell.ColorRGB6(0, 0, 0),
     171 + BgColor: cell.ColorRGB6(5, 5, 5),
     172 + },
     173 + want: tcell.StyleDefault.
     174 + Foreground(tcell.Color16).
     175 + Background(tcell.Color231),
     176 + },
     177 + {
     178 + desc: "ColorMode256: first and last RGB24 color",
     179 + colorMode: terminalapi.ColorMode256,
     180 + opts: cell.Options{
     181 + FgColor: cell.ColorRGB24(0, 0, 0),
     182 + BgColor: cell.ColorRGB24(255, 255, 255),
     183 + },
     184 + want: tcell.StyleDefault.
     185 + Foreground(tcell.Color16).
     186 + Background(tcell.Color231),
    128 187   },
    129 188   {
     189 + desc: "ColorModeNormal: first and last color",
    130 190   colorMode: terminalapi.ColorModeNormal,
    131  - opts: cell.Options{FgColor: cell.ColorWhite, BgColor: cell.ColorBlack},
    132  - want: tcell.StyleDefault.Foreground(tcell.ColorSilver).Background(tcell.ColorBlack),
     191 + opts: cell.Options{
     192 + FgColor: cell.ColorBlack,
     193 + BgColor: cell.ColorWhite,
     194 + },
     195 + want: tcell.StyleDefault.
     196 + Foreground(tcell.ColorBlack).
     197 + Background(tcell.ColorWhite),
     198 + },
     199 + {
     200 + desc: "ColorModeNormal: colors in the middle",
     201 + colorMode: terminalapi.ColorModeNormal,
     202 + opts: cell.Options{
     203 + FgColor: cell.ColorGreen,
     204 + BgColor: cell.ColorOlive,
     205 + },
     206 + want: tcell.StyleDefault.
     207 + Foreground(tcell.ColorGreen).
     208 + Background(tcell.ColorOlive),
     209 + },
     210 + {
     211 + desc: "ColorModeNormal: colors above the range rotate back",
     212 + colorMode: terminalapi.ColorModeNormal,
     213 + opts: cell.Options{
     214 + FgColor: cell.ColorNumber(17),
     215 + BgColor: cell.ColorNumber(18),
     216 + },
     217 + want: tcell.StyleDefault.
     218 + Foreground(tcell.ColorBlack).
     219 + Background(tcell.ColorMaroon),
    133 220   },
    134 221   {
    135  - colorMode: terminalapi.ColorModeGrayscale,
    136  - opts: cell.Options{FgColor: cell.ColorWhite, BgColor: cell.ColorBlack},
    137  - want: tcell.StyleDefault.Foreground(tcell.Color239).Background(tcell.Color232),
     222 + desc: "ColorMode216: first and last color",
     223 + colorMode: terminalapi.ColorMode216,
     224 + opts: cell.Options{
     225 + FgColor: cell.ColorNumber(0),
     226 + BgColor: cell.ColorNumber(215),
     227 + },
     228 + want: tcell.StyleDefault.
     229 + Foreground(tcell.Color16).
     230 + Background(tcell.Color231),
    138 231   },
    139 232   {
     233 + desc: "ColorMode216: colors in the middle",
    140 234   colorMode: terminalapi.ColorMode216,
    141  - opts: cell.Options{FgColor: cell.ColorWhite, BgColor: cell.ColorBlack},
    142  - want: tcell.StyleDefault.Foreground(tcell.Color23).Background(tcell.Color16),
     235 + opts: cell.Options{
     236 + FgColor: cell.ColorNumber(1),
     237 + BgColor: cell.ColorNumber(2),
     238 + },
     239 + want: tcell.StyleDefault.
     240 + Foreground(tcell.Color17).
     241 + Background(tcell.Color18),
     242 + },
     243 + {
     244 + desc: "ColorMode216: colors above the range rotate back",
     245 + colorMode: terminalapi.ColorMode216,
     246 + opts: cell.Options{
     247 + FgColor: cell.ColorNumber(216),
     248 + BgColor: cell.ColorNumber(217),
     249 + },
     250 + want: tcell.StyleDefault.
     251 + Foreground(tcell.Color16).
     252 + Background(tcell.Color17),
     253 + },
     254 + {
     255 + desc: "ColorModeGrayscale: first and last color",
     256 + colorMode: terminalapi.ColorModeGrayscale,
     257 + opts: cell.Options{
     258 + FgColor: cell.ColorNumber(0),
     259 + BgColor: cell.ColorNumber(23),
     260 + },
     261 + want: tcell.StyleDefault.
     262 + Foreground(tcell.Color232).
     263 + Background(tcell.Color255),
     264 + },
     265 + {
     266 + desc: "ColorModeGrayscale: colors in the middle",
     267 + colorMode: terminalapi.ColorModeGrayscale,
     268 + opts: cell.Options{
     269 + FgColor: cell.ColorNumber(1),
     270 + BgColor: cell.ColorNumber(2),
     271 + },
     272 + want: tcell.StyleDefault.
     273 + Foreground(tcell.Color233).
     274 + Background(tcell.Color234),
     275 + },
     276 + {
     277 + desc: "ColorModeGrayscale: colors above the range rotate back",
     278 + colorMode: terminalapi.ColorModeGrayscale,
     279 + opts: cell.Options{
     280 + FgColor: cell.ColorNumber(24),
     281 + BgColor: cell.ColorNumber(25),
     282 + },
     283 + want: tcell.StyleDefault.
     284 + Foreground(tcell.Color232).
     285 + Background(tcell.Color233),
     286 + },
     287 + {
     288 + desc: "Unknown color mode converts to default color",
     289 + colorMode: terminalapi.ColorMode(-1),
     290 + opts: cell.Options{
     291 + FgColor: cell.ColorNumber(24),
     292 + BgColor: cell.ColorNumber(25),
     293 + },
     294 + want: tcell.StyleDefault.
     295 + Foreground(tcell.ColorDefault).
     296 + Background(tcell.ColorDefault),
    143 297   },
    144 298   {
    145 299   colorMode: terminalapi.ColorModeNormal,
    skipped 13 lines
    159 313   }
    160 314   
    161 315   for _, tc := range tests {
    162  - t.Run(tc.opts.FgColor.String()+"+"+tc.opts.BgColor.String(), func(t *testing.T) {
     316 + t.Run(tc.desc, func(t *testing.T) {
    163 317   got := cellOptsToStyle(&tc.opts, tc.colorMode)
    164  - if got != tc.want {
    165  - fg, bg, _ := got.Decompose()
    166  - wantFg, wantBg, _ := tc.want.Decompose()
    167  - t.Errorf("cellOptsToStyle(%v, fg=%v, bg=%v) => got (fg=%X, bg=%X), want (fg=%X, bg=%X)",
    168  - tc.colorMode, tc.opts.FgColor, tc.opts.BgColor, fg, bg, wantFg, wantBg)
     318 + if !reflect.DeepEqual(got, tc.want) {
     319 + diff := pretty.Compare(tc.want, got)
     320 + t.Logf("opts: %+v\nstyle:%+v", tc.opts, got)
     321 + t.Errorf("cellOptsToStyle => unexpected diff (-want, +got):\n%s", diff)
    169 322   }
    170 323   })
    171 324   }
    skipped 2 lines
  • ■ ■ ■ ■
    terminal/tcell/event.go
    skipped 16 lines
    17 17  import (
    18 18   "image"
    19 19   
    20  - "github.com/gdamore/tcell"
     20 + tcell "github.com/gdamore/tcell/v2"
    21 21   "github.com/mum4k/termdash/keyboard"
    22 22   "github.com/mum4k/termdash/mouse"
    23 23   "github.com/mum4k/termdash/terminal/terminalapi"
    skipped 175 lines
  • ■ ■ ■ ■
    terminal/tcell/event_test.go
    skipped 20 lines
    21 21   "testing"
    22 22   "time"
    23 23   
    24  - "github.com/gdamore/tcell"
     24 + tcell "github.com/gdamore/tcell/v2"
    25 25   "github.com/kylelemons/godebug/pretty"
    26 26   "github.com/mum4k/termdash/keyboard"
    27 27   "github.com/mum4k/termdash/mouse"
    skipped 255 lines
  • ■ ■ ■ ■ ■ ■
    terminal/tcell/tcell.go
    skipped 18 lines
    19 19   "fmt"
    20 20   "image"
    21 21   
    22  - "github.com/gdamore/tcell"
    23  - "github.com/gdamore/tcell/encoding"
     22 + tcell "github.com/gdamore/tcell/v2"
     23 + "github.com/gdamore/tcell/v2/encoding"
    24 24   "github.com/mum4k/termdash/cell"
    25 25   "github.com/mum4k/termdash/private/event/eventqueue"
    26 26   "github.com/mum4k/termdash/terminal/terminalapi"
    skipped 179 lines
  • ■ ■ ■ ■
    terminal/tcell/tcell_test.go
    skipped 16 lines
    17 17  import (
    18 18   "testing"
    19 19   
    20  - "github.com/gdamore/tcell"
     20 + tcell "github.com/gdamore/tcell/v2"
    21 21   "github.com/kylelemons/godebug/pretty"
    22 22   "github.com/mum4k/termdash/cell"
    23 23   "github.com/mum4k/termdash/terminal/terminalapi"
    skipped 99 lines
  • ■ ■ ■ ■ ■ ■
    terminal/termbox/cell_options.go
    skipped 24 lines
    25 25   
    26 26  // cellColor converts termdash cell color to the termbox format.
    27 27  func cellColor(c cell.Color) tbx.Attribute {
    28  - return tbx.Attribute(c)
     28 + // Special cases for backward compatibility after we have aligned the
     29 + // definition of the first 16 colors with Xterm and tcell.
     30 + // This ensures that users that run with termbox-go don't experience any
     31 + // change in colors.
     32 + switch c {
     33 + case cell.ColorRed:
     34 + return tbx.Attribute(cell.ColorMaroon)
     35 + case cell.ColorYellow:
     36 + return tbx.Attribute(cell.ColorOlive)
     37 + case cell.ColorBlue:
     38 + return tbx.Attribute(cell.ColorNavy)
     39 + case cell.ColorWhite:
     40 + return tbx.Attribute(cell.ColorSilver)
     41 + default:
     42 + return tbx.Attribute(c)
     43 + }
    29 44  }
    30 45   
    31 46  // cellOptsToFg converts the cell options to the termbox foreground attribute.
    skipped 24 lines
  • ■ ■ ■ ■ ■ ■
    terminal/terminalapi/color_mode.go
    skipped 36 lines
    37 37   
    38 38  // Supported color modes.
    39 39  const (
    40  - // ColorModeNormal supports 8 "system" colors.
     40 + // ColorModeNormal supports 16 Xterm colors.
    41 41   // These are defined as constants in the cell package.
    42 42   ColorModeNormal ColorMode = iota
    43 43   
    44 44   // ColorMode256 enables using any of the 256 terminal colors.
    45  - // 0-7: the 8 "system" colors accessible in ColorModeNormal.
    46  - // 8-15: the 8 "bright system" colors.
     45 + // 0-7: the 8 Xterm colors accessible in ColorModeNormal.
     46 + // 8-15: the 8 "bright" Xterm colors.
    47 47   // 16-231: the 216 different terminal colors.
    48 48   // 232-255: the 24 different shades of grey.
    49 49   ColorMode256
    skipped 12 lines
Please wait...
Page is in error, reload to recover