class TermBuf::Field

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.cr

Constant Summary

MARKERS = {'<', '>'}

Shown where text has run off the left or right of a fixed field.

Constructors

Instance Method Summary

Constructor Detail

def self.new(bounds : Rect, editor : Editor = Editor.new, border : Border | Nil = nil, prompt : Prompt | Nil = nil, growth : Growth = Growth::Fixed, max_rows : Int32 = 8, style : Style = Style::DEFAULT, selection_style : Style = Style::DEFAULT.reverse, placeholder : String | Nil = nil, placeholder_style : Style = Style::DEFAULT.faint) #

[View source]

Instance Method Detail

def border : Border | Nil #

Drawn around the panel, or nil for none.


[View source]
def border=(border : Border | Nil) #

Drawn around the panel, or nil for none.


[View source]
def bounds : Rect #

The whole panel, border included.


[View source]
def bounds=(bounds : Rect) #

The whole panel, border included.


[View source]
def buffer : LineBuffer #

The text being edited.


[View source]
def cursor_cell : Tuple(Int32, Int32) #

Which row the cursor is on and how many cells into it.


[View source]
def cursor_position : Tuple(Int32, Int32) #

Where the terminal's own cursor belongs, in screen coordinates.


[View source]
def desired_height : Int32 #

Rows the whole panel would like, border included, capped at #max_rows.


[View source]
def draw(screen : Drawing) : Nil #

Draws the panel, its border, its prompt, and as much of the text as there is room for.


[View source]
def editor : Editor #

Keys, bound to what they do to the text.


[View source]
def growth : Growth #

What happens when the text outgrows one row.


[View source]
def growth=(growth : Growth) #

What happens when the text outgrows one row.


[View source]
def handle(key : Key) : Editor::Outcome #

Does whatever key is bound to. The view catches up at the next draw.


[View source]
def inner : Rect #

The area inside the border.


[View source]
def max_rows : Int32 #

Rows the panel may grow to, border included.


[View source]
def max_rows=(max_rows : Int32) #

Rows the panel may grow to, border included.


[View source]
def offset : Int32 #

Where the view has scrolled to: cells for a fixed field, rows for one that grows.


[View source]
def paste(text : String) : Editor::Outcome #

Pasted text goes in as text. A field with no room for a line break flattens them rather than dropping the rest.


[View source]
def placeholder : String | Nil #

Shown instead of the text when there is none.


[View source]
def placeholder=(placeholder : String | Nil) #

Shown instead of the text when there is none.


[View source]
def placeholder_style : Style #

What the placeholder is drawn in.


[View source]
def placeholder_style=(placeholder_style : Style) #

What the placeholder is drawn in.


[View source]
def prompt : Prompt | Nil #

Drawn in front of the text, or nil for none.


[View source]
def prompt=(prompt : Prompt | Nil) #

Drawn in front of the text, or nil for none.


[View source]
def prompt_width : Int32 #

Cells the prompt takes on the first row.


[View source]
def reflow : Nil #

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.


[View source]
def rows : Array(Range(Int32, Int32)) #

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.


[View source]
def run(terminal : Terminal) : String | Nil #

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.


[View source]
def selection_style : Style #

What selected text is drawn in.


[View source]
def selection_style=(selection_style : Style) #

What selected text is drawn in.


[View source]
def style : Style #

What the panel and its text are drawn in.


[View source]
def style=(style : Style) #

What the panel and its text are drawn in.


[View source]
def text : String #

The line as it stands.


[View source]
def text=(value : String) : String #

Replaces the line, ending any history walk.


[View source]
def text_rows : Int32 #

Rows of text the field would like, before the border and any listing.


[View source]
def text_width : Int32 #

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.


[View source]