bduggan / raku-terminal-ui

A framework for building terminal inferfaces in Raku
MIT License
2 stars 0 forks source link

Sending colored content to .splash #3

Open Xliff opened 1 month ago

Xliff commented 1 month ago

I have colored content I'd like to send to splash, but it is rendering incorrectly.

What would I need to do. There is only color codes in the string I am sending in.

Thanks

bduggan commented 1 month ago

Here's a simple splash example with color:

use Terminal::UI 'ui';
use Terminal::ANSI::OO 't';

ui.setup(:1pane);
ui.pane.splash( [ t.green => 'hello', t.text-reset => 'world' ] );
ui.get-key;
ui.shutdown;

The formatting codes need to be in the keys of the pairs that are sent.

The reason it works this way is because in order to center things horizontally, the text portion is used to compute the indentation.

Xliff commented 1 month ago

What if there was a way to pass in the width of the actual text to center?

Would splash still be the best way to do it or would I need another method to add in the raw content?

bduggan commented 1 month ago

Hmm, passing the width could remove that requirement I suppose -- but it could take some work -- splash just uses put which looks for either text or format => text pairs, so this method would probably need a way to take text that also had escape sequences...things would get unfortunate when callbacks are triggered and the text conatins formatting codes though, so if there's a way to separate them I think that's ideal.