loom & weft
Made for Swift.

Unreleased APIs from PR #2. Not in 0.2.1. Stable 0.2.1 reference.

LOOM Unreleased (PR #2) / WIDGETS

TextInput

The widget holds an editor snapshot; your app owns edits and focus. height, contentArea, rendering, and cursor use shared geometry. Set frame.cursor from cursor(in:) only for the focused input. Content scrolls to keep the editor cursor visible. ghostText is presentation-only and is shown after the cursor only when the cursor is at the unselected draft’s end; with an empty draft it replaces the placeholder.

Standard inherited Swift protocol operations such as synthesized equality and OptionSet set operations are not repeated. The public declarations below are extracted from the exact source revision listed in the coverage manifest.

Example

var editor = LineEditor()
editor.insert("Hello")
let input = TextInput(editor, placeholder: "Message", maximumRows: 3)
var frame = Frame(width: 60, height: input.height(width: 60))
frame.render(input, in: frame.area)
frame.cursor = input.cursor(in: frame.area)
Members on this page

Feature guides and release status

TextInput

Structure
struct TextInput

Conforms to: Widget.

A view of a line editor, with configurable borders, wrapping, and a visible cursor.

The application owns and changes the editor. Create a new widget from that state when drawing; height, text painting, and cursor placement use the same content geometry.

Source · TextInput.swift:7

editor

Instance Property
let editor: LineEditor

The editor snapshot from which this widget is drawn.

Source · TextInput.swift:8

placeholder

Instance Property
var placeholder: String

Text displayed when the draft is empty and no ghost text is supplied.

Source · TextInput.swift:9

prompt

Instance Property
var prompt: String

Marker displayed before editable text.

Source · TextInput.swift:10

maximumRows

Instance Property
var maximumRows: Int

Maximum visible editable rows, excluding borders.

Source · TextInput.swift:11

minimumRows

Instance Property
var minimumRows: Int

Preferred minimum editable rows.

Source · TextInput.swift:12

borderStyle

Instance Property
var borderStyle: Style

Appearance of the outline, independent of the editable text.

Source · TextInput.swift:15

borderType

Instance Property
var borderType: BorderType

Line/corner glyph style for the border.

Source · TextInput.swift:16

borders

Instance Property
var borders: BorderEdges

Enabled border sides.

Source · TextInput.swift:17

horizontalPadding

Instance Property
var horizontalPadding: Int

Cell padding inside the left/right border.

Source · TextInput.swift:18

textColor

Instance Property
var textColor: Color

Editable text foreground.

Source · TextInput.swift:19

placeholderColor

Instance Property
var placeholderColor: Color

Empty-draft placeholder foreground.

Source · TextInput.swift:20

ghostText

Instance Property
var ghostText: String?

Dim completion text painted after the draft cursor without changing the editor.

Source · TextInput.swift:22

ghostColor

Instance Property
var ghostColor: Color

Completion preview foreground.

Source · TextInput.swift:23

promptColor

Instance Property
var promptColor: Color?

The prompt marker's foreground, or nil to use the editable text color.

Source · TextInput.swift:26

fill

Instance Property
var fill: Color

Background painted on every cell of the input, including the border.

An explicit color also applies to padding and text cells. The terminal default follows the terminal's background color.

Source · TextInput.swift:32

init(_:placeholder:prompt:maximumRows:)

Initializer
init(_ editor: LineEditor, placeholder: String = "", prompt: String = "❯", maximumRows: Int = 2)

Creates a value with the supplied arguments. Default arguments are shown in the declaration.

Parameters (4)
editor
Argument type and any default are shown in the declaration; see the behavior notes above.
placeholder
Argument type and any default are shown in the declaration; see the behavior notes above.
prompt
Argument type and any default are shown in the declaration; see the behavior notes above.
maximumRows
Maximum number of visible choice rows.
Source · TextInput.swift:41

height(width:)

Instance Method
func height(width: Int) -> Int

The preferred height including the selected borders, with at least one input row.

Parameters (1)
width
Available columns in terminal cells.

Returns Int.

Source · TextInput.swift:49

cursor(in:)

Instance Method
func cursor(in area: Rect) -> Point?

The cursor's absolute terminal cell, or nil when there is no usable input area.

Parameters (1)
in
Argument type and any default are shown in the declaration; see the behavior notes above.

Returns Point?.

Source · TextInput.swift:57

render(in:buffer:)

Instance Method
func render(in area: Rect, buffer: inout Buffer)

Paints this widget into the assigned terminal-cell rectangle. Application code owns state, input routing, and terminal lifetime.

Parameters (2)
in
Argument type and any default are shown in the declaration; see the behavior notes above.
buffer
Mutable destination cell grid.
Source · TextInput.swift:65

contentArea(in:)

Instance Method
func contentArea(in area: Rect) -> Rect

The visible text region, excluding borders, padding, and the prompt label.

Parameters (1)
in
Argument type and any default are shown in the declaration; see the behavior notes above.

Returns Rect.

Source · TextInput.swift:144