Skip to content

Commit

Permalink
Adjust input widget rendering based on available symbol set
Browse files Browse the repository at this point in the history
  • Loading branch information
japhb committed May 21, 2023
1 parent bc9bff9 commit 0d77720
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
8 changes: 5 additions & 3 deletions lib/Terminal/Widgets/Input/Button.rakumod
@@ -1,5 +1,6 @@
# ABSTRACT: General clickable button

use Terminal::Widgets::TerminalCapabilities;
use Terminal::Widgets::Events;
use Terminal::Widgets::Input;
use Terminal::Widgets::Input::Labeled;
Expand All @@ -10,9 +11,10 @@ class Terminal::Widgets::Input::Button
does Terminal::Widgets::Input::Labeled {
#| Refresh the whole input
method full-refresh(Bool:D :$print = True) {
# my $text = '[' ~ (self.label || 'Button') ~ ']';
my $text = '⌈' ~ (self.label || 'Button') ~ 'βŒ‹';

my $label = self.label || 'Button';
my $symbol-set = self.terminal.caps.symbol-set;
my $text = $symbol-set >= Uni1 ?? '⌈' ~ $label ~ 'βŒ‹'
!! '[' ~ $label ~ ']';
$.grid.clear;
$.grid.set-span(0, 0, $text, self.current-color);
self.composite(:$print);
Expand Down
8 changes: 6 additions & 2 deletions lib/Terminal/Widgets/Input/Checkbox.rakumod
Expand Up @@ -10,8 +10,12 @@ class Terminal::Widgets::Input::Checkbox
does Terminal::Widgets::Input::Labeled {
#| Checkbox glyphs
method checkbox-text() {
# $.state ?? '[x]' !! '[ ]'
$.state ?? 'πŸž•' !! '🞏'
my constant %boxes =
ASCII => Β« '[ ]' [x] Β»,
Uni1 => Β« ☐ β˜’ Β»,
Uni7 => Β« 🞏 πŸž• Β»;

self.terminal.caps.best-symbol-choice(%boxes)[+$.state]
}

#| Refresh just the value, without changing anything else
Expand Down
8 changes: 6 additions & 2 deletions lib/Terminal/Widgets/Input/RadioButton.rakumod
Expand Up @@ -27,8 +27,12 @@ class Terminal::Widgets::Input::RadioButton

#| Radio button glyphs
method button-text() {
# $.state ?? '(*)' !! '( )'
$.state ?? '🞊' !! 'πŸž…';
my constant %buttons =
ASCII => Β« '( )' (*) Β»,
Uni1 => Β« β—‹ βŠ™ Β»,
Uni7 => Β« πŸž… 🞊 Β»;

self.terminal.caps.best-symbol-choice(%buttons)[+$.state]
}

#| Refresh just the value, without changing anything else
Expand Down

0 comments on commit 0d77720

Please sign in to comment.