Teek::UI::TextContent Class
The rich text API for one ui.text_area widget’s content - reached
via Handle#text_content, the same shape Handle#tagged/Handle#line
use to hand back a CanvasItem: a small, focused companion object,
not a pile of widget-specific methods on Handle itself.
Indices (every index/from/to/at parameter below) are Tk’s own
text index syntax, passed through verbatim as Ruby strings -
"1.0", "end", "sel.first", "insert 1 line”, a mark name,
“@12,34” - see the Tk text manual page for the full grammar.
This is deliberately NOT wrapped in a new index type - sugar, not a
wall. Two Symbol shortcuts cover the common cases: :end and
:cursor (the insert mark, renamed to something that doesn't
collide with [#insert`](#method-insert){: data-turbo=”false”} the method).
Naming: a Tk text “tag” is not an HTML tag - it’s a named, reusable
set of display properties you apply to ranges, like a CSS class.
The primary vocabulary here calls that a “format” (avoiding “style”,
already taken by ttk’s own style: widget option); the Tk-named
methods (tag_configure, tag_add, …) still work as plain
aliases, so 1:1 Tk documentation mapping and Tk-fluent muscle memory
both keep working.
Every content-mutating method (insert/delete/replace/value=/clear/
insert_image) transparently lifts a -state disabled (read-only)
widget to `normal+ for the duration of the call and restores it
after - Tk itself silently no-ops a mutation against a disabled
text widget, which is exactly the kind of Tk wonk this DSL exists
to hide. An app author building a read-only log pane never needs to
know this footgun exists.
Inherits: Object
Instance Methods ↑
add_marker(name, at:)
A marker is a named, floating position in the text that moves with edits around it - a bookmark, not a range.
Parameters
nameSymbol, StringatString, Symbol— where to place it
Returns void
apply_format(name, from, to)
Applies a previously-#formatted name to a range.
Parameters
nameSymbol, StringfromString, SymboltoString, Symbol
Returns void
clear_format(name, from, to)
Removes name from a range - the format definition itself is
untouched, still applyable elsewhere; see #delete_format to
remove the definition entirely.
Parameters
nameSymbol, StringfromString, SymboltoString, Symbol
Returns void
cursor
Returns String — the text cursor's current position (the insert
mark), as "line.char"
delete(start, end_ nil)
Parameters
startString, Symbolend_String, Symbol, nil— a single character atstartif omitted, the range[start, end_)otherwise
Returns void
delete_format(name)
Deletes a format’s definition entirely, and with it every range it was applied to.
Parameters
nameSymbol, String
Returns void
format(name, **opts)
Defines (or redefines) a named format - a reusable set of display
properties, applied to text ranges via #apply_format.
Parameters
nameSymbol, StringoptsHash— Tk text-tag options, e.g.foreground:/font:/underline:
Returns void
format_ranges(name)
Parameters
nameSymbol, String
Returns Array<String> — a flat list of index pairs - [start1,
end1, start2, end2, ...], one pair per contiguous applied range
get(start '1.0', end_ 'end')
Parameters
startString, Symbolend_String, Symbol, nil— a single character atstartif omitted, the range[start, end_)otherwise
Returns String
index(spec)
Resolves any index expression to its canonical "line.char" form.
Parameters
specString, Symbol
Returns String
insert(index, text, *tags)
Parameters
indexString, SymboltextStringtagsArray<String, Symbol>— format name(s) to apply to the inserted text, same as Tk's own trailing tagList
Returns void
insert_image(index, image:)
Embeds an image inline in the text flow at index.
Parameters
indexString, SymbolimageImage, Teek::Photo— anything whose#to_sis a Tcl image name - a DSLImageor a rawTeek::Photoboth work
Returns void
mark_gravity(name, direction nil)
Which way name drifts when text is inserted exactly at it -
an advanced, rarely-needed Tk concept, so this stays under its Tk
name only (no friendlier alias).
Parameters
nameSymbol, StringdirectionString, Symbol, nil—:left/:rightto set; omit to just read the current gravity
Returns String — "left" or "right"
markers
Returns Array<String> — every marker currently defined, including
the built-in insert/current ones
on_format(name, event, &block)
#on_format_click, for an arbitrary Tk event pattern instead of
the common left-click case.
Parameters
nameSymbol, StringeventString— a Tk bind event pattern, e.g."Double-Button-1"
Returns void
@yield called with no arguments
on_format_click(name, &block)
Fires on a left click anywhere text carrying name is displayed.
Wired through tag bind (not a raw tcl_eval), so the existing
leak-safe reconcile (teek core’s TagBindInterceptor, already
registered for the text widget) releases the callback if name
stops being applied anywhere - the same leak-safety every other
DSL event binding already gets.
Parameters
nameSymbol, String
Returns void
@yield called with no arguments
read_only
Returns Boolean — whether this widget currently rejects direct
typing/edits (its Tk -state is disabled) - #insert/
#delete/etc still work regardless, temporarily lifting this
for their own duration (see the class docs)
replace(start, end_, text)
Atomic delete-then-insert over [start, end_).
Parameters
startString, Symbolend_String, SymboltextString
Returns void
search(pattern, from: 'insert', to: 'end', backwards: false, regexp: false, nocase: false)
Parameters
patternStringfromString, Symbol— where to start searchingtoString, Symbol— the search boundary - withbackwards: truethis is the earliest index the search may reach, same as plain TksearchbackwardsBooleanregexpBoolean— treatpatternas a regular expressionnocaseBoolean
Returns String, nil — the matching index, or nil if not found
value
Returns String — the whole buffer's text, without the synthetic
trailing newline Tk always keeps at end