Skip to content

Commit e4acf56

Browse files
committed
Provide a RenderSpan.Str method to get an SGR-escaped string
1 parent 44b59db commit e4acf56

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

META6.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
],
88
"depends": [
99
"Color::DirColors:auth<zef:japhb>:ver<0.0.3+>",
10+
"Terminal::ANSIColor:ver<0.14+>:auth<zef:raku-community-modules>"
1011
"Terminal::Capabilities:auth<zef:japhb>:ver<0.0.14+>",
1112
"Terminal::LineEditor:auth<zef:japhb>:ver<0.0.23+>",
1213
"Terminal::Print:auth<zef:terminal-printers>:ver<0.977+>",

lib/Terminal/Widgets/TextContent.rakumod

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
unit module Terminal::Widgets::TextContent;
44

55
use Text::MiscUtils::Layout;
6+
use Terminal::ANSIColor;
67

78

89
#| An exception preventing stringification for content that requires more processing
@@ -38,6 +39,12 @@ class RenderSpan is export {
3839
method width(--> UInt:D) {
3940
$!width //= duospace-width-core($!text)
4041
}
42+
43+
#| Stringify to an SGR-escaped string instead of rendering into a widget's
44+
#| content area (use Widget.draw-line-spans for that)
45+
method Str(--> Str:D) {
46+
colored($!text, $!color)
47+
}
4148
}
4249

4350

0 commit comments

Comments
 (0)