mirror of
https://github.com/aristocratos/btop.git
synced 2024-09-29 22:51:35 +02:00
Changed: Regex for Fx::uncolor() changed to string search and replace
This commit is contained in:
parent
ce2a2797b8
commit
36c74fb08a
@ -139,6 +139,25 @@ namespace Term {
|
|||||||
|
|
||||||
//? --------------------------------------------------- FUNCTIONS -----------------------------------------------------
|
//? --------------------------------------------------- FUNCTIONS -----------------------------------------------------
|
||||||
|
|
||||||
|
namespace Fx {
|
||||||
|
string uncolor(const string& s) {
|
||||||
|
string out = s;
|
||||||
|
for (size_t offset = 0, start_pos = 0, end_pos = 0, next_pos = 0;;) {
|
||||||
|
if ((start_pos = next_pos > 0 ? next_pos : out.find('\x1b', offset)) == string::npos)
|
||||||
|
break;
|
||||||
|
offset = start_pos;
|
||||||
|
if ((end_pos = out.find('m', offset)) == string::npos)
|
||||||
|
break;
|
||||||
|
else if (next_pos = out.find('\x1b', offset + 1); end_pos - start_pos > next_pos - start_pos)
|
||||||
|
continue;
|
||||||
|
out.replace(start_pos, (end_pos - start_pos) + 1, "");
|
||||||
|
next_pos = 0;
|
||||||
|
}
|
||||||
|
out.shrink_to_fit();
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
namespace Tools {
|
namespace Tools {
|
||||||
|
|
||||||
atomic<int> active_locks (0);
|
atomic<int> active_locks (0);
|
||||||
|
@ -64,7 +64,7 @@ namespace Fx {
|
|||||||
const regex color_regex("\033\\[\\d+;?\\d?;?\\d*;?\\d*;?\\d*(m){1}");
|
const regex color_regex("\033\\[\\d+;?\\d?;?\\d*;?\\d*;?\\d*(m){1}");
|
||||||
|
|
||||||
//* Return a string with all colors and text styling removed
|
//* Return a string with all colors and text styling removed
|
||||||
inline string uncolor(const string& s) { return regex_replace(s, color_regex, ""); }
|
string uncolor(const string& s);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user