Closed vincentaxhe closed 1 month ago
if I select and colorize it, and update pane, maybe will do what I want
Thanks! Your program is nice! I had to make a little change to use slurp(:close)
instead of slurp
in a few places to stop nmcli
from waiting, but otherwise it worked well.
For divide.raku, colorizing and updating sounds like the way to go, something like:
#!/usr/bin/env raku
use Terminal::UI 'ui';
use Terminal::ANSI::OO 't';
ui.setup: :2panes;
my (\top,\bottom) = ui.panes;
top.put: [ t.white => "$_" ], meta => %( :line($_) ) for 0..9;
my $last;
top.on: select => -> :$raw, :%meta {
my $line = +%meta<line>;
top.update: :$line, [ t.yellow => +$line ];
ui.refresh;
bottom.put: "selected $line";
with $last {
if ($line == 0) {
bottom.put: "cannot divide by zero";
} else {
bottom.put: "$last / $line = {$last / $line}";
}
}
$last = $line;
};
ui.interact;
ui.shutdown;
use update method is the right way instead of reput everything, it's annoying to back from top. your example help me on that. It take me some time to recognize the flexibility of bind, pane on, %meta, in general it's great design! maybe some more examples will be helpful. Like the sticky color example above. I finished my pactl-tui in two days, it's a great journey.
There are a number of examples here:
https://github.com/bduggan/raku-terminal-ui/tree/master/eg
But always happy to add more!
Thanks for the nice feedback!
glad to find an terminal tui module developed by Raku, its simple interface is a great advantage. I have write my first raku tui program 'nmtui.raku' which is for switching wifi connection,
The selection support is sufficient for such work But I want write another one. for example 'divide.raku', put 0-9,I want to calculate 9 / 4 / 1, I can select '9', '4', '1', then '9', '4', '1' is stay highlighted until I reverse select any of them, the color is attached to the number when scroll, then I want to do some check, if '0' is selected ,there is a warning on second pane 'divide by zero is illegal' or output the result.