class
TermBuf::Field
- TermBuf::Field
- Reference
- Object
Overview
A place to type, drawn through the same Drawing API an application uses.
The field owns a rectangle and nothing else: it reports the height it would like and where the terminal's cursor belongs, and the application decides where to put it. That is the line between this and a layout manager, which this shard does not have.
Defined in:
termbuf/widgets/field.crConstant Summary
-
MARKERS =
{'<', '>'} -
Shown where text has run off the left or right of a fixed field.
Constructors
Instance Method Summary
-
#border : Border | Nil
Drawn around the panel, or
nilfor none. -
#border=(border : Border | Nil)
Drawn around the panel, or
nilfor none. -
#bounds : Rect
The whole panel, border included.
-
#bounds=(bounds : Rect)
The whole panel, border included.
-
#buffer : LineBuffer
The text being edited.
-
#cursor_cell : Tuple(Int32, Int32)
Which row the cursor is on and how many cells into it.
-
#cursor_position : Tuple(Int32, Int32)
Where the terminal's own cursor belongs, in screen coordinates.
-
#desired_height : Int32
Rows the whole panel would like, border included, capped at
#max_rows. -
#draw(screen : Drawing) : Nil
Draws the panel, its border, its prompt, and as much of the text as there is room for.
-
#editor : Editor
Keys, bound to what they do to the text.
-
#growth : Growth
What happens when the text outgrows one row.
-
#growth=(growth : Growth)
What happens when the text outgrows one row.
-
#handle(key : Key) : Editor::Outcome
Does whatever key is bound to.
-
#inner : Rect
The area inside the border.
-
#max_rows : Int32
Rows the panel may grow to, border included.
-
#max_rows=(max_rows : Int32)
Rows the panel may grow to, border included.
-
#offset : Int32
Where the view has scrolled to: cells for a fixed field, rows for one that grows.
-
#paste(text : String) : Editor::Outcome
Pasted text goes in as text.
-
#placeholder : String | Nil
Shown instead of the text when there is none.
-
#placeholder=(placeholder : String | Nil)
Shown instead of the text when there is none.
-
#placeholder_style : Style
What the placeholder is drawn in.
-
#placeholder_style=(placeholder_style : Style)
What the placeholder is drawn in.
-
#prompt : Prompt | Nil
Drawn in front of the text, or
nilfor none. -
#prompt=(prompt : Prompt | Nil)
Drawn in front of the text, or
nilfor none. -
#prompt_width : Int32
Cells the prompt takes on the first row.
-
#reflow : Nil
Keeps the cursor in view, scrolling by the least that does it.
-
#rows : Array(Range(Int32, Int32))
Where each row of text starts and ends, in cluster indices.
-
#run(terminal : Terminal) : String | Nil
Owns the event loop until the line is accepted or abandoned, and hands back what was entered or
nil. -
#selection_style : Style
What selected text is drawn in.
-
#selection_style=(selection_style : Style)
What selected text is drawn in.
-
#style : Style
What the panel and its text are drawn in.
-
#style=(style : Style)
What the panel and its text are drawn in.
-
#text : String
The line as it stands.
-
#text=(value : String) : String
Replaces the line, ending any history walk.
-
#text_rows : Int32
Rows of text the field would like, before the border and any listing.
-
#text_width : Int32
Cells available for text, which the prompt eats into.
Constructor Detail
Instance Method Detail
Where the terminal's own cursor belongs, in screen coordinates.
Draws the panel, its border, its prompt, and as much of the text as there is room for.
Does whatever key is bound to. The view catches up at the next draw.
Where the view has scrolled to: cells for a fixed field, rows for one that grows.
Pasted text goes in as text. A field with no room for a line break flattens them rather than dropping the rest.
Keeps the cursor in view, scrolling by the least that does it.
Recomputed at every draw rather than at every keystroke, because how much is in view depends on the bounds and the bounds are the application's to change. Doing it on a keystroke measures against the panel as it was before it grew.
Where each row of text starts and ends, in cluster indices.
A fixed field is one row however long the text is. A growing one wraps at the right edge and at every line break, and a cluster the terminal draws double never straddles the edge: it moves down whole.
Owns the event loop until the line is accepted or abandoned, and hands
back what was entered or nil.
For the case where a prompt is the only thing on screen. An application
with a loop of its own drives #handle and #draw from that instead.
The field is placed at the bottom of the screen and follows a resize.
Pasted text goes in as text, and a paste worth noticing draws a
PasteNotice over the top.
Cells available for text, which the prompt eats into.
The wider of the prompt and its continuation, so that a row is laid out to fit under either and nothing overflows the one that is longer.