Published release 0.2.1. Unreleased PR #2 reference.
LOOM 0.2.1 / 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
struct TextInputConforms 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:7editor
let editor: LineEditorThe editor snapshot from which this widget is drawn.
Source · TextInput.swift:8placeholder
var placeholder: StringText displayed when the draft is empty and no ghost text is supplied.
Source · TextInput.swift:9prompt
var prompt: StringMarker displayed before editable text.
Source · TextInput.swift:10maximumRows
var maximumRows: IntMaximum visible editable rows, excluding borders.
Source · TextInput.swift:11minimumRows
var minimumRows: IntPreferred minimum editable rows.
Source · TextInput.swift:12borderStyle
var borderStyle: StyleAppearance of the outline, independent of the editable text.
Source · TextInput.swift:15borderType
var borderType: BorderTypeLine/corner glyph style for the border.
Source · TextInput.swift:16borders
var borders: BorderEdgesEnabled border sides.
Source · TextInput.swift:17horizontalPadding
var horizontalPadding: IntCell padding inside the left/right border.
Source · TextInput.swift:18textColor
var textColor: ColorEditable text foreground.
Source · TextInput.swift:19placeholderColor
var placeholderColor: ColorEmpty-draft placeholder foreground.
Source · TextInput.swift:20ghostText
var ghostText: String?Dim completion text painted after the draft cursor without changing the editor.
Source · TextInput.swift:22ghostColor
var ghostColor: ColorCompletion preview foreground.
Source · TextInput.swift:23promptColor
var promptColor: Color?The prompt marker's foreground, or nil to use the editable text color.
Source · TextInput.swift:26fill
var fill: ColorBackground 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:32init(_:placeholder:prompt:maximumRows:)
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.
height(width:)
func height(width: Int) -> IntThe preferred height including the selected borders, with at least one input row.
Parameters (1)
width- Available columns in terminal cells.
Returns Int.
cursor(in:)
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?.
render(in:buffer:)
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.
contentArea(in:)
func contentArea(in area: Rect) -> RectThe 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.