Skip to content

Commit

Permalink
Merge pull request #5094 from Textualize/digits-hex
Browse files Browse the repository at this point in the history
Added hex chars to digits
  • Loading branch information
willmcgugan authored Oct 5, 2024
2 parents 063cfc7 + 54d7dd6 commit 445ed5d
Show file tree
Hide file tree
Showing 9 changed files with 386 additions and 258 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

### Added

- Added support for A-F to Digits widget https://github.com/Textualize/textual/pull/5094

### Changed

- Digits are now thin by default, style with text-style: bold to get bold digits https://github.com/Textualize/textual/pull/5094

## [0.82.0] - 2024-10-03

### Fixed
Expand Down
21 changes: 21 additions & 0 deletions docs/blog/images/compositor/cuts.excalidraw.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
105 changes: 100 additions & 5 deletions src/textual/renderables/digits.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from rich.segment import Segment
from rich.style import Style, StyleType

DIGITS = " 0123456789+-^x:"
DIGITS3X3 = """\
DIGITS = " 0123456789+-^x:ABCDEF"
DIGITS3X3_BOLD = """\
Expand Down Expand Up @@ -55,6 +55,96 @@
:
╭─╮
├─┤
╵ ╵
┌─╮
├─┤
└─╯
╭─╮
╰─╯
┌─╮
│ │
└─╯
╭─╴
├─
╰─╴
╭─╴
├─
""".splitlines()


DIGITS3X3 = """\
╭─╮
│ │
╰─╯
╶╮
╶┴╴
╶─╮
┌─┘
╰─╴
╶─╮
─┤
╶─╯
╷ ╷
╰─┤
╭─╴
╰─╮
╶─╯
╭─╴
├─╮
╰─╯
╶─┐
╭─╮
├─┤
╰─╯
╭─╮
╰─┤
╶─╯
╶┼╴
╶─╴
^
×
:
╭─╮
├─┤
╵ ╵
┌─╮
├─┤
└─╯
╭─╮
╰─╯
┌─╮
│ │
└─╯
╭─╴
├─
╰─╴
╭─╴
├─
""".splitlines()


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

if style.bold:
digits = DIGITS3X3_BOLD
else:
digits = DIGITS3X3

for character in self._text:
try:
position = DIGITS.index(character) * 3
Expand All @@ -99,9 +194,9 @@ def render(self, style: Style) -> RenderResult:
row2(" ")
row3(character)
else:
row1(DIGITS3X3[position].ljust(3))
row2(DIGITS3X3[position + 1].ljust(3))
row3(DIGITS3X3[position + 2].ljust(3))
row1(digits[position].ljust(3))
row2(digits[position + 1].ljust(3))
row3(digits[position + 2].ljust(3))

new_line = Segment.line()
for line in digit_pieces:
Expand Down
3 changes: 1 addition & 2 deletions src/textual/widgets/_digits.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ class Digits(Widget):
Digits {
width: 1fr;
height: auto;
text-align: left;
text-style: bold;
text-align: left;
box-sizing: border-box;
}
"""
Expand Down
110 changes: 55 additions & 55 deletions tests/snapshot_tests/__snapshots__/test_snapshots/test_digits.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
115 changes: 57 additions & 58 deletions tests/snapshot_tests/__snapshots__/test_snapshots/test_recompose.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 10 additions & 6 deletions tests/snapshot_tests/snapshot_apps/digits.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@

class DigitApp(App):
CSS = """
#digits1 {
.left {
text-align: left;
}
#digits2 {
.center {
text-align:center;
}
#digits3 {
.right {
text-align:right;
}
.bold {
text-style: bold;
}
"""

def compose(self) -> ComposeResult:
yield Digits("3.1427", id="digits1")
yield Digits(" 0123456789+-.,", id="digits2")
yield Digits("3x10^4", id="digits3")
yield Digits("3.1427", classes="left")
yield Digits(" 0123456789+-.,ABCDEF", classes="center")
yield Digits(" 0123456789+-.,ABCDEF", classes="center bold")
yield Digits("3x10^4", classes="right")


if __name__ == "__main__":
Expand Down

0 comments on commit 445ed5d

Please sign in to comment.