xnano.cursor
xnano.cursor
¶
xnano.cursor
A canvas's cursor: where it is, how it looks, and how to move it.
Classes:
-
Cursor–The one cursor a canvas has.
Cursor
¶
Bases: _SealedAttributes
The one cursor a canvas has.
Get it from Canvas.cursor or from context.cursor
inside a hook. A canvas draws no cursor until it is given a position, which a text field
does to show where typing goes. Any thread may change it, a change is drawn on the next
frame even when no cell changed, and a canvas on the screen gives the user's own cursor
back when it closes. Opening a canvas on the screen keeps its cursor as it was.
Moving is relative to where the cursor is: up,
down, left and
right move it by a count of cells, and
move moves it along both axes at once. The cursor stays
inside the canvas, so moving past an edge stops at the edge. A cursor with no position
moves from the top-left cell. Each of these returns the cursor, so they chain.
Attributes:
-
position(Point | None) –The cell the cursor is at as a
Point, orNonewhen it has none. Assign aPoint, an(x, y)pair orNone. -
shape(CursorShape | None) –'block','bar'or'underline';Nonekeeps the user's own shape. -
is_blinking(bool) –Whether the cursor blinks. Setting it without a shape uses a block.
-
is_visible(bool) –Whether the cursor is shown when it has a position.
Raises:
-
TypeError–is_blinkingoris_visibleis assigned a value that is notTrueorFalse.
Examples:
import xnano
from xnano_core import Point
with xnano.new(width=10, height=3) as canvas:
canvas.cursor.shape = 'bar'
canvas.cursor.home().right(4).down()
assert canvas.cursor.position == Point(4, 1)
Create the canvas's cursor. Use canvas.cursor instead of calling this.
Parameters:
Methods:
-
move–Move the cursor by a number of cells along each axis.
-
up–Move the cursor up by
countrows, stopping at the top. -
down–Move the cursor down by
countrows, stopping at the bottom. -
left–Move the cursor left by
countcolumns, stopping at the left edge. -
right–Move the cursor right by
countcolumns, stopping at the right edge. -
home–Put the cursor in the top-left cell.
-
show–Make the cursor visible, in the top-left cell when it has no position yet.
-
hide–Hide the cursor. Its position is kept, so
showbrings it back. -
follow–Keep the cursor at a place inside a placement, region or buffer, wherever it goes.
-
unfollow–Stop following a placement or buffer, leaving the cursor where it is.
-
__setattr__–Set an attribute, or raise
AttributeErrorfor an unknown public name.
Source code in xnano/cursor.py
position
property
writable
¶
position: Point | None
The cell the cursor is at, or None when it has none.
shape
property
writable
¶
shape: CursorShape | None
'block', 'bar' or 'underline'; None keeps the user's own shape.
is_blinking
property
writable
¶
is_blinking: bool
Whether the cursor blinks. Setting it without a shape uses a block.
move
¶
Move the cursor by a number of cells along each axis.
Parameters:
-
x(int, default:0) –Columns to move right; a negative number moves left.
-
y(int, default:0) –Rows to move down; a negative number moves up.
Returns:
-
Cursor–The cursor, so calls can chain.
Raises:
-
TypeError–An amount is not a whole number.
-
ValueError–An amount is outside the range of a cell number.
Examples:
import xnano
from xnano_core import Point
with xnano.new(width=10, height=3) as canvas:
canvas.cursor.position = (2, 1)
canvas.cursor.move(x=3, y=-1)
assert canvas.cursor.position == Point(5, 0)
canvas.cursor.move(x=-99)
assert canvas.cursor.position == Point(0, 0)
Source code in xnano/cursor.py
up
¶
Move the cursor up by count rows, stopping at the top.
Parameters:
-
count(int, default:1) –How many rows to move.
Raises:
-
TypeError–countis not a whole number. -
ValueError–countis negative.
Source code in xnano/cursor.py
down
¶
Move the cursor down by count rows, stopping at the bottom.
Parameters:
-
count(int, default:1) –How many rows to move.
Raises:
-
TypeError–countis not a whole number. -
ValueError–countis negative.
Source code in xnano/cursor.py
left
¶
Move the cursor left by count columns, stopping at the left edge.
Parameters:
-
count(int, default:1) –How many columns to move.
Raises:
-
TypeError–countis not a whole number. -
ValueError–countis negative.
Source code in xnano/cursor.py
right
¶
Move the cursor right by count columns, stopping at the right edge.
Parameters:
-
count(int, default:1) –How many columns to move.
Raises:
-
TypeError–countis not a whole number. -
ValueError–countis negative.
Source code in xnano/cursor.py
show
¶
show() -> Cursor
Make the cursor visible, in the top-left cell when it has no position yet.
Examples:
import xnano
from xnano_core import Point
with xnano.new(width=10, height=3) as canvas:
canvas.cursor.show()
assert canvas.cursor.is_visible
assert canvas.cursor.position == Point(0, 0)
Source code in xnano/cursor.py
follow
¶
Keep the cursor at a place inside a placement, region or buffer, wherever it goes.
The cursor hides while the target, or anything above it, is hidden, and it loses its
position when the target is removed. Assigning position or calling
move stops the following.
Parameters:
-
target(Placement[object, object] | Region | Buffer) – -
x(int, default:0) –The column inside the target.
-
y(int, default:0) –The row inside the target.
Raises:
-
TerminalClosedError–The target is a placement, or a region of one, that was already removed, or its canvas is closed.
-
TypeError–The target is not a placement, a region or a buffer, or
xoryis not a whole number. -
ValueError–xoryis outside the range of a cell number.
Examples:
import xnano
from xnano_core import Point
with xnano.new(width=20, height=3) as canvas:
field = canvas.write('name', x=5, y=1)
canvas.cursor.follow(field, x=4)
field.x = 8
assert canvas.cursor.position == Point(12, 1)
Source code in xnano/cursor.py
unfollow
¶
unfollow() -> Cursor
Stop following a placement or buffer, leaving the cursor where it is.
Source code in xnano/cursor.py
__setattr__
¶
Set an attribute, or raise AttributeError for an unknown public name.