Skip to content

Commit 445ed5d

Browse files
authored
Merge pull request #5094 from Textualize/digits-hex
Added hex chars to digits
2 parents 063cfc7 + 54d7dd6 commit 445ed5d

File tree

9 files changed

+386
-258
lines changed

9 files changed

+386
-258
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## Unreleased
9+
10+
### Added
11+
12+
- Added support for A-F to Digits widget https://github.com/Textualize/textual/pull/5094
13+
14+
### Changed
15+
16+
- Digits are now thin by default, style with text-style: bold to get bold digits https://github.com/Textualize/textual/pull/5094
17+
818
## [0.82.0] - 2024-10-03
919

1020
### Fixed

docs/blog/images/compositor/cuts.excalidraw.svg

Lines changed: 21 additions & 0 deletions
Loading

src/textual/renderables/digits.py

Lines changed: 100 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
from rich.segment import Segment
66
from rich.style import Style, StyleType
77

8-
DIGITS = " 0123456789+-^x:"
9-
DIGITS3X3 = """\
8+
DIGITS = " 0123456789+-^x:ABCDEF"
9+
DIGITS3X3_BOLD = """\
1010
1111
1212
@@ -55,6 +55,96 @@
5555
5656
:
5757
58+
╭─╮
59+
├─┤
60+
╵ ╵
61+
┌─╮
62+
├─┤
63+
└─╯
64+
╭─╮
65+
66+
╰─╯
67+
┌─╮
68+
│ │
69+
└─╯
70+
╭─╴
71+
├─
72+
╰─╴
73+
╭─╴
74+
├─
75+
76+
77+
""".splitlines()
78+
79+
80+
DIGITS3X3 = """\
81+
82+
83+
84+
╭─╮
85+
│ │
86+
╰─╯
87+
╶╮
88+
89+
╶┴╴
90+
╶─╮
91+
┌─┘
92+
╰─╴
93+
╶─╮
94+
─┤
95+
╶─╯
96+
╷ ╷
97+
╰─┤
98+
99+
╭─╴
100+
╰─╮
101+
╶─╯
102+
╭─╴
103+
├─╮
104+
╰─╯
105+
╶─┐
106+
107+
108+
╭─╮
109+
├─┤
110+
╰─╯
111+
╭─╮
112+
╰─┤
113+
╶─╯
114+
115+
╶┼╴
116+
117+
118+
╶─╴
119+
120+
^
121+
122+
123+
124+
×
125+
126+
127+
:
128+
129+
╭─╮
130+
├─┤
131+
╵ ╵
132+
┌─╮
133+
├─┤
134+
└─╯
135+
╭─╮
136+
137+
╰─╯
138+
┌─╮
139+
│ │
140+
└─╯
141+
╭─╴
142+
├─
143+
╰─╴
144+
╭─╴
145+
├─
146+
147+
58148
""".splitlines()
59149

60150

@@ -91,6 +181,11 @@ def render(self, style: Style) -> RenderResult:
91181
row2 = digit_pieces[1].append
92182
row3 = digit_pieces[2].append
93183

184+
if style.bold:
185+
digits = DIGITS3X3_BOLD
186+
else:
187+
digits = DIGITS3X3
188+
94189
for character in self._text:
95190
try:
96191
position = DIGITS.index(character) * 3
@@ -99,9 +194,9 @@ def render(self, style: Style) -> RenderResult:
99194
row2(" ")
100195
row3(character)
101196
else:
102-
row1(DIGITS3X3[position].ljust(3))
103-
row2(DIGITS3X3[position + 1].ljust(3))
104-
row3(DIGITS3X3[position + 2].ljust(3))
197+
row1(digits[position].ljust(3))
198+
row2(digits[position + 1].ljust(3))
199+
row3(digits[position + 2].ljust(3))
105200

106201
new_line = Segment.line()
107202
for line in digit_pieces:

src/textual/widgets/_digits.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ class Digits(Widget):
1818
Digits {
1919
width: 1fr;
2020
height: auto;
21-
text-align: left;
22-
text-style: bold;
21+
text-align: left;
2322
box-sizing: border-box;
2423
}
2524
"""

tests/snapshot_tests/__snapshots__/test_snapshots/test_digits.svg

Lines changed: 55 additions & 55 deletions
Loading

tests/snapshot_tests/__snapshots__/test_snapshots/test_example_calculator.svg

Lines changed: 68 additions & 68 deletions
Loading

tests/snapshot_tests/__snapshots__/test_snapshots/test_example_merlin.svg

Lines changed: 64 additions & 64 deletions
Loading

tests/snapshot_tests/__snapshots__/test_snapshots/test_recompose.svg

Lines changed: 57 additions & 58 deletions
Loading

tests/snapshot_tests/snapshot_apps/digits.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,25 @@
44

55
class DigitApp(App):
66
CSS = """
7-
#digits1 {
7+
.left {
88
text-align: left;
99
}
10-
#digits2 {
10+
.center {
1111
text-align:center;
1212
}
13-
#digits3 {
13+
.right {
1414
text-align:right;
1515
}
16+
.bold {
17+
text-style: bold;
18+
}
1619
"""
1720

1821
def compose(self) -> ComposeResult:
19-
yield Digits("3.1427", id="digits1")
20-
yield Digits(" 0123456789+-.,", id="digits2")
21-
yield Digits("3x10^4", id="digits3")
22+
yield Digits("3.1427", classes="left")
23+
yield Digits(" 0123456789+-.,ABCDEF", classes="center")
24+
yield Digits(" 0123456789+-.,ABCDEF", classes="center bold")
25+
yield Digits("3x10^4", classes="right")
2226

2327

2428
if __name__ == "__main__":

0 commit comments

Comments
 (0)