From 2c3f1aa31e5c6c73d1f2f5c94089658d247d3a01 Mon Sep 17 00:00:00 2001 From: salt-die Date: Sun, 21 Jul 2024 20:37:22 -0500 Subject: [PATCH] `text_tools` and `texture_tools` moved into root directory. --- examples/advanced/exploding_logo_redux.py | 2 +- examples/advanced/infinite_tictactoe.py | 2 +- examples/advanced/isotiles.py | 2 +- examples/advanced/raycasting.py | 4 +- examples/advanced/rigid_body_physics.py | 3 +- examples/advanced/sliding_puzzle.py | 2 +- examples/advanced/tetris/tetris/tetris.py | 2 +- examples/basic/io_events.py | 2 +- src/batgrl/{gadgets => }/_batgrl_markdown.py | 3 +- src/batgrl/{gadgets => }/_char_widths.py | 0 src/batgrl/figfont.py | 3 +- src/batgrl/gadgets/_root.py | 2 +- src/batgrl/gadgets/bar_chart.py | 2 +- src/batgrl/gadgets/box_image.py | 2 +- src/batgrl/gadgets/braille_image.py | 2 +- src/batgrl/gadgets/braille_video.py | 2 +- src/batgrl/gadgets/file_chooser.py | 2 +- src/batgrl/gadgets/gadget.py | 2 +- src/batgrl/gadgets/graphic_field.py | 2 +- src/batgrl/gadgets/graphics.py | 2 +- src/batgrl/gadgets/image.py | 2 +- src/batgrl/gadgets/line_plot.py | 2 +- src/batgrl/gadgets/pane.py | 2 +- src/batgrl/gadgets/progress_bar.py | 2 +- src/batgrl/gadgets/raycaster.py | 2 +- src/batgrl/gadgets/scroll_view.py | 2 +- src/batgrl/gadgets/sparkline.py | 2 +- src/batgrl/gadgets/text.py | 24 ++++++------ src/batgrl/gadgets/text_effects/_particle.py | 2 +- src/batgrl/gadgets/text_field.py | 4 +- src/batgrl/gadgets/text_pad.py | 2 +- src/batgrl/gadgets/textbox.py | 2 +- src/batgrl/rendering.py | 2 +- src/batgrl/{gadgets => }/text_tools.py | 39 +++++++++----------- src/batgrl/{gadgets => }/texture_tools.py | 3 +- 35 files changed, 67 insertions(+), 68 deletions(-) rename src/batgrl/{gadgets => }/_batgrl_markdown.py (99%) rename src/batgrl/{gadgets => }/_char_widths.py (100%) rename src/batgrl/{gadgets => }/text_tools.py (96%) rename src/batgrl/{gadgets => }/texture_tools.py (98%) diff --git a/examples/advanced/exploding_logo_redux.py b/examples/advanced/exploding_logo_redux.py index cd566dc2..7f0513f7 100644 --- a/examples/advanced/exploding_logo_redux.py +++ b/examples/advanced/exploding_logo_redux.py @@ -17,7 +17,7 @@ particle_data_from_texture, ) from batgrl.gadgets.image import Image, Size -from batgrl.gadgets.texture_tools import read_texture, resize_texture +from batgrl.texture_tools import read_texture, resize_texture LOGO_SIZE = Size(36, 36) POWER = 2 diff --git a/examples/advanced/infinite_tictactoe.py b/examples/advanced/infinite_tictactoe.py index 9375ce64..87d19bc5 100644 --- a/examples/advanced/infinite_tictactoe.py +++ b/examples/advanced/infinite_tictactoe.py @@ -7,7 +7,7 @@ from batgrl.gadgets.gadget import Gadget from batgrl.gadgets.grid_layout import GridLayout from batgrl.gadgets.text import Text -from batgrl.gadgets.text_tools import add_text +from batgrl.text_tools import add_text BLUES = [Color.from_hex(hexcode) for hexcode in ["2412e8", "170b93", "09053f"]] REDS = [Color.from_hex(hexcode) for hexcode in ["ea1212", "930b0b", "3d0404"]] diff --git a/examples/advanced/isotiles.py b/examples/advanced/isotiles.py index 937c5a51..f9359cb8 100644 --- a/examples/advanced/isotiles.py +++ b/examples/advanced/isotiles.py @@ -7,8 +7,8 @@ from batgrl.colors import AWHITE from batgrl.gadgets.graphics import Graphics, Point, Size from batgrl.gadgets.scroll_view import ScrollView -from batgrl.gadgets.texture_tools import composite, read_texture from batgrl.terminal.events import MouseEvent +from batgrl.texture_tools import composite, read_texture ASSETS = Path(__file__).parent.parent / "assets" TILES_PATH = ASSETS / "isometric_demo.png" diff --git a/examples/advanced/raycasting.py b/examples/advanced/raycasting.py index 7386e9fb..e62e31bd 100644 --- a/examples/advanced/raycasting.py +++ b/examples/advanced/raycasting.py @@ -11,10 +11,10 @@ from batgrl.colors import GREEN from batgrl.gadgets.raycaster import Raycaster, RaycasterCamera, RgbaTexture, Sprite from batgrl.gadgets.text_raycaster import TextRaycaster -from batgrl.gadgets.text_tools import cell -from batgrl.gadgets.texture_tools import read_texture from batgrl.gadgets.video import Video from batgrl.geometry import lerp +from batgrl.text_tools import cell +from batgrl.texture_tools import read_texture def load_assets(): diff --git a/examples/advanced/rigid_body_physics.py b/examples/advanced/rigid_body_physics.py index 07d1deb9..a63a2f30 100644 --- a/examples/advanced/rigid_body_physics.py +++ b/examples/advanced/rigid_body_physics.py @@ -3,6 +3,7 @@ Requires `pymunk` """ + import asyncio from math import ceil, degrees from pathlib import Path @@ -15,7 +16,7 @@ from batgrl.colors import AWHITE, AColor from batgrl.gadgets.graphics import Graphics from batgrl.gadgets.image import Image -from batgrl.gadgets.texture_tools import composite, read_texture, resize_texture +from batgrl.texture_tools import composite, read_texture, resize_texture from pymunk.vec2d import Vec2d BOX_SIZE = W, H = Vec2d(9, 9) diff --git a/examples/advanced/sliding_puzzle.py b/examples/advanced/sliding_puzzle.py index e76c9fd4..f595cd18 100644 --- a/examples/advanced/sliding_puzzle.py +++ b/examples/advanced/sliding_puzzle.py @@ -4,7 +4,7 @@ from batgrl.app import run_gadget_as_app from batgrl.colors import ABLACK, AWHITE from batgrl.gadgets.graphics import Graphics -from batgrl.gadgets.texture_tools import read_texture, resize_texture +from batgrl.texture_tools import read_texture, resize_texture ASSETS = Path(__file__).parent.parent / "assets" PATH_TO_LOGO = ASSETS / "python_discord_logo.png" diff --git a/examples/advanced/tetris/tetris/tetris.py b/examples/advanced/tetris/tetris/tetris.py index 1d8353e2..12a9539f 100644 --- a/examples/advanced/tetris/tetris/tetris.py +++ b/examples/advanced/tetris/tetris/tetris.py @@ -9,7 +9,7 @@ from batgrl.gadgets.graphics import Graphics from batgrl.gadgets.image import Image from batgrl.gadgets.text import Text -from batgrl.gadgets.texture_tools import composite +from batgrl.texture_tools import composite from .matrix import MatrixGadget from .modal_screen import ModalScreen diff --git a/examples/basic/io_events.py b/examples/basic/io_events.py index df351905..663856c7 100644 --- a/examples/basic/io_events.py +++ b/examples/basic/io_events.py @@ -4,8 +4,8 @@ from batgrl.app import App from batgrl.gadgets.text import Text -from batgrl.gadgets.text_tools import add_text from batgrl.terminal.events import FocusEvent, KeyEvent, MouseEvent, PasteEvent +from batgrl.text_tools import add_text class ShowIOEvents(Text): diff --git a/src/batgrl/gadgets/_batgrl_markdown.py b/src/batgrl/_batgrl_markdown.py similarity index 99% rename from src/batgrl/gadgets/_batgrl_markdown.py rename to src/batgrl/_batgrl_markdown.py index 1c2085d3..4df85fe6 100644 --- a/src/batgrl/gadgets/_batgrl_markdown.py +++ b/src/batgrl/_batgrl_markdown.py @@ -13,12 +13,13 @@ This module is adapted from `https://github.com/miyuchina/mistletoe/blob/master/mistletoe/core_tokens.py`. `mistletoe` is licensed under the MIT license. """ + import sys from string import punctuation from typing import Literal from unicodedata import category -from ..geometry import clamp +from .geometry import clamp DELIMITERS = set("*_~^") WHITESPACE = set( diff --git a/src/batgrl/gadgets/_char_widths.py b/src/batgrl/_char_widths.py similarity index 100% rename from src/batgrl/gadgets/_char_widths.py rename to src/batgrl/_char_widths.py diff --git a/src/batgrl/figfont.py b/src/batgrl/figfont.py index 29bbd4f9..acc007dc 100644 --- a/src/batgrl/figfont.py +++ b/src/batgrl/figfont.py @@ -18,6 +18,7 @@ - http://www.figlet.org/fontdb.cgi - https://github.com/salt-die/fig-fonts """ + import re import zipfile from dataclasses import dataclass, field, fields @@ -28,7 +29,7 @@ import numpy as np from numpy.typing import NDArray -from .gadgets.text_tools import char_width, str_width +from .text_tools import char_width, str_width __all__ = ["FullLayout", "FIGFont"] diff --git a/src/batgrl/gadgets/_root.py b/src/batgrl/gadgets/_root.py index d40ffaa1..ff2b3a4a 100644 --- a/src/batgrl/gadgets/_root.py +++ b/src/batgrl/gadgets/_root.py @@ -9,8 +9,8 @@ from ..app import App from ..colors import Color +from ..text_tools import cell from .gadget import Gadget, Point, Region, Size -from .text_tools import cell class _Root(Gadget): diff --git a/src/batgrl/gadgets/bar_chart.py b/src/batgrl/gadgets/bar_chart.py index b14a626f..5680446e 100644 --- a/src/batgrl/gadgets/bar_chart.py +++ b/src/batgrl/gadgets/bar_chart.py @@ -3,6 +3,7 @@ from numbers import Real from ..colors import DEFAULT_PRIMARY_BG, DEFAULT_PRIMARY_FG, Color, rainbow_gradient +from ..text_tools import add_text, smooth_vertical_bar, str_width from .gadget import ( Gadget, Point, @@ -16,7 +17,6 @@ from .pane import Pane from .scroll_view import ScrollView from .text import Text, cell -from .text_tools import add_text, smooth_vertical_bar, str_width __all__ = ["BarChart", "Point", "Size"] diff --git a/src/batgrl/gadgets/box_image.py b/src/batgrl/gadgets/box_image.py index 9ebe3f88..21208c5c 100644 --- a/src/batgrl/gadgets/box_image.py +++ b/src/batgrl/gadgets/box_image.py @@ -5,6 +5,7 @@ import cv2 import numpy as np +from ..text_tools import binary_to_box from .gadget import ( Gadget, Point, @@ -15,7 +16,6 @@ SizeHintDict, ) from .text import Text -from .text_tools import binary_to_box __all__ = ["BoxImage", "Point", "Size"] diff --git a/src/batgrl/gadgets/braille_image.py b/src/batgrl/gadgets/braille_image.py index 00d5b596..95854af8 100644 --- a/src/batgrl/gadgets/braille_image.py +++ b/src/batgrl/gadgets/braille_image.py @@ -5,6 +5,7 @@ import cv2 import numpy as np +from ..text_tools import binary_to_braille from .gadget import ( Gadget, Point, @@ -15,7 +16,6 @@ SizeHintDict, ) from .text import Text -from .text_tools import binary_to_braille __all__ = ["BrailleImage", "Point", "Size"] diff --git a/src/batgrl/gadgets/braille_video.py b/src/batgrl/gadgets/braille_video.py index 9aeaa4d0..d7b15875 100644 --- a/src/batgrl/gadgets/braille_video.py +++ b/src/batgrl/gadgets/braille_video.py @@ -12,6 +12,7 @@ from ..colors import BLACK, WHITE, Color from ..geometry import lerp +from ..text_tools import binary_to_braille from .gadget import ( Gadget, Point, @@ -22,7 +23,6 @@ SizeHintDict, ) from .text import Text -from .text_tools import binary_to_braille __all__ = ["BrailleVideo", "Point", "Size"] diff --git a/src/batgrl/gadgets/file_chooser.py b/src/batgrl/gadgets/file_chooser.py index 8e65994b..1acefd0d 100644 --- a/src/batgrl/gadgets/file_chooser.py +++ b/src/batgrl/gadgets/file_chooser.py @@ -4,6 +4,7 @@ from collections.abc import Callable from pathlib import Path +from ..text_tools import str_width from .gadget import ( Gadget, Point, @@ -14,7 +15,6 @@ SizeHintDict, ) from .scroll_view import ScrollView -from .text_tools import str_width from .tree_view import TreeView, TreeViewNode __all__ = ["FileChooser", "Point", "Size"] diff --git a/src/batgrl/gadgets/gadget.py b/src/batgrl/gadgets/gadget.py index d2c42ce3..a4a0e45c 100644 --- a/src/batgrl/gadgets/gadget.py +++ b/src/batgrl/gadgets/gadget.py @@ -16,7 +16,7 @@ from ..easings import EASINGS, Easing from ..geometry import Point, Region, Size, clamp, lerp, round_down from ..terminal.events import FocusEvent, KeyEvent, MouseEvent, PasteEvent -from .text_tools import Cell, cell +from ..text_tools import Cell, cell __all__ = [ "Anchor", diff --git a/src/batgrl/gadgets/graphic_field.py b/src/batgrl/gadgets/graphic_field.py index 85ac97fd..a3909474 100644 --- a/src/batgrl/gadgets/graphic_field.py +++ b/src/batgrl/gadgets/graphic_field.py @@ -10,6 +10,7 @@ from numpy.lib.recfunctions import structured_to_unstructured from numpy.typing import NDArray +from ..texture_tools import _composite from .gadget import ( Cell, Gadget, @@ -22,7 +23,6 @@ bindable, clamp, ) -from .texture_tools import _composite __all__ = ["GraphicParticleField", "particle_data_from_texture", "Point", "Size"] diff --git a/src/batgrl/gadgets/graphics.py b/src/batgrl/gadgets/graphics.py index f35499f8..b553a13d 100644 --- a/src/batgrl/gadgets/graphics.py +++ b/src/batgrl/gadgets/graphics.py @@ -7,6 +7,7 @@ from numpy.typing import NDArray from ..colors import TRANSPARENT, AColor +from ..texture_tools import Interpolation, _composite, resize_texture from .gadget import ( Cell, Gadget, @@ -19,7 +20,6 @@ bindable, clamp, ) -from .texture_tools import Interpolation, _composite, resize_texture __all__ = ["Graphics", "Interpolation", "Point", "Size"] diff --git a/src/batgrl/gadgets/image.py b/src/batgrl/gadgets/image.py index d96ad3ba..c98b4df8 100644 --- a/src/batgrl/gadgets/image.py +++ b/src/batgrl/gadgets/image.py @@ -6,6 +6,7 @@ from numpy.typing import NDArray from ..colors import TRANSPARENT, AColor +from ..texture_tools import read_texture, resize_texture from .graphics import ( Graphics, Interpolation, @@ -16,7 +17,6 @@ SizeHint, SizeHintDict, ) -from .texture_tools import read_texture, resize_texture __all__ = ["Image", "Interpolation", "Point", "Size"] diff --git a/src/batgrl/gadgets/line_plot.py b/src/batgrl/gadgets/line_plot.py index a51cade9..49977388 100644 --- a/src/batgrl/gadgets/line_plot.py +++ b/src/batgrl/gadgets/line_plot.py @@ -10,6 +10,7 @@ from ..colors import DEFAULT_PRIMARY_BG, DEFAULT_PRIMARY_FG, Color, rainbow_gradient from ..terminal.events import MouseEvent +from ..text_tools import binary_to_box, binary_to_braille, str_width from .behaviors.movable import Movable from .gadget import ( Gadget, @@ -24,7 +25,6 @@ from .pane import Pane from .scroll_view import ScrollView from .text import Text, add_text, cell -from .text_tools import binary_to_box, binary_to_braille, str_width __all__ = ["LinePlot", "Point", "Size"] diff --git a/src/batgrl/gadgets/pane.py b/src/batgrl/gadgets/pane.py index cc185bb2..c1715bcf 100644 --- a/src/batgrl/gadgets/pane.py +++ b/src/batgrl/gadgets/pane.py @@ -3,6 +3,7 @@ from numpy.typing import NDArray from ..colors import BLACK, Color +from ..texture_tools import _composite from .gadget import ( Cell, Gadget, @@ -15,7 +16,6 @@ bindable, clamp, ) -from .texture_tools import _composite __all__ = ["Pane", "Point", "Size"] diff --git a/src/batgrl/gadgets/progress_bar.py b/src/batgrl/gadgets/progress_bar.py index 40f07ca5..daec77a6 100644 --- a/src/batgrl/gadgets/progress_bar.py +++ b/src/batgrl/gadgets/progress_bar.py @@ -3,6 +3,7 @@ import asyncio from itertools import chain, cycle +from ..text_tools import smooth_horizontal_bar, smooth_vertical_bar from .behaviors.themable import Themable from .gadget import ( Gadget, @@ -16,7 +17,6 @@ clamp, ) from .text import Text -from .text_tools import smooth_horizontal_bar, smooth_vertical_bar __all__ = ["ProgressBar", "Point", "Size"] diff --git a/src/batgrl/gadgets/raycaster.py b/src/batgrl/gadgets/raycaster.py index 582adfc4..102510e7 100644 --- a/src/batgrl/gadgets/raycaster.py +++ b/src/batgrl/gadgets/raycaster.py @@ -7,6 +7,7 @@ from numpy.typing import NDArray from ..colors import BLACK, TRANSPARENT, AColor, Color +from ..texture_tools import _composite from .graphics import ( Graphics, Interpolation, @@ -18,7 +19,6 @@ SizeHintDict, clamp, ) -from .texture_tools import _composite __all__ = ["Raycaster", "Sprite", "RaycasterCamera", "RgbaTexture", "Point", "Size"] diff --git a/src/batgrl/gadgets/scroll_view.py b/src/batgrl/gadgets/scroll_view.py index 32b0e9aa..b54331b9 100644 --- a/src/batgrl/gadgets/scroll_view.py +++ b/src/batgrl/gadgets/scroll_view.py @@ -2,6 +2,7 @@ from ..colors import Color from ..terminal.events import KeyEvent, MouseButton, MouseEvent +from ..text_tools import smooth_horizontal_bar, smooth_vertical_bar from .behaviors.grabbable import Grabbable from .behaviors.themable import Themable from .gadget import ( @@ -17,7 +18,6 @@ ) from .pane import Pane from .text import Text -from .text_tools import smooth_horizontal_bar, smooth_vertical_bar __all__ = ["ScrollView", "Point", "Size"] diff --git a/src/batgrl/gadgets/sparkline.py b/src/batgrl/gadgets/sparkline.py index 619ee53c..4130c627 100644 --- a/src/batgrl/gadgets/sparkline.py +++ b/src/batgrl/gadgets/sparkline.py @@ -8,6 +8,7 @@ from ..colors import DEFAULT_PRIMARY_BG, DEFAULT_PRIMARY_FG, Color, lerp_colors from ..terminal.events import MouseEvent +from ..text_tools import smooth_vertical_bar from ._cursor import Cursor from .gadget import ( Gadget, @@ -19,7 +20,6 @@ SizeHintDict, ) from .text import Text, add_text -from .text_tools import smooth_vertical_bar __all__ = ["Sparkline", "Point", "Size"] diff --git a/src/batgrl/gadgets/text.py b/src/batgrl/gadgets/text.py index 48ad6b64..98bc241b 100644 --- a/src/batgrl/gadgets/text.py +++ b/src/batgrl/gadgets/text.py @@ -9,6 +9,17 @@ from pygments.style import Style from ..colors import Color, Neptune +from ..text_tools import ( + _parse_batgrl_md, + _text_to_cells, + _write_lines_to_canvas, + add_text, + cell_sans, + char_width, + coerce_cell, + str_width, +) +from ..texture_tools import _composite from .gadget import ( Cell, Gadget, @@ -22,17 +33,6 @@ cell, clamp, ) -from .text_tools import ( - _coerce_cell, - _parse_batgrl_md, - _text_to_cells, - _write_lines_to_canvas, - add_text, - cell_sans, - char_width, - str_width, -) -from .texture_tools import _composite __all__ = [ "Text", @@ -272,7 +272,7 @@ def default_cell(self) -> NDArray[Cell]: @default_cell.setter def default_cell(self, cell_: NDArray[Cell] | str): - self._default_cell = _coerce_cell(cell_, cell()) + self._default_cell = coerce_cell(cell_, cell()) @property def default_fg_color(self) -> Color: diff --git a/src/batgrl/gadgets/text_effects/_particle.py b/src/batgrl/gadgets/text_effects/_particle.py index 2cf8abd7..6776b602 100644 --- a/src/batgrl/gadgets/text_effects/_particle.py +++ b/src/batgrl/gadgets/text_effects/_particle.py @@ -1,8 +1,8 @@ from collections.abc import Iterator from dataclasses import dataclass +from ...text_tools import Cell from ..text_field import Point, TextParticleField -from ..text_tools import Cell @dataclass diff --git a/src/batgrl/gadgets/text_field.py b/src/batgrl/gadgets/text_field.py index ccda317a..b698e588 100644 --- a/src/batgrl/gadgets/text_field.py +++ b/src/batgrl/gadgets/text_field.py @@ -10,6 +10,8 @@ from numpy.typing import NDArray from ..geometry import clamp +from ..text_tools import cell_sans +from ..texture_tools import _composite from .gadget import ( Cell, Gadget, @@ -21,8 +23,6 @@ SizeHintDict, cell, ) -from .text_tools import cell_sans -from .texture_tools import _composite __all__ = ["TextParticleField", "particle_data_from_canvas", "Point", "Size"] diff --git a/src/batgrl/gadgets/text_pad.py b/src/batgrl/gadgets/text_pad.py index 15e6a6a3..86029869 100644 --- a/src/batgrl/gadgets/text_pad.py +++ b/src/batgrl/gadgets/text_pad.py @@ -3,6 +3,7 @@ from dataclasses import astuple from ..terminal.events import KeyEvent, MouseEvent, PasteEvent +from ..text_tools import is_word_char, str_width from ._cursor import Cursor from .behaviors.focusable import Focusable from .behaviors.grabbable import Grabbable @@ -18,7 +19,6 @@ ) from .scroll_view import ScrollView from .text import Text -from .text_tools import is_word_char, str_width __all__ = ["TextPad", "Point", "Size"] diff --git a/src/batgrl/gadgets/textbox.py b/src/batgrl/gadgets/textbox.py index cea7d53b..d2bbcad0 100644 --- a/src/batgrl/gadgets/textbox.py +++ b/src/batgrl/gadgets/textbox.py @@ -6,6 +6,7 @@ from numpy.typing import NDArray from ..terminal.events import KeyEvent, MouseButton, MouseEvent, PasteEvent +from ..text_tools import is_word_char, str_width from ._cursor import Cursor from .behaviors.focusable import Focusable from .behaviors.grabbable import Grabbable @@ -22,7 +23,6 @@ SizeHintDict, ) from .text import Text -from .text_tools import is_word_char, str_width __all__ = ["Textbox", "Point", "Size"] diff --git a/src/batgrl/rendering.py b/src/batgrl/rendering.py index 0a7a377a..b3df8dae 100644 --- a/src/batgrl/rendering.py +++ b/src/batgrl/rendering.py @@ -3,8 +3,8 @@ import numpy as np from .gadgets._root import _Root -from .gadgets.text_tools import char_width from .terminal import Vt100Terminal +from .text_tools import char_width def render_root(root: _Root, terminal: Vt100Terminal) -> None: diff --git a/src/batgrl/gadgets/text_tools.py b/src/batgrl/text_tools.py similarity index 96% rename from src/batgrl/gadgets/text_tools.py rename to src/batgrl/text_tools.py index 123e7541..e9edc6e7 100644 --- a/src/batgrl/gadgets/text_tools.py +++ b/src/batgrl/text_tools.py @@ -7,10 +7,10 @@ import numpy as np from numpy.typing import NDArray -from ..colors import BLACK, WHITE, Color -from ..geometry import Size from ._batgrl_markdown import find_md_tokens from ._char_widths import CHAR_WIDTHS +from .colors import BLACK, WHITE, Color +from .geometry import Size __all__ = [ "Cell", @@ -19,12 +19,24 @@ "binary_to_braille", "cell", "char_width", + "coerce_cell", "is_word_char", "smooth_horizontal_bar", "smooth_vertical_bar", "str_width", ] +VERTICAL_BLOCKS = " ▁▂▃▄▅▆▇█" +HORIZONTAL_BLOCKS = " ▏▎▍▌▋▊▉█" +_BRAILLE_ENUM = np.array([[1, 8], [2, 16], [4, 32], [64, 128]]) +_BOX_ENUM = np.array([[1, 4], [2, 8]]) + +_vectorized_chr = np.vectorize(chr) +"""Vectorized `chr`.""" + +_vectorized_box_map = np.vectorize(" ▘▖▌▝▀▞▛▗▚▄▙▐▜▟█".__getitem__) +"""Vectorized box enum to box char.""" + @lru_cache(maxsize=1024) def char_width(char: str) -> int: @@ -159,13 +171,10 @@ def cell( ) -def _coerce_cell(char: NDArray[Cell] | str, default: NDArray[Cell]) -> NDArray[Cell]: +def coerce_cell(char: NDArray[Cell] | str, default: NDArray[Cell]) -> NDArray[Cell]: """ Try to coerce a string or ``Cell`` scalar into a half-width ``Cell`` scalar. - This is an internal function for background and default character setters in App, - Gadget, Text, and a few other gadgets. - Parameters ---------- char : NDArray[Cell] | str @@ -366,10 +375,6 @@ def add_text( _write_lines_to_canvas(lines, canvas, fg_color, bg_color) -VERTICAL_BLOCKS = " ▁▂▃▄▅▆▇█" -HORIZONTAL_BLOCKS = " ▏▎▍▌▋▊▉█" - - def _smooth_bar( blocks: str, max_length: int, @@ -469,16 +474,6 @@ def smooth_horizontal_bar( return _smooth_bar(HORIZONTAL_BLOCKS, max_width, proportion, offset) -_BRAILLE_ENUM = np.array([[1, 8], [2, 16], [4, 32], [64, 128]]) -_BOX_ENUM = np.array([[1, 4], [2, 8]]) - -vectorized_chr = np.vectorize(chr) -"""Vectorized `chr`.""" - -vectorized_box_map = np.vectorize(" ▘▖▌▝▀▞▛▗▚▄▙▐▜▟█".__getitem__) -"""Vectorized box enum to box char.""" - - def binary_to_braille(array_4x2: NDArray[np.bool_]) -> NDArray[np.dtype(" NDArray[np.dtype(" NDArray[np.dtype("< NDArray[np.dtype("