Skip to content

Commit 5919d2b

Browse files
Copilotswissspidy
andcommitted
Remove unused getActiveColor function
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 5dc813f commit 5919d2b

File tree

1 file changed

+0
-63
lines changed

1 file changed

+0
-63
lines changed

lib/cli/Colors.php

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -281,69 +281,6 @@ static public function clearStringCache() {
281281
self::$_string_cache = array();
282282
}
283283

284-
/**
285-
* Get the active color code at the end of a colorized string.
286-
*
287-
* This function extracts the last active color state from a string that contains
288-
* color codes. It's used to maintain color continuity when wrapping text.
289-
*
290-
* @param string $string The string to analyze.
291-
* @param bool $pre_colorized Whether the string contains ANSI codes (true) or color tokens (false).
292-
* @return string The active color token/code or empty string if no color is active.
293-
*/
294-
static public function getActiveColor( $string, $pre_colorized = false ) {
295-
$string = (string) $string;
296-
297-
if ( $pre_colorized ) {
298-
// For pre-colorized strings, we need to track ANSI escape codes
299-
// Pattern: \x1b[...m where ... can be numbers separated by semicolons
300-
$pattern = '/\x1b\[([0-9;]+)m/';
301-
$matches = array();
302-
preg_match_all( $pattern, $string, $matches, PREG_OFFSET_CAPTURE );
303-
304-
if ( empty( $matches[0] ) ) {
305-
return '';
306-
}
307-
308-
// Get the last ANSI code
309-
$last_code = end( $matches[0] )[0];
310-
$last_params = end( $matches[1] )[0];
311-
312-
// If it's a reset code (0 or 0m), no color is active
313-
if ( $last_params === '0' ) {
314-
return '';
315-
}
316-
317-
// Return the full ANSI code
318-
return $last_code;
319-
} else {
320-
// Track the last seen color token
321-
$last_color = '';
322-
323-
// Get all color tokens
324-
$colors = self::getColors();
325-
326-
// Find all color tokens in the string
327-
foreach ( $colors as $token => $value ) {
328-
$pos = 0;
329-
while ( ( $pos = strpos( $string, $token, $pos ) ) !== false ) {
330-
// Make sure this isn't an escaped %%
331-
if ( $pos === 0 || $string[ $pos - 1 ] !== '%' ) {
332-
$last_color = $token;
333-
}
334-
$pos += strlen( $token );
335-
}
336-
}
337-
338-
// If the last color was a reset (%n or %N), return empty
339-
if ( $last_color === '%n' || $last_color === '%N' ) {
340-
return '';
341-
}
342-
343-
return $last_color;
344-
}
345-
}
346-
347284
/**
348285
* Get the ANSI reset code.
349286
*

0 commit comments

Comments
 (0)