Projects STRLCPY termdash Commits 386afb91
🤬
  • ■ ■ ■ ■ ■ ■
    CHANGELOG.md
    skipped 10 lines
    11 11   
    12 12  - Bump github.com/gdamore/tcell/v2 from 2.0.0 to 2.1.0.
    13 13   
     14 +### Added
     15 + 
     16 +- TitleColor and TitleFocusedColor options for border title which enables the
     17 + setting of separate colors for border and title on a container.
     18 + 
     19 + 
    14 20  ## [0.14.0] - 30-Dec-2020
    15 21   
    16 22  ### Breaking API changes
    skipped 450 lines
  • ■ ■ ■ ■ ■ ■
    container/container_test.go
    skipped 1003 lines
    1004 1004   },
    1005 1005   },
    1006 1006   {
     1007 + desc: "sets border title on root container of different color",
     1008 + termSize: image.Point{10, 10},
     1009 + container: func(ft *faketerm.Terminal) (*Container, error) {
     1010 + return New(
     1011 + ft,
     1012 + Border(linestyle.Light),
     1013 + BorderTitle("Ab"),
     1014 + BorderColor(cell.ColorRed),
     1015 + FocusedColor(cell.ColorBlue),
     1016 + TitleColor(cell.ColorMagenta),
     1017 + TitleFocusedColor(cell.ColorCyan),
     1018 + SplitVertical(
     1019 + Left(
     1020 + Border(linestyle.Light),
     1021 + ),
     1022 + Right(
     1023 + Border(linestyle.Light),
     1024 + ),
     1025 + ),
     1026 + )
     1027 + },
     1028 + want: func(size image.Point) *faketerm.Terminal {
     1029 + ft := faketerm.MustNew(size)
     1030 + cvs := testcanvas.MustNew(ft.Area())
     1031 + testdraw.MustBorder(
     1032 + cvs,
     1033 + image.Rect(0, 0, 10, 10),
     1034 + draw.BorderCellOpts(cell.FgColor(cell.ColorBlue)),
     1035 + )
     1036 + testdraw.MustBorder(
     1037 + cvs,
     1038 + image.Rect(1, 1, 5, 9),
     1039 + draw.BorderCellOpts(cell.FgColor(cell.ColorRed)),
     1040 + )
     1041 + testdraw.MustBorder(
     1042 + cvs,
     1043 + image.Rect(5, 1, 9, 9),
     1044 + draw.BorderCellOpts(cell.FgColor(cell.ColorRed)),
     1045 + )
     1046 + testdraw.MustText(
     1047 + cvs,
     1048 + "Ab",
     1049 + image.Point{1, 0},
     1050 + draw.TextCellOpts(cell.FgColor(cell.ColorCyan)),
     1051 + )
     1052 + testcanvas.MustApply(cvs, ft)
     1053 + return ft
     1054 + },
     1055 + },
     1056 + {
     1057 + desc: "sets different color title on left child container",
     1058 + termSize: image.Point{10, 10},
     1059 + container: func(ft *faketerm.Terminal) (*Container, error) {
     1060 + return New(
     1061 + ft,
     1062 + Border(linestyle.Light),
     1063 + BorderColor(cell.ColorRed),
     1064 + FocusedColor(cell.ColorBlue),
     1065 + SplitVertical(
     1066 + Left(
     1067 + Border(linestyle.Light),
     1068 + BorderTitle("Ab"),
     1069 + TitleColor(cell.ColorMagenta),
     1070 + TitleFocusedColor(cell.ColorCyan),
     1071 + ),
     1072 + Right(
     1073 + Border(linestyle.Light),
     1074 + ),
     1075 + ),
     1076 + )
     1077 + },
     1078 + want: func(size image.Point) *faketerm.Terminal {
     1079 + ft := faketerm.MustNew(size)
     1080 + cvs := testcanvas.MustNew(ft.Area())
     1081 + testdraw.MustBorder(
     1082 + cvs,
     1083 + image.Rect(0, 0, 10, 10),
     1084 + draw.BorderCellOpts(cell.FgColor(cell.ColorBlue)),
     1085 + )
     1086 + testdraw.MustBorder(
     1087 + cvs,
     1088 + image.Rect(1, 1, 5, 9),
     1089 + draw.BorderCellOpts(cell.FgColor(cell.ColorRed)),
     1090 + )
     1091 + testdraw.MustBorder(
     1092 + cvs,
     1093 + image.Rect(5, 1, 9, 9),
     1094 + draw.BorderCellOpts(cell.FgColor(cell.ColorRed)),
     1095 + )
     1096 + testdraw.MustText(
     1097 + cvs,
     1098 + "Ab",
     1099 + image.Point{2, 1},
     1100 + draw.TextCellOpts(cell.FgColor(cell.ColorMagenta)),
     1101 + )
     1102 + testcanvas.MustApply(cvs, ft)
     1103 + return ft
     1104 + },
     1105 + },
     1106 + {
     1107 + desc: "inherits the border color for the title on left child container when TitleColor is not set",
     1108 + termSize: image.Point{10, 10},
     1109 + container: func(ft *faketerm.Terminal) (*Container, error) {
     1110 + return New(
     1111 + ft,
     1112 + Border(linestyle.Light),
     1113 + BorderColor(cell.ColorRed),
     1114 + FocusedColor(cell.ColorBlue),
     1115 + SplitVertical(
     1116 + Left(
     1117 + Border(linestyle.Light),
     1118 + BorderTitle("Ab"),
     1119 + ),
     1120 + Right(
     1121 + Border(linestyle.Light),
     1122 + ),
     1123 + ),
     1124 + )
     1125 + },
     1126 + want: func(size image.Point) *faketerm.Terminal {
     1127 + ft := faketerm.MustNew(size)
     1128 + cvs := testcanvas.MustNew(ft.Area())
     1129 + testdraw.MustBorder(
     1130 + cvs,
     1131 + image.Rect(0, 0, 10, 10),
     1132 + draw.BorderCellOpts(cell.FgColor(cell.ColorBlue)),
     1133 + )
     1134 + testdraw.MustBorder(
     1135 + cvs,
     1136 + image.Rect(1, 1, 5, 9),
     1137 + draw.BorderCellOpts(cell.FgColor(cell.ColorRed)),
     1138 + )
     1139 + testdraw.MustBorder(
     1140 + cvs,
     1141 + image.Rect(5, 1, 9, 9),
     1142 + draw.BorderCellOpts(cell.FgColor(cell.ColorRed)),
     1143 + )
     1144 + testdraw.MustText(
     1145 + cvs,
     1146 + "Ab",
     1147 + image.Point{2, 1},
     1148 + draw.TextCellOpts(cell.FgColor(cell.ColorRed)),
     1149 + )
     1150 + testcanvas.MustApply(cvs, ft)
     1151 + return ft
     1152 + },
     1153 + },
     1154 + {
    1007 1155   desc: "splitting a container removes the widget",
    1008 1156   termSize: image.Point{10, 10},
    1009 1157   container: func(ft *faketerm.Terminal) (*Container, error) {
    skipped 1899 lines
  • ■ ■ ■ ■ ■
    container/draw.go
    skipped 83 lines
    84 84   return err
    85 85   }
    86 86   
    87  - var cOpts []cell.Option
     87 + var cOpts, titleCOpts []cell.Option
    88 88   if c.focusTracker.isActive(c) {
    89 89   cOpts = append(cOpts, cell.FgColor(c.opts.inherited.focusedColor))
     90 + if c.opts.inherited.titleFocusedColor != nil {
     91 + titleCOpts = append(titleCOpts, cell.FgColor(*c.opts.inherited.titleFocusedColor))
     92 + } else {
     93 + titleCOpts = cOpts
     94 + }
    90 95   } else {
    91 96   cOpts = append(cOpts, cell.FgColor(c.opts.inherited.borderColor))
     97 + if c.opts.inherited.titleColor != nil {
     98 + titleCOpts = append(titleCOpts, cell.FgColor(*c.opts.inherited.titleColor))
     99 + } else {
     100 + titleCOpts = cOpts
     101 + }
    92 102   }
    93 103   
    94 104   if err := draw.Border(cvs, ar,
    95 105   draw.BorderLineStyle(c.opts.border),
    96  - draw.BorderTitle(c.opts.borderTitle, draw.OverrunModeThreeDot, cOpts...),
     106 + draw.BorderTitle(c.opts.borderTitle, draw.OverrunModeThreeDot, titleCOpts...),
    97 107   draw.BorderTitleAlign(c.opts.borderTitleHAlign),
    98 108   draw.BorderCellOpts(cOpts...),
    99 109   ); err != nil {
    skipped 77 lines
  • ■ ■ ■ ■ ■ ■
    container/draw_test.go
    skipped 502 lines
    503 503   },
    504 504   },
    505 505   {
     506 + desc: "draws widget with container border and title with different color and focus color",
     507 + termSize: image.Point{9, 5},
     508 + container: func(ft *faketerm.Terminal) (*Container, error) {
     509 + return New(
     510 + ft,
     511 + Border(linestyle.Light),
     512 + BorderTitle("ab"),
     513 + TitleColor(cell.ColorBlue),
     514 + // The created container is in focus so we must set the focus color
     515 + // in order to see the difference.
     516 + TitleFocusedColor(cell.ColorBlue),
     517 + BorderTitleAlignLeft(),
     518 + PlaceWidget(fakewidget.New(widgetapi.Options{})),
     519 + )
     520 + },
     521 + want: func(size image.Point) *faketerm.Terminal {
     522 + ft := faketerm.MustNew(size)
     523 + cvs := testcanvas.MustNew(ft.Area())
     524 + // Container border.
     525 + testdraw.MustBorder(
     526 + cvs,
     527 + cvs.Area(),
     528 + draw.BorderCellOpts(cell.FgColor(cell.ColorYellow)),
     529 + draw.BorderTitle(
     530 + "ab",
     531 + draw.OverrunModeThreeDot,
     532 + cell.FgColor(cell.ColorBlue),
     533 + ),
     534 + )
     535 + 
     536 + // Fake widget border.
     537 + testdraw.MustBorder(cvs, image.Rect(1, 1, 8, 4))
     538 + testdraw.MustText(cvs, "(7,3)", image.Point{2, 2})
     539 + testcanvas.MustApply(cvs, ft)
     540 + return ft
     541 + },
     542 + },
     543 + {
    506 544   desc: "draws widget without container border",
    507 545   termSize: image.Point{9, 5},
    508 546   container: func(ft *faketerm.Terminal) (*Container, error) {
    skipped 640 lines
  • ■ ■ ■ ■ ■ ■
    container/options.go
    skipped 193 lines
    194 194   borderColor cell.Color
    195 195   // focusedColor is the color used for the border when focused.
    196 196   focusedColor cell.Color
     197 + // titleColor is the color used for the title.
     198 + titleColor *cell.Color
     199 + // titleFocusedColor is the color used for the title when focused.
     200 + titleFocusedColor *cell.Color
    197 201  }
    198 202   
    199 203  // focusGroups maps focus group numbers that have the same key assigned.
    skipped 545 lines
    745 749  func FocusedColor(color cell.Color) Option {
    746 750   return option(func(c *Container) error {
    747 751   c.opts.inherited.focusedColor = color
     752 + return nil
     753 + })
     754 +}
     755 + 
     756 +// TitleColor sets the color of the title around the container.
     757 +// This option is inherited to sub containers created by container splits.
     758 +func TitleColor(color cell.Color) Option {
     759 + return option(func(c *Container) error {
     760 + c.opts.inherited.titleColor = &color
     761 + return nil
     762 + })
     763 +}
     764 + 
     765 +// TitleFocusedColor sets the color of the container title when it has
     766 +// keyboard focus.
     767 +// This option is inherited to sub containers created by container splits.
     768 +func TitleFocusedColor(color cell.Color) Option {
     769 + return option(func(c *Container) error {
     770 + c.opts.inherited.titleFocusedColor = &color
    748 771   return nil
    749 772   })
    750 773  }
    skipped 297 lines
Please wait...
Page is in error, reload to recover