Teek API Documentation

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
  • name Symbol, String
  • at String, Symbol — where to place it

Returns void

apply_format(name, from, to)

Applies a previously-#formatted name to a range.

Parameters
  • name Symbol, String
  • from String, Symbol
  • to String, Symbol

Returns void

clear

Empties the whole buffer.

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
  • name Symbol, String
  • from String, Symbol
  • to String, Symbol

Returns void

cursor

Returns String — the text cursor's current position (the insert mark), as "line.char"

cursor=(spec)

Moves the text cursor.

Parameters
  • spec String, Symbol

Returns void

delete(start, end_ nil)

Parameters
  • start String, Symbol
  • end_ String, Symbol, nil — a single character at start if 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
  • name Symbol, 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
  • name Symbol, String
  • opts Hash — Tk text-tag options, e.g. foreground:/font:/underline:

Returns void

format_ranges(name)

Parameters
  • name Symbol, 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
  • start String, Symbol
  • end_ String, Symbol, nil — a single character at start if omitted, the range [start, end_) otherwise

Returns String

index(spec)

Resolves any index expression to its canonical "line.char" form.

Parameters
  • spec String, Symbol

Returns String

initialize(app, path)

Returns TextContent — a new instance of TextContent

@api private

insert(index, text, *tags)

Parameters
  • index String, Symbol
  • text String
  • tags Array<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
  • index String, Symbol
  • image Image, Teek::Photo — anything whose #to_s is a Tcl image name - a DSL Image or a raw Teek::Photo both 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
  • name Symbol, String
  • direction String, Symbol, nil:left/:right to 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
  • name Symbol, String
  • event String — 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
  • name Symbol, 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)

read_only=(value)

Parameters
  • value Boolean

Returns void

remove_marker(name)

Parameters
  • name Symbol, String

Returns void

replace(start, end_, text)

Atomic delete-then-insert over [start, end_).

Parameters
  • start String, Symbol
  • end_ String, Symbol
  • text String

Returns void

scroll_to(index)

Scrolls the view so index is visible.

Parameters
  • index String, Symbol

Returns void

value

Returns String — the whole buffer's text, without the synthetic trailing newline Tk always keeps at end

value=(text)

Replaces the whole buffer’s content outright.

Parameters
  • text String

Returns void