4
4
5
5
use PhpSchool \CliMenu \Exception \InvalidInstantiationException ;
6
6
use PhpSchool \CliMenu \Terminal \TerminalFactory ;
7
+ use PhpSchool \CliMenu \Util \ColourUtil ;
7
8
use PhpSchool \Terminal \Terminal ;
8
9
9
10
//TODO: B/W fallback
@@ -177,11 +178,6 @@ public function __construct(Terminal $terminal = null)
177
178
$ this ->setTitleSeparator (static ::$ defaultStyleValues ['titleSeparator ' ]);
178
179
}
179
180
180
- public static function getAvailableColours () : array
181
- {
182
- return array_keys (self ::$ availableBackgroundColors );
183
- }
184
-
185
181
public function getDisabledItemText (string $ text ) : string
186
182
{
187
183
return sprintf (
@@ -259,15 +255,11 @@ public function getFg()
259
255
260
256
public function setFg ($ fg , string $ fallback = null ) : self
261
257
{
262
- if (is_int ($ fg )) {
263
- if ($ this ->terminal ->getColourSupport () < 256 ) {
264
- $ fg = $ fallback ;
265
- } elseif ($ fg < 0 || $ fg > 255 ) {
266
- throw new \InvalidArgumentException ("Invalid colour code " );
267
- }
268
- }
269
-
270
- $ this ->fg = $ fg ;
258
+ $ this ->fg = ColourUtil::validateColour (
259
+ $ this ->terminal ,
260
+ $ colour ,
261
+ $ fallback
262
+ );
271
263
$ this ->generateColoursSetCode ();
272
264
273
265
return $ this ;
@@ -280,14 +272,11 @@ public function getBg()
280
272
281
273
public function setBg ($ bg , string $ fallback = null ) : self
282
274
{
283
- if (is_int ($ bg )) {
284
- if ($ this ->terminal ->getColourSupport () < 256 ) {
285
- $ bg = $ fallback ;
286
- } elseif ($ bg < 0 || $ bg > 255 ) {
287
- throw new \InvalidArgumentException ("Invalid colour code " );
288
- }
289
- }
290
- $ this ->bg = $ bg ;
275
+ $ this ->bg = ColourUtil::validateColour (
276
+ $ this ->terminal ,
277
+ $ colour ,
278
+ $ fallback
279
+ );
291
280
$ this ->generateColoursSetCode ();
292
281
293
282
return $ this ;
0 commit comments