xnano.buffers
xnano.buffers
¶
xnano.buffers
Buffers: grids of cells that hold text and styles.
A Buffer is what a canvas draws; each Cell holds
one symbol with its colors.
Attributes:
-
Buffer–A grid of cells with a position and a size, which a canvas draws.
-
Cell–One symbol with its style, copied out of or written into a buffer.
Buffer
module-attribute
¶
Buffer = _CoreBuffer
A grid of cells with a position and a size, which a canvas draws.
Write one onto a canvas to place prepared content, or build one cell by cell with
Cell.
import xnano
from xnano.buffers import Buffer
card = Buffer('hello', width=8, height=2)
with xnano.new(width=12, height=3) as canvas:
canvas.screen.write(card, x=2, y=1)
assert canvas.screen.render().splitlines()[1] == ' hello'
Referenced by:
Returned by:
Cell
module-attribute
¶
Cell = _CoreCell
One symbol with its style, copied out of or written into a buffer.
Use it to read or change a single cell of a Buffer.
import xnano
from xnano.buffers import Buffer, Cell
buffer = Buffer(width=3, height=1)
buffer[1, 0] = Cell('x', foreground='red')
with xnano.new(width=3, height=1) as canvas:
canvas.screen.write(buffer)
assert buffer[1, 0].symbol == 'x'
assert canvas.screen.render() == ' x'
Referenced by:
__getattr__
¶
Import an object from xnano_core the first time it is read, then keep it.
Source code in xnano/buffers.py
def __getattr__(name: str) -> object:
"""Import an object from ``xnano_core`` the first time it is read, then keep it."""
core_name = _CORE_NAMES.get(name)
if core_name is None:
raise AttributeError(
f'xnano.buffers has no name {name!r}. Its names are {", ".join(__all__)}.'
)
import xnano_core
value = getattr(xnano_core, core_name)
globals()[name] = value
return value