| Title: | Modern Reactive Terminal Applications with Data Workflows |
|---|---|
| Description: | Build modern reactive terminal applications for data workflows in R using reusable widgets, layouts, events, focus management and themes. A virtual screen buffer and incremental rendering update changed cells, while a headless driver supports deterministic application tests. Includes data tables that render visible rows on demand, lazy table sources, data inspection, SQL editing and background R workers with progress and streamed output. Optional database support and static text, Markdown, HTML, SVG and JSON exports support analytical tools and reports without requiring an interactive terminal for static output. |
| Authors: | Akims Mensikovs [aut, cre, cph] |
| Maintainer: | Akims Mensikovs <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.0.1 |
| Built: | 2026-10-21 17:58:49 UTC |
| Source: | https://github.com/cran/termr |
Changes a numeric field of a widget (e.g. value of a progress_bar(),
offset_y of a scroll_view(), count of a custom widget) smoothly
from its current value to to. Starting a new animation of the same
field replaces the running one. Animations stop when the widget is
removed or the app exits.
animate( widget, property, to, duration = 0.3, easing = "out_cubic", from = NULL, on_complete = NULL )animate( widget, property, to, duration = 0.3, easing = "out_cubic", from = NULL, on_complete = NULL )
widget |
A widget attached to a running app. |
property |
Name of a numeric field. |
to |
Target value. |
duration |
Seconds. |
easing |
|
from |
Start value (default: the current value). |
on_complete |
Optional |
An Animation handle with cancel().
bar <- progress_bar(id = "progress") pilot <- test_app(app(bar), width = 30, height = 1) animate(pilot$query_one("#progress"), "value", to = 1, duration = 0.5) pilot$advance(1) bar$value pilot$stop()bar <- progress_bar(id = "progress") pilot <- test_app(app(bar), width = 30, height = 1) animate(pilot$query_one("#progress"), "value", to = 1, duration = 0.5) pilot$advance(1) bar$value pilot$stop()
Returned by animate().
widget, propertyWhat is animated.
from, toStart and end values.
durationSeconds.
easingEasing name.
startClock time of the start.
activeStill running?
on_completefunction(widget, app) or NULL.
Animation$new()Create an animation (use animate()).
Animation$new(widget, property, from, to, duration, easing, start, on_complete)
widget, property, from, to, duration, easing, start, on_completeSee fields.
Animation$cancel()Stop the animation where it is.
Animation$cancel()
Animation$clone()The objects of this class are cloneable with this method.
Animation$clone(deep = FALSE)
deepWhether to make a deep clone.
Create an application
app( ..., bindings = list(), actions = list(), title = NULL, mouse = TRUE, stylesheet = NULL, theme = "default", debug = FALSE, reduce_motion = NULL )app( ..., bindings = list(), actions = list(), title = NULL, mouse = TRUE, stylesheet = NULL, theme = "default", debug = FALSE, reduce_motion = NULL )
... |
Widgets to show, plus optional |
bindings |
A list of |
actions |
A named list of action functions |
title |
Optional title. |
mouse |
Enable mouse input (clicks, wheel, hover)? |
stylesheet |
A |
theme |
A |
debug |
Bind F12 to a debug overlay (focused and hovered widget, last event, repaint statistics)? |
reduce_motion |
Turn decorative animation off? |
Built-in bindings: tab / shift+tab move focus, ctrl+c quits.
hello <- app( vertical( label("What is your name?"), input(id = "name"), button("Say hello", id = "hello"), label("", id = "output") ), on("button.pressed", "#hello", function(event, app) { name <- app$query_one("#name")$value app$query_one("#output")$update(paste("Hello", name)) }), bind("escape", "quit") ) if (interactive()) run(hello)hello <- app( vertical( label("What is your name?"), input(id = "name"), button("Say hello", id = "hello"), label("", id = "output") ), on("button.pressed", "#hello", function(event, app) { name <- app$query_one("#name")$value app$query_one("#output")$update(paste("Hello", name)) }), bind("escape", "quit") ) if (interactive()) run(hello)
An App owns the widget tree (through its Screen), the event queue,
timers, key bindings, focus and the terminal driver. Create one with
app() and start it with run().
Each tick of the loop waits for input (or the next timer), turns input into events, fires due timers, dispatches every queued event and then, if any widget was invalidated, repaints the screen once: the new frame is diffed against the previous one and only changed cells are written.
An event goes to its target widget (key events: the focused widget) and
bubbles up through the ancestors to the app. At each widget the
on_<type> method runs, then handlers added with widget$on(), then -
for key events - the widget's key bindings. At the app, handlers added
with app$on() / on() run, then app bindings. event$stop() stops
propagation.
titleOptional application title.
reduce_motionNULL (follow the option / environment variable),
TRUE or FALSE: reduce decorative animation? See motion_reduced().
clipboardText copied by widgets (Ctrl+C / Ctrl+X in inputs). This is the app's own clipboard, not the operating system's.
screenThe current Screen.
screensThe screen stack, bottom first.
focusedThe focused widget, or NULL.
themeThe termr_theme() (assign a theme or a theme name).
stylesheetsThe stylesheets of the app.
hoveredThe widget under the mouse pointer, or NULL.
sizeTerminal size: c(width =, height =).
runningIs the app running?
last_paintInstrumentation of the last repaint: screen cells, repainted cells, dirty rectangles, whether it was a full repaint and the ANSI bytes written. For benchmarks and debugging.
profile_last_frameOptional timings and structural counters;
enable with options(termr.profile = TRUE). Times are milliseconds.
frame_statsNumber of full and incremental repaints and of layout passes so far.
frameThe last rendered ScreenBuffer.
App$new()Create an app. See app().
App$new( ..., bindings = list(), actions = list(), title = NULL, mouse = TRUE, stylesheet = NULL, theme = "default", debug = FALSE, reduce_motion = NULL )
...bindingsA list of bind() bindings.
actionsA named list of functions function(app).
titleOptional title.
mouseEnable mouse input?
stylesheetA stylesheet(), stylesheet text or a file path
(or a list of them).
themeA termr_theme() or the name of a built-in theme.
debugBind F12 to the debug overlay?
reduce_motionTRUE to turn decorative animation off, NULL
to follow options(termr.reduce_motion) / the TERMR_REDUCE_MOTION
environment variable.
App$run()Run the app until it exits. Restores the terminal on exit, on error and on interrupt.
App$run(driver = NULL)
driverA terminal driver; detected automatically by default.
The value passed to exit(), invisibly.
App$exit()Ask the app to stop after the current event.
App$exit(value = NULL)
valueValue returned by run().
App$query()Find widgets matching a selector.
App$query(selector)
selectorA selector such as "Button", "#id", ".class".
App$query_one()The first widget matching a selector (error if none).
App$query_one(selector)
selectorA selector.
App$mount()Mount widgets on the screen.
App$mount(...)
...Widgets.
App$on()Add an event handler, see on().
App$on(type, selector = NULL, handler)
typeEvent type.
selectorOptional selector matched against the sender.
handlerfunction(event, app).
App$bind()Add an app-level key binding, see bind().
App$bind(key, action = NULL, description = NULL)
keyKey name or a binding created by bind().
actionAction name or function.
descriptionOptional description.
App$log_events()Record dispatched events (for debugging). Off by default, so normal apps pay nothing.
App$log_events(enable = TRUE, size = 200L)
enableStart (TRUE) or stop (FALSE) recording.
sizeNumber of events kept.
App$event_log()The recorded events as a data frame (see log_events()).
App$event_log()
App$toggle_debug()Show or hide the debug overlay (also F12 with
app(debug = TRUE)).
App$toggle_debug()
App$add_command()Add a command to the command palette (Ctrl+P) and the
help screen (F1). See command().
App$add_command( label, action = NULL, category = NULL, shortcut = NULL, enabled = NULL, description = NULL )
App$show_help()Show the help screen (F1): key bindings of the focused widget, its ancestors and the app, and the app's commands.
App$show_help()
App$bindings()All app-level bindings.
App$bindings()
App$post()Queue an event for dispatch.
App$post(event)
eventAn Event.
App$post_message()Send a custom message from the app (bubbles from the screen).
App$post_message(type, data = list())
typeMessage name.
dataList of values.
App$clipboard_write()Copy text to the clipboard. The app clipboard
(app$clipboard) is always set; when system = TRUE and the terminal
supports OSC 52 the text is also sent to the system clipboard
(write-only: termr never reads the system clipboard). Long text is
truncated to 100 kB for the terminal.
App$clipboard_write(text, system = TRUE)
textA string.
systemAlso write to the system clipboard?
TRUE (invisibly) if the text was sent to the terminal.
App$capture_mouse()Send all mouse events to widget (even outside its
region) until release_mouse() or the next button release. Used for
drags that start elsewhere, e.g. splitters.
App$capture_mouse(widget)
widgetA mounted widget.
App$release_mouse()Stop capturing the mouse.
App$release_mouse()
App$run_action()Run an action by name (or a function).
App$run_action(action, widget = NULL)
actionAction name such as "quit", or a function.
widgetWidget where the lookup starts (NULL: the app).
App$request_repaint()Schedule a repaint at the end of the current tick.
App$request_repaint(widget = NULL, full = is.null(widget), layout = TRUE)
widgetThe widget that changed, if known. Without it the next repaint redraws everything; with it only the rows of changed widgets are repainted when the layout did not change.
fullForce a full repaint?
layoutDoes the change possibly affect sizes or positions? When
FALSE and nothing else changed the layout pass is skipped.
App$refresh()Redraw the whole screen (e.g. after external output).
App$refresh()
App$set_focus()Give focus to a widget (or remove focus with NULL).
App$set_focus(widget)
widgetA focusable widget in this app, or NULL.
TRUE if focus changed.
App$add_stylesheet()Add a stylesheet; its rules apply to all screens.
App$add_stylesheet(sheet)
sheetA stylesheet(), stylesheet text or a file path.
App$clear_stylesheets()Remove all stylesheets.
App$clear_stylesheets()
App$stylesheet_style()The merged stylesheet rules that apply to a widget.
App$stylesheet_style(widget, states = widget$pseudo_states())
widgetA widget.
statesIts pseudo states.
App$push_screen()Show a screen on top of the current one. A widget is
wrapped in a new Screen. Use modal() for dialogs.
App$push_screen(screen, callback = NULL)
screenA Screen (or ModalScreen) or a widget.
callbackOptional function(result, app) called when the
screen is dismissed / popped with a result.
The screen, invisibly.
App$pop_screen()Remove the top screen (or a given screen) and return to the one below, restoring its focus.
App$pop_screen(result = NULL, screen = self$screen)
resultPassed to the screen's callbacks.
screenThe screen to remove (default: the top screen).
App$switch_screen()Replace the top screen.
App$switch_screen(screen)
screenA Screen or a widget.
App$run_worker()Run a function in a background R process. See
run_worker() for the arguments.
App$run_worker( fn, args = list(), on_complete = NULL, on_error = NULL, on_progress = NULL, name = NULL, owner = NULL, packages = character(), inline = FALSE, on_stdout = NULL, on_stderr = NULL, timeout = NULL )
fn, args, on_complete, on_error, on_progress, name, owner, packages, inlineSee run_worker().
on_stdout, on_stderr, timeoutSee run_worker().
App$run_process()Run an external program in the background, without a
shell. See run_process().
App$run_process( command, args = character(), on_complete = NULL, on_error = NULL, on_stdout = NULL, on_stderr = NULL, on_exit = NULL, timeout = NULL, wd = NULL, env = NULL, name = NULL, owner = NULL )
command, args, on_complete, on_error, on_stdout, on_stderr, on_exit, timeout, wd, env, name, ownerSee run_process().
App$workers()Running workers.
App$workers()
App$notify()Show a notification (toast) in the bottom-right corner.
App$notify(message, title = NULL, severity = "information", timeout = 3)
messageText.
titleOptional title.
severity"information", "success", "warning" or "error".
timeoutSeconds before it disappears (Inf: until clicked).
The Toast widget, invisibly.
App$notifications()Active notifications (toasts).
App$notifications()
App$scroll_into_view()Scroll every scroll view containing widget so that it
becomes visible (done at the next repaint).
App$scroll_into_view(widget)
widgetA widget of this app.
App$focus_next()Move focus to the next focusable widget.
App$focus_next()
App$focus_previous()Move focus to the previous focusable widget.
App$focus_previous()
App$focus_chain()Focusable widgets in focus order.
App$focus_chain()
App$set_timeout()Call callback(app) once after delay seconds.
App$set_timeout(delay, callback)
delaySeconds.
callbackFunction.
App$set_interval()Call callback(app) every interval seconds.
App$set_interval(interval, callback)
intervalSeconds.
callbackFunction.
App$call_later()Call callback(app) at the start of the next tick.
App$call_later(callback)
callbackFunction.
App$print()Print a summary of the app.
App$print(...)
...Ignored.
App$clone()The objects of this class are cloneable with this method.
App$clone(deep = FALSE)
deepWhether to make a deep clone.
bind() maps a key (or several keys separated by commas) to an action.
Bindings can be attached to the app (app()), to the screen, to a widget
type (widget()) or to a single widget (widget$bind()). When a key is
pressed, bindings are searched from the focused widget up to the app, so
the most local binding wins.
bind(key, action, description = NULL)bind(key, action, description = NULL)
key |
Key name such as |
action |
Action name or a function. Functions bound on the app are
called as |
description |
Optional human readable description (for help screens and footers). |
An action is either the name of an action or a function. Named actions
are looked up on the widget that owns the binding, then on its
ancestors, then on the app. Prefix a name with "app." to call an app
action directly. Built-in app actions are "quit", "focus_next",
"focus_previous" and "refresh".
An object of class termr_binding.
bind("q", "quit") bind("ctrl+r", function(app) app$refresh(), "Redraw")bind("q", "quit") bind("ctrl+r", function(app) app$refresh(), "Redraw")
browse_data() opens an interactive viewer for a data frame: summary
metrics, a virtualised table (fast for millions of rows), information
about the selected column, search across all columns, sorting, and row
details. data_browser() builds the same app without running it, e.g.
to customise or test it.
browse_data(data, title = deparse(substitute(data)), ...) data_browser(data, title = deparse(substitute(data)), ...)browse_data(data, title = deparse(substitute(data)), ...) data_browser(data, title = deparse(substitute(data)), ...)
data |
A data frame or matrix. |
title |
Title shown at the top (defaults to the expression). |
... |
Passed to |
Keys: arrows / Page Up / Page Down move the cell cursor; / focuses the
search box (Enter applies it, Escape in the box clears it); s sorts by
the current column (again: descending); r resets sorting and search;
Enter shows the row; q quits.
browse_data() returns NULL invisibly; data_browser()
returns an App.
viewer <- data_browser(mtcars) pilot <- test_app(viewer, 100, 30) pilot$press("s") pilot$stop() if (interactive()) browse_data(mtcars)viewer <- data_browser(mtcars) pilot <- test_app(viewer, 100, 30) pilot$press("s") pilot$stop() if (interactive()) browse_data(mtcars)
A focusable button. Pressing Enter or Space while it has focus sends a
"button.pressed" message, which you can handle with
on("button.pressed", "#id", function(event, app) ...).
button( label = "Button", id = NULL, classes = NULL, style = NULL, disabled = FALSE, variant = "default", on_press = NULL )button( label = "Button", id = NULL, classes = NULL, style = NULL, disabled = FALSE, variant = "default", on_press = NULL )
label |
Button text. |
id |
Optional identifier (for |
classes |
Optional classes (for |
style |
A |
disabled |
Disabled buttons cannot be focused or pressed. |
variant |
Colour variant: |
on_press |
Optional |
A Button widget.
button("Run", id = "run", variant = "primary")button("Run", id = "run", variant = "primary")
A focusable button. See button().
Widget -> Button
paint_statesPressing only repaints.
focusableButtons can be focused.
variantColour variant.
press_durationSeconds the pressed state stays visible.
labelThe button text (reactive).
pressedIs the button showing its pressed state?
Widget$add_class()Widget$ancestors()Widget$animate()Widget$arrange_children()Widget$bind()Widget$bind_reactive()Widget$bindings()Widget$blur()Widget$capture_mouse()Widget$child_clip()Widget$clear()Widget$computed_style()Widget$content_height()Widget$content_width()Widget$focus()Widget$format()Widget$get_state()Widget$has_class()Widget$invalidate()Widget$invalidate_paint()Widget$is_displayed()Widget$is_enabled()Widget$layout_descend()Widget$layout_differs()Widget$matches()Widget$mount()Widget$on()Widget$paint()Widget$post_message()Widget$print()Widget$query()Widget$query_one()Widget$refresh()Widget$release_mouse()Widget$remove()Widget$remove_children()Widget$remove_class()Widget$render_lines()Widget$replace()Widget$run_action()Widget$run_process()Widget$run_worker()Widget$set()Widget$set_interval()Widget$set_state()Widget$set_timeout()Widget$toggle_class()Widget$walk()Button$new()Create a button.
Button$new( label = "Button", id = NULL, classes = NULL, style = NULL, disabled = FALSE, variant = "default" )
Button$default_style()The built-in style.
Button$default_style()
Button$default_bindings()Enter and space press the button.
Button$default_bindings()
Button$render()The button text.
Button$render()
Button$press()Press the button: shows the pressed state briefly and
sends a "button.pressed" message. Does nothing when disabled.
Button$press()
TRUE if the button was pressed.
Button$on_click()A left click presses the button.
Button$on_click(event)
eventA MouseEvent.
Button$action_press()Action used by the default bindings.
Button$action_press()
Button$pseudo_states()Active states: focus, disabled and pressed.
Button$pseudo_states()
Button$clone()The objects of this class are cloneable with this method.
Button$clone(deep = FALSE)
deepWhether to make a deep clone.
Cells are the unit of the virtual screen. Each cell holds one character
(a wide character such as a CJK ideograph occupies two cells; the second one is a
continuation cell whose char is ""), colours and text attributes.
cell( char = " ", fg = NULL, bg = NULL, bold = FALSE, italic = FALSE, underline = FALSE, reverse = FALSE, dim = FALSE, strike = FALSE )cell( char = " ", fg = NULL, bg = NULL, bold = FALSE, italic = FALSE, underline = FALSE, reverse = FALSE, dim = FALSE, strike = FALSE )
char |
A single character. |
fg, bg
|
Foreground and background colours. |
bold, italic, underline, reverse, dim, strike
|
Text attributes. |
The framebuffer stores cells column-wise in matrices for speed; cell()
is the value-level representation used for inspection and tests.
An object of class termr_cell.
cell("A", fg = "red", bold = TRUE)cell("A", fg = "red", bold = TRUE)
A labelled toggle. Space, Enter or a click toggles it and sends
"checkbox.changed" (event$data$value).
checkbox( label = "", value = FALSE, id = NULL, classes = NULL, style = NULL, disabled = FALSE )checkbox( label = "", value = FALSE, id = NULL, classes = NULL, style = NULL, disabled = FALSE )
label |
Label text. |
value |
Initial state. |
id |
Optional identifier. |
classes |
Optional classes. |
style |
A |
disabled |
Disabled checkboxes cannot be toggled. |
A Checkbox widget with a reactive value.
checkbox("Enable logs", value = TRUE, id = "logs")checkbox("Enable logs", value = TRUE, id = "logs")
A labelled boolean toggle. See checkbox().
Widget -> Checkbox
focusableCheckboxes can be focused.
valueTRUE or FALSE (reactive; sends "checkbox.changed").
labelThe label (reactive).
Widget$add_class()Widget$ancestors()Widget$animate()Widget$arrange_children()Widget$bind()Widget$bind_reactive()Widget$bindings()Widget$blur()Widget$capture_mouse()Widget$child_clip()Widget$clear()Widget$computed_style()Widget$content_height()Widget$content_width()Widget$focus()Widget$format()Widget$get_state()Widget$has_class()Widget$invalidate()Widget$invalidate_paint()Widget$is_displayed()Widget$is_enabled()Widget$layout_descend()Widget$layout_differs()Widget$matches()Widget$mount()Widget$on()Widget$paint()Widget$post_message()Widget$print()Widget$pseudo_states()Widget$query()Widget$query_one()Widget$refresh()Widget$release_mouse()Widget$remove()Widget$remove_children()Widget$remove_class()Widget$render_lines()Widget$replace()Widget$run_action()Widget$run_process()Widget$run_worker()Widget$set()Widget$set_interval()Widget$set_state()Widget$set_timeout()Widget$toggle_class()Widget$walk()Checkbox$new()Create a checkbox. See checkbox().
Checkbox$new( label = "", value = FALSE, id = NULL, classes = NULL, style = NULL, disabled = FALSE )
labelLabel.
valueInitial state.
id, classes, style, disabledSee Widget.
Checkbox$default_style()The built-in style.
Checkbox$default_style()
Checkbox$default_bindings()Space and Enter toggle.
Checkbox$default_bindings()
Checkbox$toggle()Toggle the value (sends "checkbox.changed").
Checkbox$toggle()
Checkbox$action_toggle()Action used by the bindings.
Checkbox$action_toggle()
Checkbox$on_click()Clicking toggles.
Checkbox$on_click(event)
eventA MouseEvent.
Checkbox$render()The box and the label.
Checkbox$render()
Checkbox$clone()The objects of this class are cloneable with this method.
Checkbox$clone(deep = FALSE)
deepWhether to make a deep clone.
Column options for data tables
column( label = NULL, width = NULL, align = NULL, formatter = NULL, min_width = NULL, max_width = NULL, visible = TRUE, sortable = TRUE, editable = NULL )column( label = NULL, width = NULL, align = NULL, formatter = NULL, min_width = NULL, max_width = NULL, visible = TRUE, sortable = TRUE, editable = NULL )
label |
Header text (defaults to the column name). |
width |
Fixed width in cells; |
align |
|
formatter |
|
min_width, max_width
|
Limits for the estimated width. |
visible |
Show the column? (Hidden columns stay in the data; see
|
sortable |
Can the table be sorted by this column? |
editable |
Can cells be edited (when the table is |
An object of class termr_column.
column(label = "Score", width = 8, align = "right", formatter = function(x) sprintf("%.1f", x))column(label = "Score", width = 8, align = "right", formatter = function(x) sprintf("%.1f", x))
A command is something the user can do: it has a label, an action, an
optional category and keyboard shortcut, and may be enabled or disabled
depending on the app state. The command palette (Ctrl+P) and the help
screen (F1) are built from the same list: commands added with
app$add_command(), the described key bindings of the focused widget, its
ancestors and the app, and the app's named actions. Existing bind()
bindings keep working and appear in both.
command( label, action, category = NULL, shortcut = NULL, enabled = NULL, description = NULL )command( label, action, category = NULL, shortcut = NULL, enabled = NULL, description = NULL )
label |
Text shown in the palette and the help screen. |
action |
An action name or a |
category |
Optional group name, e.g. |
shortcut |
Optional key shown next to the command (documentation
only; use |
enabled |
|
description |
Optional longer text for the help screen. |
An object of class termr_command.
command("Save", action = "save", category = "File", shortcut = "ctrl+s")command("Save", action = "save", category = "File", shortcut = "ctrl+s")
The running app
current_app()current_app()
The App that is currently running, or NULL.
Summarizes numeric/integer, character/factor, logical, Date, and POSIXct
vectors. Numeric summaries use base R type-7 quartiles and sample standard
deviation (stats::sd). Numeric data also gets an eight-bin histogram
rendered with the existing sparkline widget. Without sample, vector
summaries analyze the full in-memory vector. Character top-value counts
cap their frequency table at 100,000 analyzed non-missing values. Supplying
sample analyzes deterministic, evenly spaced positions. A table_source
is rejected to prevent an implicit full scan; fetch or sample data
explicitly first. data may also be a reactive function.
data_profile( data, name = NULL, sample = NULL, top_n = 5L, id = NULL, classes = NULL, style = NULL, disabled = FALSE )data_profile( data, name = NULL, sample = NULL, top_n = 5L, id = NULL, classes = NULL, style = NULL, disabled = FALSE )
data |
An atomic vector, factor, Date, or POSIXct vector. |
name |
Heading for the profile. |
sample |
Optional positive number of evenly spaced values to analyze. |
top_n |
Number of frequent character/factor values to display. |
id |
Optional identifier. |
classes |
Optional classes. |
style |
A |
disabled |
Disable the widget? |
A DataProfile widget with reactive $data and $summary.
data_profile(mtcars$mpg, name = "mpg")data_profile(mtcars$mpg, name = "mpg")
A fast, read-only viewer for data frames: a header, optional row names, automatic column widths, keyboard and mouse navigation, horizontal and vertical scrolling, and a row or cell cursor. Only the visible rows are formatted and painted, so tables with millions of rows scroll smoothly.
data_table( data, cursor = "row", columns = NULL, formatters = NULL, row_names = NA, header = TRUE, zebra = FALSE, row_style = NULL, cell_style = NULL, max_column_width = 40L, frozen_columns = 0L, header_sort = FALSE, editable = FALSE, on_edit = NULL, id = NULL, classes = NULL, style = NULL )data_table( data, cursor = "row", columns = NULL, formatters = NULL, row_names = NA, header = TRUE, zebra = FALSE, row_style = NULL, cell_style = NULL, max_column_width = 40L, frozen_columns = 0L, header_sort = FALSE, editable = FALSE, on_edit = NULL, id = NULL, classes = NULL, style = NULL )
data |
A data frame (tibbles work too) or a matrix. |
cursor |
|
columns |
Named list of |
formatters |
Named list of |
row_names |
Show row names? |
header |
Show the header row? |
zebra |
Stripe alternate rows? |
row_style |
|
cell_style |
|
max_column_width |
Upper limit for automatic column widths. |
frozen_columns |
Number of leading columns that stay in place while the others scroll horizontally. |
header_sort |
Sort when a header is clicked (again: descending, then off; Shift+click adds a secondary key)? |
editable |
Allow editing cells (Enter or double click opens a small
dialog)? The table edits its own copy of the data; read it with |
on_edit |
|
id |
Optional identifier. |
classes |
Optional classes. |
style |
A |
Keys: arrows move the cursor (with a row cursor, Left/Right scroll the
columns), Page Up/Down move a page, Home/End go to the first / last row,
Enter activates the row (or edits the cell when editable), Ctrl+F finds
text (Enter/Down next, Up previous, Tab all columns / this column,
Ctrl+R regex, Alt+C case, Esc close), F3 / Shift+F3 next / previous match,
Ctrl+G jumps to a row, S (with header_sort) sorts by the active column
(ascending, descending, off), Alt+Left / Alt+Right narrow / widen the active column.
Clicking a row selects it; clicking the header sends
"datatable.header_selected" (and sorts with header_sort); dragging the
separator between two header cells resizes a column; the wheel scrolls.
The header and the first frozen_columns columns stay in place while the
rest scrolls.
Messages (event$data):
"datatable.row_selected" / "datatable.cell_selected": the cursor
moved; row (original row number), position (in the view),
value (the row as a list, or the cell value), column (cell cursor);
"datatable.row_activated": Enter; same data;
"datatable.header_selected": column (name) and index;
"datatable.sorted" (columns, decreasing),
"datatable.column_resized" (column, width),
"datatable.columns_changed" (column, visible),
"datatable.found" (position, row, column),
"datatable.cell_changed" (row, column, old, value).
Methods: set_data(), sort(by, decreasing) (several columns allowed),
clear_sort(), toggle_sort(), filter(rows), move_cursor(row, column),
goto_row(), scroll_to_row(), selected_row(), row_data(row),
set_column_width(), auto_size_column(), auto_size_all(),
set_column_visible(), column_info(), find(), find_next(),
find_previous(), edit_cell(), set_cell().
A DataTable widget.
tbl <- data_table(mtcars, id = "cars", zebra = TRUE, formatters = list(mpg = function(x) sprintf("%.1f", x))) render_widget(tbl, 60, 6)tbl <- data_table(mtcars, id = "cars", zebra = TRUE, formatters = list(mpg = function(x) sprintf("%.1f", x))) render_widget(tbl, 60, 6)
See data_profile().
Widget -> Vertical -> DataProfile
sampleThe deterministic sample size, or NULL for full scan.
top_nNumber of frequent text values shown.
dataThe vector being summarized (reactive).
summaryComputed summary statistics and histogram data.
Widget$add_class()Widget$ancestors()Widget$animate()Widget$arrange_children()Widget$bind()Widget$bind_reactive()Widget$bindings()Widget$blur()Widget$capture_mouse()Widget$child_clip()Widget$clear()Widget$computed_style()Widget$content_height()Widget$content_width()Widget$default_bindings()Widget$focus()Widget$format()Widget$get_state()Widget$has_class()Widget$invalidate()Widget$invalidate_paint()Widget$is_displayed()Widget$is_enabled()Widget$layout_descend()Widget$layout_differs()Widget$matches()Widget$mount()Widget$on()Widget$paint()Widget$post_message()Widget$print()Widget$pseudo_states()Widget$query()Widget$query_one()Widget$refresh()Widget$release_mouse()Widget$remove()Widget$remove_children()Widget$remove_class()Widget$render()Widget$render_lines()Widget$replace()Widget$run_action()Widget$run_process()Widget$run_worker()Widget$set()Widget$set_interval()Widget$set_state()Widget$set_timeout()Widget$toggle_class()Widget$walk()DataProfile$new()Create a vector profile. See data_profile().
DataProfile$new( data, name = "value", sample = NULL, top_n = 5L, id = NULL, classes = NULL, style = NULL, disabled = FALSE )
dataAn in-memory supported vector.
nameHeading.
sampleOptional deterministic sample size.
top_nFrequent values to show.
id, classes, styleSee Widget.
disabledIs the widget disabled?
DataProfile$default_style()The built-in style.
DataProfile$default_style()
DataProfile$clone()The objects of this class are cloneable with this method.
DataProfile$clone(deep = FALSE)
deepWhether to make a deep clone.
A virtualised table for data frames or lazy table sources. See data_table().
Widget -> DataTable
paint_statesCursor and scroll changes only repaint.
focusableTables can be focused.
cursor_type"row", "cell" or "none".
show_headerShow the header row?
zebraStripe alternate rows?
row_styleNULL or function(row, data) returning a style for
a data row (row is the original row number or source position).
cell_styleNULL or function(value, row, column) returning a
style for a cell.
frozen_columnsNumber of leading columns that stay visible while the others scroll horizontally.
header_sortClicking a header sorts by that column (click again: descending, then unsorted; Shift+click adds a column)?
editableAllow editing cells (Enter / double click)?
on_editNULL or function(row, column, value) called before a
cell edit is applied; return NULL / TRUE to accept or a message
to reject the edit.
dataThe data frame or source (assigning calls set_data()).
row_countNumber of rows in the current view.
column_namesNames of the data columns.
cursor_rowCursor position in the view (0 = none).
cursor_columnCursor column number (cell cursor; 0 = none).
offset_row, offset_columnScroll offsets (rows / columns).
viewRow numbers or source view positions in display order.
sort_stateNULL or a data frame (column, decreasing) of
the current sort keys.
match_hitNULL or the current search result (position,
row, column).
Widget$add_class()Widget$ancestors()Widget$animate()Widget$arrange_children()Widget$bind()Widget$bind_reactive()Widget$bindings()Widget$blur()Widget$capture_mouse()Widget$child_clip()Widget$clear()Widget$computed_style()Widget$focus()Widget$format()Widget$get_state()Widget$has_class()Widget$invalidate()Widget$invalidate_paint()Widget$is_displayed()Widget$is_enabled()Widget$layout_descend()Widget$layout_differs()Widget$matches()Widget$mount()Widget$on()Widget$post_message()Widget$print()Widget$pseudo_states()Widget$query()Widget$query_one()Widget$release_mouse()Widget$remove()Widget$remove_children()Widget$remove_class()Widget$render()Widget$render_lines()Widget$replace()Widget$run_action()Widget$run_process()Widget$run_worker()Widget$set()Widget$set_interval()Widget$set_state()Widget$set_timeout()Widget$toggle_class()Widget$walk()DataTable$new()Create a table. See data_table().
DataTable$new( data, cursor = "row", columns = NULL, formatters = NULL, row_names = NA, header = TRUE, zebra = FALSE, row_style = NULL, cell_style = NULL, max_column_width = 40L, frozen_columns = 0L, header_sort = FALSE, editable = FALSE, on_edit = NULL, id = NULL, classes = NULL, style = NULL, disabled = FALSE )
dataA data frame, matrix, or table_source().
cursorCursor type.
columnsNamed list of column() options.
formattersNamed list of formatter functions.
row_namesShow row names? NA: only when they are not 1..n.
headerShow the header?
zebraStripe rows?
row_style, cell_styleStyle hooks.
max_column_widthUpper limit for estimated widths.
frozen_columns, header_sort, editable, on_editSee the fields.
id, classes, style, disabledSee Widget.
filtersNamed column filters for filter_columns().
DataTable$default_style()The built-in style.
DataTable$default_style()
DataTable$default_bindings()Navigation keys and Enter.
DataTable$default_bindings()
DataTable$set_data()Replace the data. Resets the view, cursor and scroll.
DataTable$set_data(data)
dataA data frame, matrix, or table_source().
DataTable$refresh()Re-read the source row count and clear cached rows.
DataTable$refresh()
DataTable$close()Explicitly close this table's source resource.
DataTable$close()
DataTable$source_stats()Read structural fetch/cache counters for diagnostics.
DataTable$source_stats()
DataTable$sort()Sort the view by one or more columns (stable; NAs
last). Sorting always starts from the unsorted view (after
filter()), so sort(c("cyl", "mpg")) sorts by cyl, then mpg.
DataTable$sort(by, decreasing = FALSE)
byColumn names or numbers.
decreasingSort in decreasing order? One value, or one per column.
DataTable$clear_sort()Remove the sort order (back to the order before sorting).
DataTable$clear_sort()
DataTable$toggle_sort()Header-click behaviour: sort by a column ascending, then descending, then unsorted.
DataTable$toggle_sort(column, add = FALSE)
columnColumn name or number.
addAdd the column to the existing sort (secondary key)?
DataTable$filter()Show a subset of rows (in the given order), or all rows.
DataTable$filter(rows = NULL)
rowsRow numbers of the data, a logical vector over the rows,
or NULL for all rows.
DataTable$filter_columns()Filter named columns; all predicates are combined with
AND and evaluated in row chunks. A predicate may be a
table_filter() or function(values) logical.
DataTable$filter_columns(filters = NULL)
filtersNamed list by column; NULL clears column filters.
DataTable$move_cursor()Move the cursor (and scroll so it is visible).
DataTable$move_cursor(row = NULL, column = NULL)
rowPosition in the view.
columnColumn name or number (cell cursor).
DataTable$scroll_to_row()Scroll so that a view position is the first visible row.
DataTable$scroll_to_row(row)
rowPosition in the view.
DataTable$selected_row()The data-frame row number or source row key under the cursor (or NA).
DataTable$selected_row()
DataTable$row_data()One data row as a named list.
DataTable$row_data(row)
rowOriginal row number.
DataTable$selected_data()Data for selected view rows, in view order. A single cursor row is returned when no range is selected.
DataTable$selected_data()
DataTable$visible_data()Data in the current viewport, in display order.
DataTable$visible_data()
DataTable$reorder_column()Move a column in the display order.
DataTable$reorder_column(column, to)
columnColumn name or number.
toNew 1-based position in the complete column order.
DataTable$select_range()Select a range of rows by view position.
DataTable$select_range(from, to = from)
from, to1-based positions in the view.
DataTable$copy_selection()Copy selected rows as tab-separated values.
DataTable$copy_selection(headers = TRUE, system = TRUE)
headersInclude column names?
systemAlso write to the system clipboard when supported?
DataTable$goto_row()Jump to a row of the view (and scroll to it).
DataTable$goto_row(row)
rowPosition in the view (1-based).
DataTable$column_width()Width of a column in cells.
DataTable$column_width(column)
columnColumn name or number.
DataTable$set_column_width()Set a column's width (at least 1 cell). Sends
"datatable.column_resized".
DataTable$set_column_width(column, width)
columnColumn name or number.
widthWidth in cells.
DataTable$auto_size_column()Fit a column to its content. Rows are sampled, never all scanned unless asked for, so this is fast for huge tables.
DataTable$auto_size_column(column, rows = c("sample", "visible", "all"))
columnColumn name or number.
rows"sample" (the visible rows plus the first and last 500;
default), "visible" (visible rows only) or "all" (every row of
the view; slow for millions of rows).
DataTable$auto_size_all()Fit every visible column to its content.
DataTable$auto_size_all(rows = c("sample", "visible", "all"))
rowsSee auto_size_column().
DataTable$set_column_visible()Show or hide a column.
DataTable$set_column_visible(column, visible = TRUE)
columnColumn name or number.
visibleTRUE to show, FALSE to hide.
DataTable$column_info()Describe the columns: name, label, width, visible, sortable.
DataTable$column_info()
DataTable$find()Search the formatted cell text and move the cursor to the first match at or after the cursor (reading order, wrapping around). Large tables are scanned in chunks; the data is never converted to one big string matrix.
DataTable$find(query, column = NULL, case_sensitive = FALSE, regex = FALSE)
queryText or regular expression (PCRE).
columnSearch only this column (name or number); NULL: all
visible columns.
case_sensitiveMatch case?
regexIs query a regular expression?
TRUE if there is a match (invisibly).
DataTable$find_next()Go to the next match.
DataTable$find_next()
DataTable$find_previous()Go to the previous match.
DataTable$find_previous()
DataTable$clear_find()Forget the search and close the find bar.
DataTable$clear_find()
DataTable$edit_cell()Edit a cell in a small dialog (needs editable = TRUE).
The default is the cursor cell.
DataTable$edit_cell(position = NULL, column = NULL)
positionPosition in the view (default: the cursor row).
columnColumn name or number (default: the cursor / active column).
DataTable$set_cell()Change one cell of the table's own copy of the data
(the data frame you passed in is never modified; read the result
with $data). Runs on_edit, then sends "datatable.cell_changed"
with row, column, old and value.
DataTable$set_cell(row, column, value)
rowOriginal row number.
columnColumn name or number.
valueNew value (must fit the column type).
DataTable$action_cursor_up()Actions used by the bindings.
DataTable$action_cursor_up()
DataTable$action_cursor_down()Move down.
DataTable$action_cursor_down()
DataTable$action_extend_selection_up()Extend selection upward.
DataTable$action_extend_selection_up()
DataTable$action_extend_selection_down()Extend selection downward.
DataTable$action_extend_selection_down()
DataTable$action_move_column_left()Move the active column left in display order.
DataTable$action_move_column_left()
DataTable$action_move_column_right()Move the active column right in display order.
DataTable$action_move_column_right()
DataTable$action_copy_selection()Copy selected rows.
DataTable$action_copy_selection()
DataTable$action_cursor_left()Move left (cell cursor) or scroll left.
DataTable$action_cursor_left()
DataTable$action_cursor_right()Move right (cell cursor) or scroll right.
DataTable$action_cursor_right()
DataTable$action_page_up()Move one page up.
DataTable$action_page_up()
DataTable$action_page_down()Move one page down.
DataTable$action_page_down()
DataTable$action_first_row()Go to the first row.
DataTable$action_first_row()
DataTable$action_last_row()Go to the last row.
DataTable$action_last_row()
DataTable$action_open_find()Open the find bar (Ctrl+F).
DataTable$action_open_find()
DataTable$action_open_goto()Open the "go to row" bar (Ctrl+G).
DataTable$action_open_goto()
DataTable$action_find_next()Go to the next match (F3).
DataTable$action_find_next()
DataTable$action_find_previous()Go to the previous match (Shift+F3).
DataTable$action_find_previous()
DataTable$action_widen_column()Make the active column one cell wider (Alt+Right).
DataTable$action_widen_column()
DataTable$action_narrow_column()Make the active column one cell narrower (Alt+Left).
DataTable$action_narrow_column()
DataTable$action_sort_column()Sort by the active column (S): ascending, descending, off.
DataTable$action_sort_column()
DataTable$action_activate()Send "datatable.row_activated" for the cursor row
(or edit the cell when the table is editable).
DataTable$action_activate()
DataTable$on_mouse_down()Mouse: clicking a row moves the cursor, clicking the
header sends "datatable.header_selected" (and sorts when
header_sort is on); dragging a column separator in the header
resizes the column; a double click edits a cell of an editable table.
DataTable$on_mouse_down(event)
eventA MouseEvent.
DataTable$on_drag_move()Resizing a column by dragging its header separator.
DataTable$on_drag_move(event)
eventA MouseEvent.
DataTable$on_drag_end()Ends a column resize.
DataTable$on_drag_end(event)
eventA MouseEvent.
DataTable$on_key()Keys for the find / go-to bar while it is open.
DataTable$on_key(event)
eventA KeyEvent.
DataTable$on_paste()Pasted text goes into the find / go-to bar when open.
DataTable$on_paste(event)
eventA PasteEvent.
DataTable$on_mouse_scroll()The mouse wheel scrolls three rows.
DataTable$on_mouse_scroll(event)
eventA MouseEvent.
DataTable$content_width()Natural width: all columns.
DataTable$content_width()
DataTable$content_height()Natural height: header plus rows (at most 1000).
DataTable$content_height(width)
widthContent width.
DataTable$paint()Draw the visible part of the table.
DataTable$paint(buffer, area, st)
bufferA ScreenBuffer.
areaVisible part of the region.
stComputed style.
DataTable$clone()The objects of this class are cloneable with this method.
DataTable$clone(deep = FALSE)
deepWhether to make a deep clone.
Wrap a DBI connection for use by termr SQL widgets
db_connection(con, name = NULL, owned = FALSE)db_connection(con, name = NULL, owned = FALSE)
con |
A DBI connection. |
name |
Optional connection label. |
owned |
Disconnect this connection when |
A lightweight connection wrapper with query(), execute(),
is_valid(), and disconnect() methods.
Composes a lazy object tree, SQLite table preview, SQL editor and result table, details and in-memory query history. The object tree loads metadata only when its Tables or Views node is expanded. DBI/RSQLite remain optional dependencies.
db_explorer(connection, id = NULL)db_explorer(connection, id = NULL)
connection |
A |
id |
Optional widget identifier. |
A DatabaseExplorer widget with $refresh(), $run_query(),
$open_table(), and $query_history() methods.
if (requireNamespace("DBI", quietly = TRUE) && requireNamespace("RSQLite", quietly = TRUE)) { con <- DBI::dbConnect(RSQLite::SQLite(), ":memory:") DBI::dbWriteTable(con, "mtcars", mtcars) pilot <- test_app(app(db_explorer(db_connection(con, owned = TRUE)))) pilot$stop() # App teardown closes its owned connection. }if (requireNamespace("DBI", quietly = TRUE) && requireNamespace("RSQLite", quietly = TRUE)) { con <- DBI::dbConnect(RSQLite::SQLite(), ":memory:") DBI::dbWriteTable(con, "mtcars", mtcars) pilot <- test_app(app(db_explorer(db_connection(con, owned = TRUE)))) pilot$stop() # App teardown closes its owned connection. }
The returned functions use DBI's portable table and field listing. SQLite additionally exposes views from its catalog. Driver packages can use this small callback protocol when building their own metadata views; the explorer does not yet have an adapter registry.
db_metadata(connection)db_metadata(connection)
connection |
A |
A list with schemas(), tables(schema), views(schema),
columns(table, schema), and quote(identifier) functions.
The source implements table_source() and fetches bounded pages for a
query result. The built-in pager supports RSQLite only. Other DBI drivers
can provide an adapter list with column_names(connection, query, params), row_count(connection, query, params), and get_rows(connection, query, params, start, count, columns) callbacks. This keeps dialect-specific
pagination in the backend adapter rather than assuming all DBI drivers use
the same SQL.
db_query_source(connection, query, params = NULL, adapter = NULL)db_query_source(connection, query, params = NULL, adapter = NULL)
connection |
A |
query |
A single query that returns a result set. |
params |
Optional DBI parameter list passed to the query. |
adapter |
Optional backend adapter callbacks. |
The built-in SQLite adapter wraps the query as a subquery, runs one cached
COUNT(*), and adds bound LIMIT/OFFSET values to page requests. A single
trailing semicolon is removed before wrapping. The query must produce one
result set; arbitrary SQL statements are not parsed or rewritten. The row
count can be expensive, but it is computed once at source creation and on
explicit refresh, never on repaint.
The returned source is read-only. Sorting, filtering, and search are not pushed into the user query.
An experimental table_source() accepted directly by
data_table().
This optional adapter uses bounded LIMIT/OFFSET queries and
parameterized filter values. It supports equals, contains, range, and
missing table_filter() filters and sorting by quoted column names.
Arbitrary queries and other SQL dialects are intentionally outside this
adapter; custom table_source() callbacks can implement driver-specific
pagination.
db_table_source(connection, table, owned = FALSE)db_table_source(connection, table, owned = FALSE)
connection |
An open RSQLite connection, or a |
table |
A table name or |
owned |
If |
An experimental table source accepted by data_table().
Computes the minimal set of horizontal runs of cells that must be
rewritten to turn the screen old into new. Nearby runs on the same
row are merged when rewriting the unchanged cells between them is cheaper
than an extra cursor movement.
diff_screen(old, new, merge_gap = 3L)diff_screen(old, new, merge_gap = 3L)
old, new
|
ScreenBuffer objects ( |
merge_gap |
Runs separated by at most this many unchanged cells are merged. |
If old is NULL or has different dimensions, the patch covers every
non-blank cell of new and is marked full = TRUE; the renderer then
clears the screen first.
A termr_patch: a list with full (logical), width, height
and runs, a list of runs. Each run has y, x and vectors chars,
fg, bg, attrs copied from new.
a <- screen_buffer(10, 2) b <- a$copy() b$put_text(3, 2, "hi") diff_screen(a, b)a <- screen_buffer(10, 2) b <- a$copy() b$put_text(3, 2, "hi") diff_screen(a, b)
Shows the selected choice; Enter, Space, Down or a click opens a list
below it. Choosing an option sends "dropdown.changed"
(event$data: value, label); Escape or a click outside closes the
list.
dropdown( choices, value = NULL, prompt = "Select", id = NULL, classes = NULL, style = NULL, disabled = FALSE )dropdown( choices, value = NULL, prompt = "Select", id = NULL, classes = NULL, style = NULL, disabled = FALSE )
choices |
A character vector; names, if present, are shown. |
value |
Initially selected value, or |
prompt |
Text shown when nothing is selected. |
id |
Optional identifier. |
classes |
Optional classes. |
style |
A |
disabled |
Disabled selects cannot be opened. |
Named dropdown() rather than select() so that it does not mask
dplyr::select(); the widget type (for selectors) is Select.
A Select widget with a reactive value.
dropdown(c("Comma separated" = "csv", "JSON" = "json"), value = "csv", id = "format")dropdown(c("Comma separated" = "csv", "JSON" = "json"), value = "csv", id = "format")
Everything that happens in a termr application is an event: key
presses, terminal resizes, focus changes, widgets being mounted, and
messages that widgets send (such as "button.pressed").
Events are delivered to their target widget and, if they bubble, to
each ancestor in turn and finally to the App. Any handler can call
event$stop() to stop propagation.
Event types and their classes:
"key": KeyEvent with fields key, char, ctrl, alt, shift;
"resize": ResizeEvent with width and height;
"paste": PasteEvent with the pasted text (bracketed paste);
"focus" / "blur": FocusEvent / BlurEvent (do not bubble);
"mount" / "unmount": MountEvent / UnmountEvent (do not bubble);
any other name: MessageEvent, created by widget$post_message().
typeEvent type, e.g. "key" or "button.pressed".
senderThe widget that created the event (or NULL).
targetThe widget the event is delivered to first.
currentThe widget currently handling the event.
dataA list of event-specific values.
bubblesIs the event passed on to ancestors?
timeCreation time (seconds, monotonic).
stoppedHas propagation been stopped?
default_preventedWas prevent_default() called?
Event$new()Create an event.
Event$new(type, sender = NULL, data = list(), bubbles = TRUE)
typeEvent type.
senderSending widget.
dataList of values.
bubblesDoes the event bubble?
Event$stop()Stop the event from reaching further handlers.
Event$stop()
Event$prevent_default()Ask the sender not to perform its default behaviour.
Event$prevent_default()
Event$format()One-line description.
Event$format(...)
...Ignored.
Event$print()Print the event.
Event$print(...)
...Ignored.
Event$clone()The objects of this class are cloneable with this method.
Event$clone(deep = FALSE)
deepWhether to make a deep clone.
Event -> KeyEvent
keyCanonical key name, e.g. "a", "enter", "ctrl+c".
charThe printable character, or "".
ctrl, alt, shiftModifier flags.
KeyEvent$new()Create a key event.
KeyEvent$new(key, char = NULL)
keyKey name (normalised).
charPrintable character, if any.
KeyEvent$is_printable()Is this a printable character without ctrl/alt?
KeyEvent$is_printable()
KeyEvent$clone()The objects of this class are cloneable with this method.
KeyEvent$clone(deep = FALSE)
deepWhether to make a deep clone.
Event -> ResizeEvent
width, heightNew terminal size.
ResizeEvent$new()Create a resize event.
ResizeEvent$new(width, height)
width, heightTerminal size.
ResizeEvent$clone()The objects of this class are cloneable with this method.
ResizeEvent$clone(deep = FALSE)
deepWhether to make a deep clone.
Event -> PasteEvent
textThe pasted text, normalised: line breaks are LF, tabs are kept and other control characters are removed.
PasteEvent$new()Create a paste event.
PasteEvent$new(text)
textPasted text.
PasteEvent$clone()The objects of this class are cloneable with this method.
PasteEvent$clone(deep = FALSE)
deepWhether to make a deep clone.
Event -> FocusEvent
FocusEvent$new()Create a focus event.
FocusEvent$new(widget)
widgetThe widget that received focus.
FocusEvent$clone()The objects of this class are cloneable with this method.
FocusEvent$clone(deep = FALSE)
deepWhether to make a deep clone.
Event -> BlurEvent
BlurEvent$new()Create a blur event.
BlurEvent$new(widget)
widgetThe widget that lost focus.
BlurEvent$clone()The objects of this class are cloneable with this method.
BlurEvent$clone(deep = FALSE)
deepWhether to make a deep clone.
Event -> MountEvent
MountEvent$new()Create a mount event.
MountEvent$new(widget)
widgetThe mounted widget.
MountEvent$clone()The objects of this class are cloneable with this method.
MountEvent$clone(deep = FALSE)
deepWhether to make a deep clone.
Event -> UnmountEvent
UnmountEvent$new()Create an unmount event.
UnmountEvent$new(widget)
widgetThe removed widget.
UnmountEvent$clone()The objects of this class are cloneable with this method.
UnmountEvent$clone(deep = FALSE)
deepWhether to make a deep clone.
Event -> MessageEvent
MessageEvent$new()Create a custom message.
MessageEvent$new(type, sender = NULL, data = list(), bubbles = TRUE)
typeMessage name, e.g. "counter.changed".
senderSending widget.
dataList of values.
bubblesDoes the message bubble?
MessageEvent$clone()The objects of this class are cloneable with this method.
MessageEvent$clone(deep = FALSE)
deepWhether to make a deep clone.
Event -> MouseEvent
action"down", "up", "move", "scroll" or "click".
button"left", "middle", "right" or "none".
directionWheel direction for scroll events, else NA.
screen_x, screen_yPointer position on the screen (1-based).
x, yPointer position inside the target widget (1-based, relative to the widget's region).
origin_x, origin_yWhere the button went down (screen
coordinates) for drag.* events, else NA.
shift, ctrl, altModifier flags.
MouseEvent$new()Create a mouse event.
MouseEvent$new( action, screen_x, screen_y, button = "none", direction = NA_character_, shift = FALSE, ctrl = FALSE, alt = FALSE )
actionEvent action.
screen_x, screen_yScreen position.
buttonButton name.
directionWheel direction (scroll events).
shift, ctrl, altModifiers.
MouseEvent$offset_in()The pointer position relative to another widget.
MouseEvent$offset_in(widget)
widgetA widget with a region.
c(x =, y =), 1-based; may be outside the widget.
MouseEvent$clone()The objects of this class are cloneable with this method.
MouseEvent$clone(deep = FALSE)
deepWhether to make a deep clone.
Arranges children in a grid. See grid_layout().
Widget -> Grid
Widget$add_class()Widget$ancestors()Widget$animate()Widget$arrange_children()Widget$bind()Widget$bind_reactive()Widget$bindings()Widget$blur()Widget$capture_mouse()Widget$child_clip()Widget$clear()Widget$computed_style()Widget$content_height()Widget$content_width()Widget$default_bindings()Widget$focus()Widget$format()Widget$get_state()Widget$has_class()Widget$initialize()Widget$invalidate()Widget$invalidate_paint()Widget$is_displayed()Widget$is_enabled()Widget$layout_descend()Widget$layout_differs()Widget$matches()Widget$mount()Widget$on()Widget$paint()Widget$post_message()Widget$print()Widget$pseudo_states()Widget$query()Widget$query_one()Widget$refresh()Widget$release_mouse()Widget$remove()Widget$remove_children()Widget$remove_class()Widget$render()Widget$render_lines()Widget$replace()Widget$run_action()Widget$run_process()Widget$run_worker()Widget$set()Widget$set_interval()Widget$set_state()Widget$set_timeout()Widget$toggle_class()Widget$walk()Grid$default_style()The built-in style.
Grid$default_style()
Grid$clone()The objects of this class are cloneable with this method.
Grid$clone(deep = FALSE)
deepWhether to make a deep clone.
Places children in a grid, row by row. Column (and optionally row)
tracks are sized like widgets: a number of cells, "auto" (natural size
of the content), "<n>fr" (share of the remaining space) or "<n>%".
Rows not listed are "auto". A child can cover several cells with
style(column_span = 2, row_span = 2).
grid_layout( ..., columns = 2L, rows = NULL, gap = 0L, id = NULL, classes = NULL, style = NULL )grid_layout( ..., columns = 2L, rows = NULL, gap = 0L, id = NULL, classes = NULL, style = NULL )
... |
Child widgets. |
columns |
A number of equal columns, or a vector of column sizes. |
rows |
Optional vector of row sizes. |
gap |
Space between cells: one value, or |
id |
Optional identifier. |
classes |
Optional classes. |
style |
A |
Named grid_layout() because grid() would mask graphics::grid().
A Grid widget.
ui <- grid_layout( label("a"), label("b"), label("c"), label("wide", style = style(column_span = 2)), columns = c("1fr", "2fr"), gap = 1 ) render_widget(ui, 20, 5)ui <- grid_layout( label("a"), label("b"), label("c"), label("wide", style = style(column_span = 2)), columns = c("1fr", "2fr"), gap = 1 ) render_widget(ui, 20, 5)
Arranges children left to right. See horizontal().
Widget -> Horizontal
Widget$add_class()Widget$ancestors()Widget$animate()Widget$arrange_children()Widget$bind()Widget$bind_reactive()Widget$bindings()Widget$blur()Widget$capture_mouse()Widget$child_clip()Widget$clear()Widget$computed_style()Widget$content_height()Widget$content_width()Widget$default_bindings()Widget$focus()Widget$format()Widget$get_state()Widget$has_class()Widget$initialize()Widget$invalidate()Widget$invalidate_paint()Widget$is_displayed()Widget$is_enabled()Widget$layout_descend()Widget$layout_differs()Widget$matches()Widget$mount()Widget$on()Widget$paint()Widget$post_message()Widget$print()Widget$pseudo_states()Widget$query()Widget$query_one()Widget$refresh()Widget$release_mouse()Widget$remove()Widget$remove_children()Widget$remove_class()Widget$render()Widget$render_lines()Widget$replace()Widget$run_action()Widget$run_process()Widget$run_worker()Widget$set()Widget$set_interval()Widget$set_state()Widget$set_timeout()Widget$toggle_class()Widget$walk()Horizontal$default_style()The built-in style.
Horizontal$default_style()
Horizontal$clone()The objects of this class are cloneable with this method.
Horizontal$clone(deep = FALSE)
deepWhether to make a deep clone.
A focusable text field.
input( value = "", placeholder = "", id = NULL, classes = NULL, style = NULL, disabled = FALSE, password = FALSE, max_length = NULL, validate = NULL )input( value = "", placeholder = "", id = NULL, classes = NULL, style = NULL, disabled = FALSE, password = FALSE, max_length = NULL, validate = NULL )
value |
Initial text. |
placeholder |
Text shown while the input is empty. |
id |
Optional identifier (for |
classes |
Optional classes (for |
style |
A |
disabled |
Disabled inputs cannot be focused or edited. |
password |
Show bullets instead of the typed characters. |
max_length |
Maximum number of characters. |
validate |
Optional |
Keys: typing inserts at the cursor (replacing a selection);
Left/Right/Home/End move (Ctrl+E: end); Ctrl+Left/Right move by word;
Shift (+Ctrl) with those keys selects; Ctrl+A selects all;
Backspace/Delete delete a character or the selection;
Ctrl+Backspace / Alt+Backspace / Ctrl+W and Ctrl+Delete / Alt+D delete a
word; Ctrl+U / Ctrl+K delete to the start / end; Ctrl+C, Ctrl+X and
Ctrl+V copy, cut and paste with the app clipboard (app$clipboard;
Ctrl+C without a selection keeps its app meaning, quit by default).
The mouse places the cursor; shift+click and dragging select.
Messages (event$data): "input.changed" (value, valid) on every
change, "input.submitted" (value, valid) on Enter, and
"input.valid" / "input.invalid" (value, error) when the result of
validate changes. Invalid inputs have the :invalid state (red
border by default).
An Input widget. Read or set the text with $value; see also
$valid, $error, $selection, $select_range().
name <- input(placeholder = "Your name", id = "name", validate = function(x) if (!nzchar(x)) "Required") name$valid name$value <- "Ada" name$validname <- input(placeholder = "Your name", id = "name", validate = function(x) if (!nzchar(x)) "Required") name$valid name$value <- "Ada" name$valid
A single-line text input. See input().
Widget -> Input
paint_statesCursor and selection changes only repaint.
focusableInputs can be focused.
placeholderText shown while the input is empty.
passwordShow bullets instead of the characters?
max_lengthMaximum number of characters, or NULL.
validateNULL or function(value) returning NULL (valid)
or an error message.
valueThe text (reactive). Assigning moves the cursor to the
end and sends "input.changed".
cursor_positionCursor position in characters (0 = start).
selectionThe selected text ("" if none).
validDoes the value pass validate?
errorThe validation message, or NULL.
Widget$add_class()Widget$ancestors()Widget$animate()Widget$arrange_children()Widget$bind()Widget$bind_reactive()Widget$bindings()Widget$blur()Widget$capture_mouse()Widget$child_clip()Widget$computed_style()Widget$content_height()Widget$focus()Widget$format()Widget$get_state()Widget$has_class()Widget$invalidate()Widget$invalidate_paint()Widget$is_displayed()Widget$is_enabled()Widget$layout_descend()Widget$layout_differs()Widget$matches()Widget$mount()Widget$on()Widget$paint()Widget$post_message()Widget$print()Widget$query()Widget$query_one()Widget$refresh()Widget$release_mouse()Widget$remove()Widget$remove_children()Widget$remove_class()Widget$render()Widget$replace()Widget$run_action()Widget$run_process()Widget$run_worker()Widget$set()Widget$set_interval()Widget$set_state()Widget$set_timeout()Widget$toggle_class()Widget$walk()Input$new()Create an input.
Input$new( value = "", placeholder = "", id = NULL, classes = NULL, style = NULL, disabled = FALSE, password = FALSE, max_length = NULL, validate = NULL )
valueInitial text.
placeholderPlaceholder text.
id, classes, style, disabledSee Widget.
passwordMask the characters?
max_lengthMaximum number of characters.
validateValidation function.
Input$default_style()The built-in style.
Input$default_style()
Input$pseudo_states()Active states: focus, hover, disabled and invalid.
Input$pseudo_states()
Input$default_bindings()Editing key bindings.
Input$default_bindings()
Input$on_key()Printable keys replace the selection or are inserted at the cursor. Ctrl+C / Ctrl+X copy / cut when text is selected (otherwise Ctrl+C keeps its app meaning).
Input$on_key(event)
eventA KeyEvent.
Input$on_mouse_down()Clicking places the cursor; shift+click and dragging select.
Input$on_mouse_down(event)
eventA MouseEvent.
Input$on_mouse_move()Dragging with the left button extends the selection.
Input$on_mouse_move(event)
eventA MouseEvent.
Input$on_paste()Pasted text is inserted as one edit. An Input is a single line, so line breaks in the paste become spaces.
Input$on_paste(event)
eventA PasteEvent.
Input$insert()Insert text at the cursor (replacing the selection).
Input$insert(text)
textA string.
Input$clear()Remove all text.
Input$clear()
Input$select_range()Select a range of characters.
Input$select_range(start, end)
start, endPositions (0 = before the first character).
Input$copy()Copy the selection to the app clipboard (and, when
system = TRUE and supported, to the system clipboard via OSC 52).
Input$copy(system = TRUE)
systemAlso write to the system clipboard?
Input$action_cursor_left()Move one character left.
Input$action_cursor_left()
Input$action_cursor_right()Move one character right.
Input$action_cursor_right()
Input$action_cursor_home()Move to the start.
Input$action_cursor_home()
Input$action_cursor_end()Move to the end.
Input$action_cursor_end()
Input$action_word_left()Move to the previous word.
Input$action_word_left()
Input$action_word_right()Move to the next word.
Input$action_word_right()
Input$action_select_left()Extend the selection left.
Input$action_select_left()
Input$action_select_right()Extend the selection right.
Input$action_select_right()
Input$action_select_home()Select to the start.
Input$action_select_home()
Input$action_select_end()Select to the end.
Input$action_select_end()
Input$action_select_word_left()Select to the previous word.
Input$action_select_word_left()
Input$action_select_word_right()Select to the next word.
Input$action_select_word_right()
Input$action_select_all()Select everything.
Input$action_select_all()
Input$action_delete_left()Delete the selection or the character before the cursor.
Input$action_delete_left()
Input$action_delete_right()Delete the selection or the character at the cursor.
Input$action_delete_right()
Input$action_delete_word_left()Delete the word before the cursor.
Input$action_delete_word_left()
Input$action_delete_word_right()Delete the word after the cursor.
Input$action_delete_word_right()
Input$action_delete_to_start()Delete everything before the cursor.
Input$action_delete_to_start()
Input$action_delete_to_end()Delete everything after the cursor.
Input$action_delete_to_end()
Input$action_paste()Insert the app clipboard.
Input$action_paste()
Input$action_submit()Send an "input.submitted" message (Enter).
Input$action_submit()
Input$content_width()Natural content width.
Input$content_width()
Input$render_lines()The visible part of the text, scrolled so the cursor is visible, with the cursor drawn in reverse video and the selection highlighted when focused.
Input$render_lines(width = NA_integer_)
widthContent width.
Input$clone()The objects of this class are cloneable with this method.
Input$clone(deep = FALSE)
deepWhether to make a deep clone.
Return dependency and subscriber names, lifecycle state, and cumulative counters for a signal, computed value, or watcher.
inspect_signal(x)inspect_signal(x)
x |
A |
A list describing the node and its direct graph edges.
Collects what termr knows about a widget: type, id, classes, region, states, reactive state values, computed style, matching stylesheet rules, bindings, parent and children. Printing the result gives a readable report.
inspect_widget(x, selector = NULL)inspect_widget(x, selector = NULL)
x |
An App or a widget. |
selector |
A selector to find the widget when |
A list of class termr_inspection.
ui <- vertical(button("Save", id = "save", classes = "primary")) inspect_widget(ui, "#save")ui <- vertical(button("Save", id = "save", classes = "primary")) inspect_widget(ui, "#save")
Displays already-parsed R objects as a tree_view(). Named lists and
data frames are objects; unnamed lists and vectors are arrays. Children
are created when a node is expanded. At most page_size children are
created per page; a Load next ... node exposes the next page. Character
scalars are quoted, logical values use lowercase JSON spelling, NULL is
shown as null, and R NA is shown as NA to keep it distinct from JSON
null. Set parse = TRUE for JSON text when optional package jsonlite
is installed; this is a convenience over the primary R-object interface.
json_view( x, parse = FALSE, page_size = 100L, id = NULL, classes = NULL, style = NULL, disabled = FALSE )json_view( x, parse = FALSE, page_size = 100L, id = NULL, classes = NULL, style = NULL, disabled = FALSE )
x |
An R object, or one JSON string when |
parse |
Parse a JSON character string with optional |
page_size |
Maximum children created when a tree node is expanded. |
id |
Optional identifier. |
classes |
Optional classes. |
style |
A |
disabled |
Disable focus and tree interaction? |
A TreeView with lazily loaded object/array children.
json_view(list(user = list(id = 42, name = "Alice"), active = TRUE))json_view(list(user = list(id = 42, name = "Alice"), active = TRUE))
Mostly useful in tests: see test_app() for simulating key presses.
key_event(key)key_event(key)
key |
Key name such as |
A KeyEvent.
key_event("ctrl+c")key_event("ctrl+c")
Shows names and values in two aligned columns, e.g. a summary of a data set.
key_value(data = list(), id = NULL, classes = NULL, style = NULL)key_value(data = list(), id = NULL, classes = NULL, style = NULL)
data |
A named list or vector. |
id |
Optional identifier. |
classes |
Optional classes. |
style |
A |
A KeyValue widget with a reactive data field.
key_value(): a few known values shown in full, such as a summary
panel. Not focusable, does not scroll; values are not wrapped.
property_grid(): an inspector for many or arbitrary named values.
Focusable and scrollable, wraps long values, formats vectors and lists
compactly and accepts a format function.
record_view(): property_grid() for exactly one record, such as the
selected row of a data_table(); accepts a one-row data frame.
render_widget(key_value(list(Rows = 32, Columns = 11, Source = "mtcars")), 20, 3)render_widget(key_value(list(Rows = 32, Columns = 11, Source = "mtcars")), 20, 3)
See key_value().
Widget -> KeyValue
dataNamed list of values (reactive).
Widget$add_class()Widget$ancestors()Widget$animate()Widget$arrange_children()Widget$bind()Widget$bind_reactive()Widget$bindings()Widget$blur()Widget$capture_mouse()Widget$child_clip()Widget$clear()Widget$computed_style()Widget$content_height()Widget$content_width()Widget$default_bindings()Widget$focus()Widget$format()Widget$get_state()Widget$has_class()Widget$invalidate()Widget$invalidate_paint()Widget$is_displayed()Widget$is_enabled()Widget$layout_descend()Widget$layout_differs()Widget$matches()Widget$mount()Widget$on()Widget$paint()Widget$post_message()Widget$print()Widget$pseudo_states()Widget$query()Widget$query_one()Widget$refresh()Widget$release_mouse()Widget$remove()Widget$remove_children()Widget$remove_class()Widget$render_lines()Widget$replace()Widget$run_action()Widget$run_process()Widget$run_worker()Widget$set()Widget$set_interval()Widget$set_state()Widget$set_timeout()Widget$toggle_class()Widget$walk()KeyValue$new()Create a key/value list. See key_value().
KeyValue$new(data = list(), id = NULL, classes = NULL, style = NULL)
dataNamed list or vector.
id, classes, styleSee Widget.
KeyValue$default_style()The built-in style.
KeyValue$default_style()
KeyValue$render()Aligned key and value lines.
KeyValue$render()
KeyValue$clone()The objects of this class are cloneable with this method.
KeyValue$clone(deep = FALSE)
deepWhether to make a deep clone.
Render a static representation for knitr or Quarto
knit_termr(x, width = 80, height = 24, format = c("markdown", "html"))knit_termr(x, width = 80, height = 24, format = c("markdown", "html"))
x |
A widget, Screen, App, or ScreenBuffer. |
width, height
|
Frame size in cells. |
format |
Explicit output format: |
A knitr::asis_output() object.
Text label
label(text = "", id = NULL, classes = NULL, style = NULL, wrap = NULL)label(text = "", id = NULL, classes = NULL, style = NULL, wrap = NULL)
text |
A string, a character vector (one element per line), a
number, or |
id |
Optional identifier (for |
classes |
Optional classes (for |
style |
A |
wrap |
Shortcut for |
A Label widget. Change its text with $update() or by
assigning $text.
lbl <- label("Hello", style = style(bold = TRUE)) lbl$update("Goodbye") render_widget(lbl, 10, 1)lbl <- label("Hello", style = style(bold = TRUE)) lbl$update("Goodbye") render_widget(lbl, 10, 1)
Displays text. See label().
Widget -> Label
textThe label text (reactive).
Widget$add_class()Widget$ancestors()Widget$animate()Widget$arrange_children()Widget$bind()Widget$bind_reactive()Widget$bindings()Widget$blur()Widget$capture_mouse()Widget$child_clip()Widget$clear()Widget$computed_style()Widget$content_height()Widget$content_width()Widget$default_bindings()Widget$focus()Widget$format()Widget$get_state()Widget$has_class()Widget$invalidate()Widget$invalidate_paint()Widget$is_displayed()Widget$is_enabled()Widget$layout_descend()Widget$layout_differs()Widget$matches()Widget$mount()Widget$on()Widget$paint()Widget$post_message()Widget$print()Widget$pseudo_states()Widget$query()Widget$query_one()Widget$refresh()Widget$release_mouse()Widget$remove()Widget$remove_children()Widget$remove_class()Widget$render_lines()Widget$replace()Widget$run_action()Widget$run_process()Widget$run_worker()Widget$set()Widget$set_interval()Widget$set_state()Widget$set_timeout()Widget$toggle_class()Widget$walk()Label$new()Create a label.
Label$new(text = "", id = NULL, classes = NULL, style = NULL, visible = TRUE)
Label$default_style()The built-in style.
Label$default_style()
Label$update()Replace the text.
Label$update(text = "")
textNew text.
Label$render()The label content.
Label$render()
Label$clone()The objects of this class are cloneable with this method.
Label$clone(deep = FALSE)
deepWhether to make a deep clone.
A scrolling log for long-running work. write() appends lines with a
level ("debug", "info", "success", "warning", "error", shown
in different colours). Only the last max_lines lines are kept, so
memory stays bounded. While the view is scrolled to the end it follows
new lines; scroll up (keys or wheel) to read older lines, or pause().
log_view( max_lines = 1000L, timestamps = FALSE, auto_scroll = TRUE, id = NULL, classes = NULL, style = NULL )log_view( max_lines = 1000L, timestamps = FALSE, auto_scroll = TRUE, id = NULL, classes = NULL, style = NULL )
max_lines |
Number of lines kept. |
timestamps |
Prefix lines with |
auto_scroll |
Follow new lines? |
id |
Optional identifier. |
classes |
Optional classes. |
style |
A |
A LogView widget with methods write(), clear(),
pause(), resume().
logs <- log_view(max_lines = 500, id = "log") logs$write("Starting model...") logs$write("Convergence is slow", level = "warning")logs <- log_view(max_lines = 500, id = "log") logs$write("Starting model...") logs$write("Convergence is slow", level = "warning")
See log_view().
Widget -> ListBase -> LogView
has_cursorLog views scroll; they have no cursor.
max_linesLines kept (older lines are dropped).
timestampsPrefix lines with the time?
auto_scrollFollow new lines while scrolled to the end?
linesThe current lines.
pausedIs following paused?
Widget$add_class()Widget$ancestors()Widget$animate()Widget$arrange_children()Widget$bind()Widget$bind_reactive()Widget$bindings()Widget$blur()Widget$capture_mouse()Widget$child_clip()Widget$computed_style()Widget$focus()Widget$format()Widget$get_state()Widget$has_class()Widget$invalidate()Widget$invalidate_paint()Widget$is_displayed()Widget$is_enabled()Widget$layout_descend()Widget$layout_differs()Widget$matches()Widget$mount()Widget$on()Widget$post_message()Widget$print()Widget$pseudo_states()Widget$query()Widget$query_one()Widget$refresh()Widget$release_mouse()Widget$remove()Widget$remove_children()Widget$remove_class()Widget$render()Widget$render_lines()Widget$replace()Widget$run_action()Widget$run_process()Widget$run_worker()Widget$set()Widget$set_interval()Widget$set_state()Widget$set_timeout()Widget$toggle_class()Widget$walk()ListBase$action_list_activate()ListBase$action_list_down()ListBase$action_list_first()ListBase$action_list_last()ListBase$action_list_page_down()ListBase$action_list_page_up()ListBase$action_list_up()ListBase$content_height()ListBase$content_width()ListBase$default_bindings()ListBase$default_style()ListBase$highlight()ListBase$on_activate()ListBase$on_click()ListBase$on_highlight()ListBase$on_mouse_down()ListBase$on_mouse_scroll()ListBase$paint()ListBase$scroll_to_end()ListBase$scroll_to_item()LogView$new()Create a log view. See log_view().
LogView$new( max_lines = 1000L, timestamps = FALSE, auto_scroll = TRUE, id = NULL, classes = NULL, style = NULL )
max_lines, timestamps, auto_scrollSee fields.
id, classes, styleSee Widget.
LogView$write()Add lines.
LogView$write(..., level = "info")
...Text, pasted together; newlines start new lines.
level"debug", "info", "success", "warning" or "error".
LogView$clear()Remove all lines.
LogView$clear()
LogView$pause()Stop following new lines.
LogView$pause()
LogView$resume()Follow new lines again (and jump to the end).
LogView$resume()
LogView$at_end()Is the view scrolled to the last line?
LogView$at_end()
LogView$item_count()Number of lines.
LogView$item_count()
LogView$item_text()Text of line i.
LogView$item_text(i)
iIndex.
LogView$item_style()Style of line i (by level).
LogView$item_style(i)
iIndex.
LogView$clone()The objects of this class are cloneable with this method.
LogView$clone(deep = FALSE)
deepWhether to make a deep clone.
Shows Markdown text: headings, paragraphs, bold, italic,
~~strikethrough~~, inline code, fenced code blocks, bullet and numbered
lists, block quotes, horizontal rules, simple pipe tables and links. It
is meant for help screens, release notes and dialogs; there is no HTML
and the parser is not CommonMark-complete. Text is wrapped to the width
of the view.
markdown_view(text, id = NULL, classes = NULL, style = NULL, scroll = TRUE)markdown_view(text, id = NULL, classes = NULL, style = NULL, scroll = TRUE)
text |
Markdown source (a character vector is joined with newlines). |
id |
Optional identifier. |
classes |
Optional classes. |
style |
A |
scroll |
Wrap the view in a scrollable container? |
With scroll = TRUE (the default) the view is placed in a
scroll_view() that fills its parent; use scroll = FALSE for short
text inside your own layout.
A scroll_view() containing a MarkdownView (or the
MarkdownView itself with scroll = FALSE). Change the text with
$set_markdown(); the MarkdownView is the first child of the scroll
view.
md <- markdown_view("# Title\n\nSome *emphasis* and `code`.\n\n- one\n- two", scroll = FALSE) render_widget(md, 40, 8)$to_text()md <- markdown_view("# Title\n\nSome *emphasis* and `code`.\n\n- one\n- two", scroll = FALSE) render_widget(md, 40, 8)$to_text()
A read-only Markdown document. See markdown_view().
Widget -> MarkdownView
markdownThe source text (assigning calls set_markdown()).
linksThe links in the document: a data frame (text, url).
Widget$add_class()Widget$ancestors()Widget$animate()Widget$arrange_children()Widget$bind()Widget$bind_reactive()Widget$bindings()Widget$blur()Widget$capture_mouse()Widget$child_clip()Widget$clear()Widget$computed_style()Widget$default_bindings()Widget$focus()Widget$format()Widget$get_state()Widget$has_class()Widget$invalidate()Widget$invalidate_paint()Widget$is_displayed()Widget$is_enabled()Widget$layout_descend()Widget$layout_differs()Widget$matches()Widget$mount()Widget$on()Widget$paint()Widget$post_message()Widget$print()Widget$pseudo_states()Widget$query()Widget$query_one()Widget$refresh()Widget$release_mouse()Widget$remove()Widget$remove_children()Widget$remove_class()Widget$render()Widget$replace()Widget$run_action()Widget$run_process()Widget$run_worker()Widget$set()Widget$set_interval()Widget$set_state()Widget$set_timeout()Widget$toggle_class()Widget$walk()MarkdownView$new()Create a Markdown view.
MarkdownView$new(text = "", id = NULL, classes = NULL, style = NULL)
textMarkdown source.
id, classes, styleSee Widget.
MarkdownView$default_style()The built-in style.
MarkdownView$default_style()
MarkdownView$set_markdown()Replace the document.
MarkdownView$set_markdown(text)
textMarkdown source.
MarkdownView$render_lines()The rendered lines for a width.
MarkdownView$render_lines(width = NA_integer_)
widthContent width.
MarkdownView$content_width()Natural width.
MarkdownView$content_width()
MarkdownView$content_height()Natural height for a width.
MarkdownView$content_height(width)
widthContent width.
MarkdownView$clone()The objects of this class are cloneable with this method.
MarkdownView$clone(deep = FALSE)
deepWhether to make a deep clone.
A key number with a label and an optional change (delta) shown as a green up or red down arrow. Useful in dashboards.
metric( label, value = NA, delta = NULL, format = NULL, id = NULL, classes = NULL, style = NULL )metric( label, value = NA, delta = NULL, format = NULL, id = NULL, classes = NULL, style = NULL )
label |
Label shown above the value. |
value |
The value (any R value; numbers are formatted with thousands separators). |
delta |
Optional change since the last value. |
format |
Optional |
id |
Optional identifier. |
classes |
Optional classes. |
style |
A |
A Metric widget with reactive value and delta, and method
update(value, delta).
render_widget(metric("Accuracy", 0.943, delta = 0.012), 20, 4)render_widget(metric("Accuracy", 0.943, delta = 0.012), 20, 4)
See metric().
Widget -> Metric
formatterfunction(value) returning a string.
valueThe value (reactive).
deltaThe change shown next to the value (reactive).
Widget$add_class()Widget$ancestors()Widget$animate()Widget$arrange_children()Widget$bind()Widget$bind_reactive()Widget$bindings()Widget$blur()Widget$capture_mouse()Widget$child_clip()Widget$clear()Widget$computed_style()Widget$content_height()Widget$content_width()Widget$default_bindings()Widget$focus()Widget$format()Widget$get_state()Widget$has_class()Widget$invalidate()Widget$invalidate_paint()Widget$is_displayed()Widget$is_enabled()Widget$layout_descend()Widget$layout_differs()Widget$matches()Widget$mount()Widget$on()Widget$paint()Widget$post_message()Widget$print()Widget$pseudo_states()Widget$query()Widget$query_one()Widget$refresh()Widget$release_mouse()Widget$remove()Widget$remove_children()Widget$remove_class()Widget$render_lines()Widget$replace()Widget$run_action()Widget$run_process()Widget$run_worker()Widget$set()Widget$set_interval()Widget$set_state()Widget$set_timeout()Widget$toggle_class()Widget$walk()Metric$new()Create a metric. See metric().
Metric$new( label, value = NA, delta = NULL, format = NULL, id = NULL, classes = NULL, style = NULL )
labelLabel.
valueValue.
deltaChange.
formatFormatter.
id, classes, styleSee Widget.
Metric$default_style()The built-in style.
Metric$default_style()
Metric$update()Set the value (and optionally the delta).
Metric$update(value, delta = NULL)
valueNew value.
deltaNew delta (NULL keeps none).
Metric$render()Label, value and delta lines.
Metric$render()
Metric$clone()The objects of this class are cloneable with this method.
Metric$clone(deep = FALSE)
deepWhether to make a deep clone.
modal() builds a screen that is drawn over the current one and takes
the keyboard and mouse until it is closed. Show it with
app$push_screen(); close it with Escape or screen$dismiss(result).
The previously focused widget gets focus back.
modal( ..., title = NULL, width = 50L, dim = TRUE, dismissable = TRUE, on_dismiss = NULL, id = NULL ) confirm_dialog( message, on_confirm = NULL, on_cancel = NULL, title = "Confirm", confirm_label = "OK", cancel_label = "Cancel", width = 50L ) alert_dialog(message, title = "Message", button_label = "OK", width = 50L)modal( ..., title = NULL, width = 50L, dim = TRUE, dismissable = TRUE, on_dismiss = NULL, id = NULL ) confirm_dialog( message, on_confirm = NULL, on_cancel = NULL, title = "Confirm", confirm_label = "OK", cancel_label = "Cancel", width = 50L ) alert_dialog(message, title = "Message", button_label = "OK", width = 50L)
... |
Content widgets (placed in a bordered panel). |
title |
Panel title. |
width |
Panel width (cells, |
dim |
Dim the screens below? |
dismissable |
Can Escape close the dialog? |
on_dismiss |
|
id |
Optional identifier of the screen. |
message |
Message text. |
on_confirm, on_cancel
|
|
confirm_label, cancel_label
|
Button labels. |
button_label |
Label of the close button. |
confirm_dialog() and alert_dialog() are ready-made dialogs built on
modal().
A ModalScreen.
dlg <- confirm_dialog("Delete file?", on_confirm = function(app) message("deleted")) a <- app(label("main")) pilot <- test_app(a, 40, 10) a$push_screen(dlg) pilot$press("tab", "enter") # move to OK, press it pilot$stop()dlg <- confirm_dialog("Delete file?", on_confirm = function(app) message("deleted")) a <- app(label("main")) pilot <- test_app(a, 40, 10) a$push_screen(dlg) pilot$press("tab", "enter") # move to OK, press it pilot$stop()
A screen drawn over the current one. See modal().
Widget -> Screen -> ModalScreen
dimDim the screens below?
dismissableClose with Escape?
on_dismissNULL or function(result, app) called when the
screen is dismissed.
Widget$add_class()Widget$ancestors()Widget$animate()Widget$arrange_children()Widget$bind()Widget$bind_reactive()Widget$bindings()Widget$blur()Widget$capture_mouse()Widget$child_clip()Widget$clear()Widget$computed_style()Widget$content_height()Widget$content_width()Widget$focus()Widget$format()Widget$get_state()Widget$has_class()Widget$invalidate()Widget$invalidate_paint()Widget$is_displayed()Widget$is_enabled()Widget$layout_descend()Widget$layout_differs()Widget$matches()Widget$mount()Widget$on()Widget$paint()Widget$post_message()Widget$print()Widget$pseudo_states()Widget$query()Widget$query_one()Widget$refresh()Widget$release_mouse()Widget$remove()Widget$remove_children()Widget$remove_class()Widget$render()Widget$render_lines()Widget$replace()Widget$run_action()Widget$run_process()Widget$run_worker()Widget$set()Widget$set_interval()Widget$set_state()Widget$set_timeout()Widget$toggle_class()Widget$walk()ModalScreen$new()Create a modal screen. See modal().
ModalScreen$new( ..., dim = TRUE, dismissable = TRUE, on_dismiss = NULL, id = NULL, classes = NULL, style = NULL )
...Child widgets.
dim, dismissableSee fields.
on_dismissCallback.
id, classes, styleSee Widget.
ModalScreen$default_style()The built-in style: content centred.
ModalScreen$default_style()
ModalScreen$default_bindings()Escape closes the screen (when dismissable).
ModalScreen$default_bindings()
ModalScreen$dismiss()Close the screen, passing result to the callbacks.
ModalScreen$dismiss(result = NULL)
resultAny value.
ModalScreen$action_dismiss()Action used by the Escape binding.
ModalScreen$action_dismiss()
ModalScreen$clone()The objects of this class are cloneable with this method.
ModalScreen$clone(deep = FALSE)
deepWhether to make a deep clone.
Decorative animation (animate() transitions, indeterminate progress
shimmer, spinners) is turned off when motion is reduced: animate() jumps
to the final value at once, spinners show a still symbol. Timers, events
and real progress updates are unaffected. Motion is reduced when
app(reduce_motion = TRUE), options(termr.reduce_motion = TRUE) or the
environment variable TERMR_REDUCE_MOTION=1 is set (in that order of
precedence).
motion_reduced(app = NULL)motion_reduced(app = NULL)
app |
An app, or |
TRUE or FALSE.
motion_reduced()motion_reduced()
on() creates an event handler that can be passed to app() together
with the widgets. It is equivalent to calling app$on().
on(type, selector = NULL, handler)on(type, selector = NULL, handler)
type |
Event type such as |
selector |
Optional selector (e.g. |
handler |
|
The handler runs when an event of the given type reaches the app and, if a selector is given, the widget that sent the event matches it.
An object of class termr_handler.
on("button.pressed", "#hello", function(event, app) { app$query_one("#output")$update("Hello!") })on("button.pressed", "#hello", function(event, app) { app$query_one("#output")$update("Hello!") })
A scrollable list of choices. Up/Down/Page Up/Page Down/Home/End move the
highlight (sending "option_list.highlighted"); Enter or a click selects
("option_list.selected"). event$data has index, value and
label.
option_list(choices, id = NULL, classes = NULL, style = NULL)option_list(choices, id = NULL, classes = NULL, style = NULL)
choices |
A character vector. Names, if present, are shown instead of the values. |
id |
Optional identifier. |
classes |
Optional classes. |
style |
A |
An OptionList widget with field value.
option_list(c(Comma = "csv", JSON = "json", Parquet = "parquet"))option_list(c(Comma = "csv", JSON = "json", Parquet = "parquet"))
A list of choices. See option_list().
Widget -> ListBase -> OptionList
valueValue of the highlighted choice (NULL if none).
choicesThe choice values.
Widget$add_class()Widget$ancestors()Widget$animate()Widget$arrange_children()Widget$bind()Widget$bind_reactive()Widget$bindings()Widget$blur()Widget$capture_mouse()Widget$child_clip()Widget$clear()Widget$computed_style()Widget$focus()Widget$format()Widget$get_state()Widget$has_class()Widget$invalidate()Widget$invalidate_paint()Widget$is_displayed()Widget$is_enabled()Widget$layout_descend()Widget$layout_differs()Widget$matches()Widget$mount()Widget$on()Widget$post_message()Widget$print()Widget$pseudo_states()Widget$query()Widget$query_one()Widget$refresh()Widget$release_mouse()Widget$remove()Widget$remove_children()Widget$remove_class()Widget$render()Widget$render_lines()Widget$replace()Widget$run_action()Widget$run_process()Widget$run_worker()Widget$set()Widget$set_interval()Widget$set_state()Widget$set_timeout()Widget$toggle_class()Widget$walk()ListBase$action_list_activate()ListBase$action_list_down()ListBase$action_list_first()ListBase$action_list_last()ListBase$action_list_page_down()ListBase$action_list_page_up()ListBase$action_list_up()ListBase$content_height()ListBase$content_width()ListBase$default_bindings()ListBase$default_style()ListBase$highlight()ListBase$item_style()ListBase$on_click()ListBase$on_mouse_down()ListBase$on_mouse_scroll()ListBase$paint()ListBase$scroll_to_end()ListBase$scroll_to_item()OptionList$new()Create an option list. See option_list().
OptionList$new( choices, id = NULL, classes = NULL, style = NULL, disabled = FALSE )
choicesChoices.
id, classes, style, disabledSee Widget.
OptionList$set_choices()Replace the choices.
OptionList$set_choices(choices)
choicesCharacter vector (named: names are shown).
OptionList$item_count()Number of choices.
OptionList$item_count()
OptionList$item_text()Label of choice i.
OptionList$item_text(i)
iIndex.
OptionList$on_highlight()Sends "option_list.highlighted".
OptionList$on_highlight(i)
iIndex.
OptionList$on_activate()Sends "option_list.selected".
OptionList$on_activate(i)
iIndex.
OptionList$clone()The objects of this class are cloneable with this method.
OptionList$clone(deep = FALSE)
deepWhether to make a deep clone.
A container with a border and an optional title in the top border. Its height follows its content by default.
panel(..., title = NULL, id = NULL, classes = NULL, style = NULL)panel(..., title = NULL, id = NULL, classes = NULL, style = NULL)
... |
Child widgets. |
title |
Title shown in the top border. |
id |
Optional identifier. |
classes |
Optional classes. |
style |
A |
A Panel widget. Change the title with $border_title.
render_widget(panel(label("CPU 42%"), title = "Metrics"), 20, 3)render_widget(panel(label("CPU 42%"), title = "Metrics"), 20, 3)
A bordered container with an optional title. See panel().
Widget$add_class()Widget$ancestors()Widget$animate()Widget$arrange_children()Widget$bind()Widget$bind_reactive()Widget$bindings()Widget$blur()Widget$capture_mouse()Widget$child_clip()Widget$clear()Widget$computed_style()Widget$content_height()Widget$content_width()Widget$default_bindings()Widget$focus()Widget$format()Widget$get_state()Widget$has_class()Widget$initialize()Widget$invalidate()Widget$invalidate_paint()Widget$is_displayed()Widget$is_enabled()Widget$layout_descend()Widget$layout_differs()Widget$matches()Widget$mount()Widget$on()Widget$paint()Widget$post_message()Widget$print()Widget$pseudo_states()Widget$query()Widget$query_one()Widget$refresh()Widget$release_mouse()Widget$remove()Widget$remove_children()Widget$remove_class()Widget$render()Widget$render_lines()Widget$replace()Widget$run_action()Widget$run_process()Widget$run_worker()Widget$set()Widget$set_interval()Widget$set_state()Widget$set_timeout()Widget$toggle_class()Widget$walk()Panel$default_style()The built-in style.
Panel$default_style()
Panel$clone()The objects of this class are cloneable with this method.
Panel$clone(deep = FALSE)
deepWhether to make a deep clone.
Each run becomes a cursor movement followed by the run's characters. An SGR (style) sequence is emitted only when the style differs from the previous cell. The output always ends with a style reset.
patch_to_ansi(patch, color_mode = "truecolor")patch_to_ansi(patch, color_mode = "truecolor")
patch |
A patch from |
color_mode |
One of |
A single string.
a <- screen_buffer(10, 1) b <- a$copy() b$put_text(1, 1, "hi", fg = "red") patch_to_ansi(diff_screen(a, b))a <- screen_buffer(10, 1) b <- a$copy() b$put_text(1, 1, "hi", fg = "red") patch_to_ansi(diff_screen(a, b))
Runs an external program (without a shell) and shows its output in a
scrolling log: standard output as normal lines and standard error in the
error colour, under a one-line status. The process starts when the view
is mounted (or call $start()), is cancelled when the view is removed
or the app exits, and sends "process.finished" (status, state)
when it ends. Ctrl+X cancels it and Ctrl+R restarts it while the view
has focus. Experimental.
process_view( command, args = character(), wd = NULL, env = NULL, timeout = NULL, autostart = TRUE, max_lines = 2000L, id = NULL, classes = NULL, style = NULL )process_view( command, args = character(), wd = NULL, env = NULL, timeout = NULL, autostart = TRUE, max_lines = 2000L, id = NULL, classes = NULL, style = NULL )
command |
The program (a path or a name on the |
args |
Arguments, one element each; never interpreted by a shell. |
wd |
Working directory ( |
env |
Named character vector of extra environment variables. |
timeout |
Seconds before the process is stopped ( |
autostart |
Start when mounted? |
max_lines |
Output lines kept. |
id, classes, style
|
Common widget arguments. |
A ProcessView widget with $start(), $cancel(),
$restart(), $running, $output and $worker.
pv <- process_view(file.path(R.home("bin"), "Rscript"), c("-e", "cat('hi\\n')"), autostart = FALSE) pv$runningpv <- process_view(file.path(R.home("bin"), "Rscript"), c("-e", "cat('hi\\n')"), autostart = FALSE) pv$running
Runs a program and shows its output. See process_view().
Widget -> Vertical -> ProcessView
command, args, wd, env, timeoutThe process to run.
autostartStart when the widget is mounted?
workerThe Worker of the current run, or NULL.
runningIs the process running?
outputThe output lines so far.
Widget$add_class()Widget$ancestors()Widget$animate()Widget$arrange_children()Widget$bind()Widget$bind_reactive()Widget$bindings()Widget$blur()Widget$capture_mouse()Widget$child_clip()Widget$clear()Widget$computed_style()Widget$content_height()Widget$content_width()Widget$focus()Widget$format()Widget$get_state()Widget$has_class()Widget$invalidate()Widget$invalidate_paint()Widget$is_displayed()Widget$is_enabled()Widget$layout_descend()Widget$layout_differs()Widget$matches()Widget$mount()Widget$on()Widget$paint()Widget$post_message()Widget$print()Widget$pseudo_states()Widget$query()Widget$query_one()Widget$refresh()Widget$release_mouse()Widget$remove()Widget$remove_children()Widget$remove_class()Widget$render()Widget$render_lines()Widget$replace()Widget$run_action()Widget$run_process()Widget$run_worker()Widget$set()Widget$set_interval()Widget$set_state()Widget$set_timeout()Widget$toggle_class()Widget$walk()Vertical$default_style()ProcessView$new()Create a process view. See process_view().
ProcessView$new( command, args = character(), wd = NULL, env = NULL, timeout = NULL, autostart = TRUE, max_lines = 2000L, id = NULL, classes = NULL, style = NULL )
command, args, wd, env, timeoutThe process to run.
autostartStart when mounted?
max_linesOutput lines kept.
id, classes, styleSee Widget.
ProcessView$default_bindings()Ctrl+X cancels the process, Ctrl+R restarts it.
ProcessView$default_bindings()
ProcessView$on_mount()Start the process when the widget is mounted.
ProcessView$on_mount(event)
eventA MountEvent.
ProcessView$start()Run the process (output starts afresh).
ProcessView$start()
ProcessView$cancel()Stop the process.
ProcessView$cancel()
ProcessView$restart()Cancel the process and run it again.
ProcessView$restart()
ProcessView$action_cancel_process()Cancel action.
ProcessView$action_cancel_process()
ProcessView$action_restart_process()Restart action.
ProcessView$action_restart_process()
ProcessView$clone()The objects of this class are cloneable with this method.
ProcessView$clone(deep = FALSE)
deepWhether to make a deep clone.
A bar filling as value goes from 0 to total, with a percentage. Set
value = NA for an indeterminate (animated) bar.
progress_bar( value = 0, total = 1, show_percent = TRUE, id = NULL, classes = NULL, style = NULL )progress_bar( value = 0, total = 1, show_percent = TRUE, id = NULL, classes = NULL, style = NULL )
value |
Current progress, or |
total |
Value that means complete. |
show_percent |
Show the percentage? |
id |
Optional identifier. |
classes |
Optional classes. |
style |
A |
A ProgressBar with a reactive value and method advance().
render_widget(progress_bar(0.42), 20, 1)render_widget(progress_bar(0.42), 20, 1)
See progress_bar().
Widget -> ProgressBar
paint_statesProgress changes only repaint.
totalThe value that means 100%.
show_percentShow the percentage?
valueProgress between 0 and total, or NA (reactive).
fractionProgress as a fraction (NA when indeterminate).
Widget$add_class()Widget$ancestors()Widget$animate()Widget$arrange_children()Widget$bind()Widget$bind_reactive()Widget$bindings()Widget$blur()Widget$capture_mouse()Widget$child_clip()Widget$clear()Widget$computed_style()Widget$content_height()Widget$default_bindings()Widget$focus()Widget$format()Widget$get_state()Widget$has_class()Widget$invalidate()Widget$invalidate_paint()Widget$is_displayed()Widget$is_enabled()Widget$layout_descend()Widget$layout_differs()Widget$matches()Widget$mount()Widget$on()Widget$paint()Widget$post_message()Widget$print()Widget$pseudo_states()Widget$query()Widget$query_one()Widget$refresh()Widget$release_mouse()Widget$remove()Widget$remove_children()Widget$remove_class()Widget$render()Widget$replace()Widget$run_action()Widget$run_process()Widget$run_worker()Widget$set()Widget$set_interval()Widget$set_state()Widget$set_timeout()Widget$toggle_class()Widget$walk()ProgressBar$new()Create a progress bar. See progress_bar().
ProgressBar$new( value = 0, total = 1, show_percent = TRUE, id = NULL, classes = NULL, style = NULL )
valueProgress (or NA for indeterminate).
totalTotal.
show_percentShow the percentage?
id, classes, styleSee Widget.
ProgressBar$default_style()The built-in style.
ProgressBar$default_style()
ProgressBar$on_mount()Animate the indeterminate state.
ProgressBar$on_mount(event)
eventA MountEvent.
ProgressBar$advance()Advance the progress.
ProgressBar$advance(amount = 1)
amountAmount to add.
ProgressBar$render_lines()The bar for a given width.
ProgressBar$render_lines(width = NA_integer_)
widthContent width.
ProgressBar$content_width()Natural width.
ProgressBar$content_width()
ProgressBar$clone()The objects of this class are cloneable with this method.
ProgressBar$clone(deep = FALSE)
deepWhether to make a deep clone.
Displays named list/vector entries in two aligned columns. Keys are sized
to their longest name up to max_key_width; values wrap and the view
scrolls when needed. NULL, NA, dates and vectors have compact default
formatting. Lists and other objects are shown as placeholders instead of
being recursively printed. A custom formatter(name, value) can replace
the default value formatting. data may be a reactive function of no
arguments.
property_grid( data = list(), format = NULL, max_key_width = 20L, id = NULL, classes = NULL, style = NULL, disabled = FALSE )property_grid( data = list(), format = NULL, max_key_width = 20L, id = NULL, classes = NULL, style = NULL, disabled = FALSE )
data |
Named list or vector; data frames are accepted as named
columns. |
format |
Optional |
max_key_width |
Maximum key column width in terminal cells. |
id |
Optional identifier. |
classes |
Optional classes. |
style |
A |
disabled |
Disable focus and scrolling interaction? |
A PropertyGrid (a focusable, scrollable widget) with reactive
$data and $set_data().
key_value(): a few known values shown in full, such as a summary
panel. Not focusable, does not scroll; values are not wrapped.
property_grid(): an inspector for many or arbitrary named values.
Focusable and scrollable, wraps long values, formats vectors and lists
compactly and accepts a format function.
record_view(): property_grid() for exactly one record, such as the
selected row of a data_table(); accepts a one-row data frame.
property_grid(list(type = "numeric", missing = 12, unique = 345))property_grid(list(type = "numeric", missing = 12, unique = 345))
See property_grid().
Widget -> ScrollView -> PropertyGrid
max_key_widthMaximum key width in terminal cells.
formatterOptional function(name, value).
dataThe current named data (reactive).
Widget$add_class()Widget$ancestors()Widget$animate()Widget$bind()Widget$bind_reactive()Widget$bindings()Widget$blur()Widget$capture_mouse()Widget$clear()Widget$computed_style()Widget$content_height()Widget$content_width()Widget$focus()Widget$format()Widget$get_state()Widget$has_class()Widget$invalidate()Widget$invalidate_paint()Widget$is_displayed()Widget$is_enabled()Widget$layout_differs()Widget$matches()Widget$mount()Widget$on()Widget$post_message()Widget$print()Widget$pseudo_states()Widget$query()Widget$query_one()Widget$refresh()Widget$release_mouse()Widget$remove()Widget$remove_children()Widget$remove_class()Widget$render()Widget$render_lines()Widget$replace()Widget$run_action()Widget$run_process()Widget$run_worker()Widget$set()Widget$set_interval()Widget$set_state()Widget$set_timeout()Widget$toggle_class()Widget$walk()ScrollView$action_page_down()ScrollView$action_page_up()ScrollView$action_scroll_down()ScrollView$action_scroll_end()ScrollView$action_scroll_home()ScrollView$action_scroll_left()ScrollView$action_scroll_right()ScrollView$action_scroll_up()ScrollView$arrange_children()ScrollView$child_clip()ScrollView$default_bindings()ScrollView$layout_descend()ScrollView$on_mouse_scroll()ScrollView$paint()ScrollView$scroll_by()ScrollView$scroll_end()ScrollView$scroll_home()ScrollView$scroll_into_view()ScrollView$scroll_to()PropertyGrid$new()Create a property grid. See property_grid().
PropertyGrid$new( data = list(), formatter = NULL, max_key_width = 20L, id = NULL, classes = NULL, style = NULL, disabled = FALSE )
dataNamed list/vector or data frame.
formatterOptional value formatter.
max_key_widthMaximum key width.
id, classes, style, disabledSee property_grid().
PropertyGrid$default_style()The built-in scrollable style.
PropertyGrid$default_style()
PropertyGrid$set_data()Replace all rows.
PropertyGrid$set_data(data)
dataNew named data.
PropertyGrid$clone()The objects of this class are cloneable with this method.
PropertyGrid$clone(deep = FALSE)
deepWhether to make a deep clone.
Returns a viewport-first tokenizer for text_area(). It highlights common
R keywords, strings, comments, numeric constants, operators, and function
names. It uses tolerant regular expressions and accepts incomplete syntax.
Each line produces grapheme-indexed spans with start, end, and token.
r_highlighter()r_highlighter()
A function (lines, state = NULL) suitable for text_area().
radio_set() groups radio_button()s so that one can be selected.
Space, Enter or a click selects an option; Up/Down move between options.
Changes send "radio_set.changed" (event$data: value, index,
label) from the set.
radio_set(..., selected = NULL, id = NULL, classes = NULL, style = NULL) radio_button(label, value = label, id = NULL, disabled = FALSE)radio_set(..., selected = NULL, id = NULL, classes = NULL, style = NULL) radio_button(label, value = label, id = NULL, disabled = FALSE)
... |
|
selected |
Value selected initially. |
id |
Optional identifier. |
classes |
Optional classes. |
style |
A |
label |
Label of the option. |
value |
Value of the option (defaults to the label). |
disabled |
Can the option be selected? |
A RadioSet widget with a value field.
radio_set(radio_button("CSV", "csv"), radio_button("JSON", "json"), selected = "csv")radio_set(radio_button("CSV", "csv"), radio_button("JSON", "json"), selected = "csv")
One option of a radio_set().
Widget -> RadioButton
focusableRadio buttons can be focused.
valueThe value this option stands for.
selectedIs this option selected? (read-only; use the set)
labelThe label (reactive).
Widget$add_class()Widget$ancestors()Widget$animate()Widget$arrange_children()Widget$bind()Widget$bind_reactive()Widget$bindings()Widget$blur()Widget$capture_mouse()Widget$child_clip()Widget$clear()Widget$computed_style()Widget$content_height()Widget$content_width()Widget$focus()Widget$format()Widget$get_state()Widget$has_class()Widget$invalidate()Widget$invalidate_paint()Widget$is_displayed()Widget$is_enabled()Widget$layout_descend()Widget$layout_differs()Widget$matches()Widget$mount()Widget$on()Widget$paint()Widget$post_message()Widget$print()Widget$pseudo_states()Widget$query()Widget$query_one()Widget$refresh()Widget$release_mouse()Widget$remove()Widget$remove_children()Widget$remove_class()Widget$render_lines()Widget$replace()Widget$run_action()Widget$run_process()Widget$run_worker()Widget$set()Widget$set_interval()Widget$set_state()Widget$set_timeout()Widget$toggle_class()Widget$walk()RadioButton$new()Create a radio button. See radio_button().
RadioButton$new( label, value = label, id = NULL, classes = NULL, style = NULL, disabled = FALSE )
labelLabel.
valueValue.
id, classes, style, disabledSee Widget.
RadioButton$default_style()The built-in style.
RadioButton$default_style()
RadioButton$default_bindings()Space and Enter select the option.
RadioButton$default_bindings()
RadioButton$action_choose()Select this option in its radio set.
RadioButton$action_choose()
RadioButton$on_click()Clicking selects.
RadioButton$on_click(event)
eventA MouseEvent.
RadioButton$render()The dot and the label.
RadioButton$render()
RadioButton$clone()The objects of this class are cloneable with this method.
RadioButton$clone(deep = FALSE)
deepWhether to make a deep clone.
A group of radio buttons. See radio_set().
Widget -> Vertical -> RadioSet
valueThe selected value (NULL if none); assign to select.
Widget$add_class()Widget$ancestors()Widget$animate()Widget$arrange_children()Widget$bind()Widget$bind_reactive()Widget$bindings()Widget$blur()Widget$capture_mouse()Widget$child_clip()Widget$clear()Widget$computed_style()Widget$content_height()Widget$content_width()Widget$focus()Widget$format()Widget$get_state()Widget$has_class()Widget$invalidate()Widget$invalidate_paint()Widget$is_displayed()Widget$is_enabled()Widget$layout_descend()Widget$layout_differs()Widget$matches()Widget$mount()Widget$on()Widget$paint()Widget$post_message()Widget$print()Widget$pseudo_states()Widget$query()Widget$query_one()Widget$refresh()Widget$release_mouse()Widget$remove()Widget$remove_children()Widget$remove_class()Widget$render()Widget$render_lines()Widget$replace()Widget$run_action()Widget$run_process()Widget$run_worker()Widget$set()Widget$set_interval()Widget$set_state()Widget$set_timeout()Widget$toggle_class()Widget$walk()RadioSet$new()Create a radio set. See radio_set().
RadioSet$new( ..., selected = NULL, id = NULL, classes = NULL, style = NULL, disabled = FALSE )
...Radio buttons.
selectedValue to select initially.
id, classes, style, disabledSee Widget.
RadioSet$default_style()The built-in style.
RadioSet$default_style()
RadioSet$default_bindings()Up/Down move to the previous / next option and select it.
RadioSet$default_bindings()
RadioSet$select()Select an option (sends "radio_set.changed").
RadioSet$select(button)
buttonA child radio button.
RadioSet$action_next_option()Move to the next option.
RadioSet$action_next_option()
RadioSet$action_previous_option()Move to the previous option.
RadioSet$action_previous_option()
RadioSet$clone()The objects of this class are cloneable with this method.
RadioSet$clone(deep = FALSE)
deepWhether to make a deep clone.
reactive() declares a state field of a custom widget (see
widget()). Reading the field returns its value; assigning a different
value (self$count <- self$count + 1L) invalidates the widget and
schedules a repaint. Repaints are batched: any number of assignments in
one event-loop tick produce a single render and a single screen diff.
reactive(value = NULL, watch = NULL)reactive(value = NULL, watch = NULL)
value |
Initial value. |
watch |
Optional |
An object of class termr_reactive.
reactive(0L) reactive("", watch = function(self, value, old) message("now ", value))reactive(0L) reactive("", watch = function(self, value, old) message("now ", value))
record_view() accepts a named list/vector or exactly one data-frame row
and presents it through the same renderer as property_grid(). It is a
semantic convenience wrapper, not a separate rendering system. A reactive
function may return a new record whenever its signals change.
record_view( data, format = NULL, max_key_width = 20L, id = NULL, classes = NULL, style = NULL, disabled = FALSE )record_view( data, format = NULL, max_key_width = 20L, id = NULL, classes = NULL, style = NULL, disabled = FALSE )
data |
One named list, named vector, or one-row data frame. |
format |
Optional |
max_key_width |
Maximum key column width. |
id |
Optional identifier. |
classes |
Optional classes. |
style |
A |
disabled |
Disable focus and scrolling interaction? |
A PropertyGrid widget.
key_value(): a few known values shown in full, such as a summary
panel. Not focusable, does not scroll; values are not wrapped.
property_grid(): an inspector for many or arbitrary named values.
Focusable and scrollable, wraps long values, formats vectors and lists
compactly and accepts a format function.
record_view(): property_grid() for exactly one record, such as the
selected row of a data_table(); accepts a one-row data frame.
record_view(list(id = 42, name = "Alice", active = TRUE))record_view(list(id = 42, name = "Alice", active = TRUE))
A region (rectangle) describes a region of the terminal in cells. Coordinates are
1-based, like R indices and ANSI cursor positions: x is the column and
y is the row of the top-left cell.
region(x = 1L, y = 1L, width = 0L, height = 0L)region(x = 1L, y = 1L, width = 0L, height = 0L)
x, y
|
Column and row of the top-left cell. |
width, height
|
Size in cells. Negative sizes are clamped to zero. |
Rectangles are plain values (lists with class termr_rect), so they can
be compared with identical() and are cheap to create during layout.
An object of class termr_rect.
r <- region(1, 1, 40, 5) rr <- region(1, 1, 40, 5) r
A registered name can be used as layout in style(). Custom names start
with custom_ to keep built-in names reserved.
register_layout(name, arrange, measure, replace = FALSE)register_layout(name, arrange, measure, replace = FALSE)
name |
A unique |
arrange |
|
measure |
|
replace |
Replace an existing registration of |
The registered name, invisibly.
Render a styled HTML fragment
render_html(x, width = 80, height = 24, color = TRUE, trim = TRUE)render_html(x, width = 80, height = 24, color = TRUE, trim = TRUE)
x |
A widget, Screen, App, or ScreenBuffer. |
width, height
|
Frame size in cells. |
color |
Include framebuffer colours even when |
trim |
Remove trailing spaces from each line? |
An embeddable <pre> fragment. Styling is approximate and depends
on the browser's monospace font and CSS environment.
cat(render_html(label("Ready", style = style(foreground = "green", bold = TRUE))))cat(render_html(label("Ready", style = style(foreground = "green", bold = TRUE))))
Render a terminal frame as a Markdown code block
render_markdown(x, width = 80, height = 24, trim = TRUE)render_markdown(x, width = 80, height = 24, trim = TRUE)
x |
A widget, Screen, App, or ScreenBuffer. |
width, height
|
Frame size in cells. |
trim |
Remove trailing spaces from each line? |
A fenced Markdown text block.
cat(render_markdown(label("Hello"), width = 20, height = 2))cat(render_markdown(label("Hello"), width = 20, height = 2))
Render a static frame as SVG
render_svg( x, width = 80, height = 24, cell_width = 9, line_height = 18, font_family = "monospace", color = TRUE )render_svg( x, width = 80, height = 24, cell_width = 9, line_height = 18, font_family = "monospace", color = TRUE )
x |
A widget, Screen, App, or ScreenBuffer. |
width, height
|
Frame size in cells. |
cell_width |
Width of a terminal cell in SVG user units. |
line_height |
Height of a row in SVG user units. |
font_family |
CSS font family. |
color |
Include framebuffer colours? |
An SVG document string.
Static renderers use the normal layout and paint pipeline and do not start an event loop or write to a terminal.
render_text(x, width = 80, height = 24, trim = TRUE) render_lines(x, width = 80, height = 24, trim = TRUE)render_text(x, width = 80, height = 24, trim = TRUE) render_lines(x, width = 80, height = 24, trim = TRUE)
x |
A widget, Screen, App, or ScreenBuffer. |
width, height
|
Frame size in cells. |
trim |
Remove trailing spaces from each line? |
render_text() returns one string separated by newlines;
render_lines() returns one string per row.
render_text(panel(label("Finished"), title = "Job"), width = 20, height = 5)render_text(panel(label("Finished"), title = "Job"), width = 20, height = 5)
Lays out and paints a widget tree into a ScreenBuffer without a terminal. Useful for snapshot tests and for checking layouts interactively.
render_widget(x, width = 80L, height = 24L)render_widget(x, width = 80L, height = 24L)
x |
|
width, height
|
Screen size in cells. |
A ScreenBuffer; use $to_text() for plain text.
buf <- render_widget(vertical(label("a"), label("b")), 10, 2) buf$to_text()buf <- render_widget(vertical(label("a"), label("b")), 10, 2) buf$to_text()
A horizontal or vertical line, optionally with a title.
rule( orientation = "horizontal", title = NULL, id = NULL, classes = NULL, style = NULL )rule( orientation = "horizontal", title = NULL, id = NULL, classes = NULL, style = NULL )
orientation |
|
title |
Optional title for horizontal rules. |
id |
Optional identifier. |
classes |
Optional classes. |
style |
A |
A Rule widget.
render_widget(rule(title = "Results"), 20, 1)render_widget(rule(title = "Results"), 20, 1)
See rule().
Widget -> Rule
orientation"horizontal" or "vertical".
titleOptional title in the middle of a horizontal rule.
Widget$add_class()Widget$ancestors()Widget$animate()Widget$arrange_children()Widget$bind()Widget$bind_reactive()Widget$bindings()Widget$blur()Widget$capture_mouse()Widget$child_clip()Widget$clear()Widget$computed_style()Widget$content_height()Widget$content_width()Widget$default_bindings()Widget$focus()Widget$format()Widget$get_state()Widget$has_class()Widget$invalidate()Widget$invalidate_paint()Widget$is_displayed()Widget$is_enabled()Widget$layout_descend()Widget$layout_differs()Widget$matches()Widget$mount()Widget$on()Widget$post_message()Widget$print()Widget$pseudo_states()Widget$query()Widget$query_one()Widget$refresh()Widget$release_mouse()Widget$remove()Widget$remove_children()Widget$remove_class()Widget$render()Widget$render_lines()Widget$replace()Widget$run_action()Widget$run_process()Widget$run_worker()Widget$set()Widget$set_interval()Widget$set_state()Widget$set_timeout()Widget$toggle_class()Widget$walk()Rule$new()Create a rule. See rule().
Rule$new( orientation = "horizontal", title = NULL, id = NULL, classes = NULL, style = NULL )
orientationOrientation.
titleTitle.
id, classes, styleSee Widget.
Rule$default_style()The built-in style.
Rule$default_style()
Rule$paint()Paint the line.
Rule$paint(buffer, area, st)
bufferA ScreenBuffer.
areaVisible part of the region.
stComputed style.
Rule$clone()The objects of this class are cloneable with this method.
Rule$clone(deep = FALSE)
deepWhether to make a deep clone.
Takes over the terminal (alternate screen, raw keyboard input), runs the
event loop until the app calls exit(), and restores the terminal -
also when an error occurs or the user interrupts R.
run(x, ...)run(x, ...)
x |
|
... |
Passed to |
When the app stops, its timers, widget timers, workers and animations are
cancelled. The same app can be run again, but timers and workers have to
be started again (for example from a "mount" handler).
termr apps need a real terminal: run them with Rscript (or an
interactive R session) in a terminal such as Windows Terminal,
iTerm2 or GNOME Terminal. RStudio's console is not a terminal.
The value passed to app$exit(), invisibly.
Run a bundled example app
run_example(name = NULL)run_example(name = NULL)
name |
Example name. Call |
The example names (invisibly when an example was run).
run_example()run_example()
app$run_worker() runs a function in a separate R process and reports
back through events and callbacks, so the interface stays responsive
during long computations (model fitting, downloads, file processing).
app$run_process() does the same for an external program.
run_worker( fn, args = list(), on_complete = NULL, on_error = NULL, on_progress = NULL, name = NULL, owner = NULL, packages = character(), inline = FALSE, on_stdout = NULL, on_stderr = NULL, timeout = NULL, app = current_app() ) run_process( command, args = character(), on_complete = NULL, on_error = NULL, on_stdout = NULL, on_stderr = NULL, on_exit = NULL, timeout = NULL, wd = NULL, env = NULL, name = NULL, owner = NULL, app = current_app() )run_worker( fn, args = list(), on_complete = NULL, on_error = NULL, on_progress = NULL, name = NULL, owner = NULL, packages = character(), inline = FALSE, on_stdout = NULL, on_stderr = NULL, timeout = NULL, app = current_app() ) run_process( command, args = character(), on_complete = NULL, on_error = NULL, on_stdout = NULL, on_stderr = NULL, on_exit = NULL, timeout = NULL, wd = NULL, env = NULL, name = NULL, owner = NULL, app = current_app() )
fn |
The function to run. |
args |
A list of arguments. |
on_complete |
|
on_error |
|
on_progress |
|
name |
Name of the worker. |
owner |
A widget owning the worker (events come from it, and it is cancelled when the widget is removed). |
packages |
Packages to attach in the worker process. |
inline |
Run in this process instead (for tests). |
on_stdout, on_stderr
|
|
timeout |
Seconds after which the worker is stopped and fails
( |
app |
The app (defaults to the running app). |
command |
The program to run (a path or a name found on the |
on_exit |
|
wd |
Working directory ( |
env |
Named character vector of extra environment variables. |
The function runs in a fresh R session (Rscript --vanilla), so it cannot
directly access the caller's global environment. Lexical values referenced
by the function are captured by value in a small environment; unrelated
bindings in the enclosing environment are omitted. For example, a function
using a local scalar binding works without serializing other locals.
Referenced nested and recursive helper functions are captured too.
Dynamic lexical lookup (get(), eval() or parent.frame()) and active
bindings are rejected; pass those values explicitly through args. Prefer
args for large data and list required packages in packages. Inside the function,
termr_progress(value, message) reports progress on a channel of its
own, so anything the function prints to stdout or stderr is free for
on_stdout / on_stderr (message() goes to stderr).
The child receives the parent's library search paths, and R_TESTS is
cleared so a check-session startup hook cannot rerun the test suite.
run_process(command, args) starts a program without a shell: the
command and its arguments are separate, so nothing is interpolated or
interpreted. (To use a shell on purpose, run it yourself:
run_process("sh", c("-c", script)).) It completes with the exit status
as result; a non-zero status counts as failure.
Events (from the owner widget, or the screen), with event$data$worker:
"worker.started", "worker.progress" (value, message),
"worker.stdout" / "worker.stderr" (line), "worker.completed"
(result), "worker.failed" (error, timed_out, status),
"worker.cancelled". Output lines are stripped of control characters;
at most 200 lines are delivered per event-loop tick.
Workers stop when cancel() is called, when their owner widget is
removed, when timeout seconds have passed, and when the app exits. A
stopping worker is interrupted first (Unix) and killed, with its child
processes, if it does not end within a short grace period.
Temporary files (the job, the result and the progress file) have unique names and are removed when the worker ends, however it ends.
The job (the function with its referenced lexical bindings, and args) is
serialized to a temporary file. Explicitly referenced objects and values in
args are still serialized. Workers and programs inherit the app's
environment variables: avoid putting secrets into worker closures or
arguments unnecessarily.
There is no worker pool: start as many workers as you need; each is an independent process. This API is experimental.
A Worker handle with cancel(), state, result, error,
stdout and stderr.
inline = TRUE runs the function in the current R process at once
(blocking), which makes tests fast and deterministic. With real
processes, pilot$wait_for_workers() waits until they finish.
pilot <- test_app(app(label("Jobs")), width = 30, height = 1) # `inline = TRUE` runs the job in this process; without it, the same call # starts a background R process, where `termr_progress()` is available. pilot$app$run_worker( function(n) sum(seq_len(n)), args = list(n = 20), inline = TRUE, on_complete = function(result, app) message("result: ", result) ) pilot$step() pilot$stop()pilot <- test_app(app(label("Jobs")), width = 30, height = 1) # `inline = TRUE` runs the job in this process; without it, the same call # starts a background R process, where `termr_progress()` is available. pilot$app$run_worker( function(n) sum(seq_len(n)), args = list(n = 20), inline = TRUE, on_complete = function(result, app) message("result: ", result) ) pilot$step() pilot$stop()
The root of a widget tree. An App shows one screen at a time; the screen always fills the terminal. Bindings on the screen apply to every widget in it.
Widget -> Screen
Widget$add_class()Widget$ancestors()Widget$animate()Widget$arrange_children()Widget$bind()Widget$bind_reactive()Widget$bindings()Widget$blur()Widget$capture_mouse()Widget$child_clip()Widget$clear()Widget$computed_style()Widget$content_height()Widget$content_width()Widget$default_bindings()Widget$focus()Widget$format()Widget$get_state()Widget$has_class()Widget$initialize()Widget$invalidate()Widget$invalidate_paint()Widget$is_displayed()Widget$is_enabled()Widget$layout_descend()Widget$layout_differs()Widget$matches()Widget$mount()Widget$on()Widget$paint()Widget$post_message()Widget$print()Widget$pseudo_states()Widget$query()Widget$query_one()Widget$refresh()Widget$release_mouse()Widget$remove()Widget$remove_children()Widget$remove_class()Widget$render()Widget$render_lines()Widget$replace()Widget$run_action()Widget$run_process()Widget$run_worker()Widget$set()Widget$set_interval()Widget$set_state()Widget$set_timeout()Widget$toggle_class()Widget$walk()Screen$default_style()The built-in style.
Screen$default_style()
Screen$clone()The objects of this class are cloneable with this method.
Screen$clone(deep = FALSE)
deepWhether to make a deep clone.
Create a virtual screen buffer
screen_buffer(width, height)screen_buffer(width, height)
width, height
|
Size in cells. |
A ScreenBuffer.
buf <- screen_buffer(10, 2) buf$put_text(2, 1, "hello", fg = "red") buf$to_text()buf <- screen_buffer(10, 2) buf$put_text(2, 1, "hello", fg = "red") buf$to_text()
The returned base R list is independent of jsonlite and has a stable
schema_version field. Runs are row-major and represent adjacent cells
with the same foreground, background, and attribute mask.
screen_snapshot(x, width = 80, height = 24)screen_snapshot(x, width = 80, height = 24)
x |
A widget, Screen, App, or ScreenBuffer. |
width, height
|
Frame size in cells. |
A termr_screen_snapshot list.
screen_snapshot(label("Hello"), width = 20, height = 2)screen_snapshot(label("Hello"), width = 20, height = 2)
The JSON form of screen_snapshot(). Requires the optional jsonlite
package.
screen_snapshot_json(x, width = 80, height = 24, pretty = TRUE)screen_snapshot_json(x, width = 80, height = 24, pretty = TRUE)
x |
A widget, Screen, App, or ScreenBuffer. |
width, height
|
Frame size in cells. |
pretty |
Format the JSON for readability? |
A JSON string.
A ScreenBuffer is an in-memory grid of terminal cells. Widgets are
painted into a buffer, buffers are compared with diff_screen() and only
the differences are sent to the terminal.
Cells are stored in four height x width matrices (chars, fg, bg,
attrs) indexed as [row, column]. A wide character occupies two
columns: the first holds the character, the second holds "" (a
continuation cell). All writes keep this invariant, so a wide character
is never left half-overwritten.
Use screen_buffer() to create one.
widthNumber of columns.
heightNumber of rows.
charsCharacter matrix of cell contents.
fgCharacter matrix of canonical foreground colours.
bgCharacter matrix of canonical background colours.
attrsInteger matrix of attribute bit masks.
ScreenBuffer$new()Create a blank buffer.
ScreenBuffer$new(width, height)
width, heightSize in cells.
ScreenBuffer$clear()Reset every cell to a blank default cell.
ScreenBuffer$clear()
ScreenBuffer$bounds()The full-buffer rectangle.
ScreenBuffer$bounds()
ScreenBuffer$get_cell()Read one cell.
ScreenBuffer$get_cell(x, y)
x, yColumn and row.
ScreenBuffer$set_cell()Write one cell (see cell()).
ScreenBuffer$set_cell(x, y, cell)
x, yColumn and row.
cellA termr_cell.
ScreenBuffer$fill()Fill a region with one character and style.
ScreenBuffer$fill(region = NULL, char = " ", fg = NULL, bg = NULL, attrs = 0L)
ScreenBuffer$paint_background()Set only the background colour of a region.
ScreenBuffer$paint_background(region, bg)
regionA region().
bgColour.
ScreenBuffer$put_text()Write a single line of text.
Text is clipped to clip (and to the buffer). A wide character that
would straddle the clip edge is replaced by a space. Control
characters are removed.
ScreenBuffer$put_text( x, y, text, fg = NULL, bg = NULL, attrs = 0L, clip = NULL )
x, yColumn and row of the first character.
textA single string (no newlines).
fgForeground colour.
bgBackground colour. NULL keeps the existing background,
so text can be drawn over a painted widget background.
attrsAttribute bit mask.
clipOptional clipping region().
The column after the last character, invisibly.
ScreenBuffer$resize()Change the buffer size, keeping the top-left content.
ScreenBuffer$resize(width, height)
width, heightNew size.
ScreenBuffer$copy()An independent copy of the buffer.
ScreenBuffer$copy()
ScreenBuffer$equals()Do two buffers hold exactly the same cells?
ScreenBuffer$equals(other)
otherAnother ScreenBuffer.
ScreenBuffer$to_text()The buffer as plain text, one string per row.
ScreenBuffer$to_text()
ScreenBuffer$print()Print the buffer contents framed by a border.
ScreenBuffer$print(...)
...Ignored.
ScreenBuffer$clone()The objects of this class are cloneable with this method.
ScreenBuffer$clone(deep = FALSE)
deepWhether to make a deep clone.
Shows content that is larger than the available space. The content is laid out at its natural size and the visible part (the viewport) is shifted by the scroll offsets; everything outside is clipped. Scroll bars appear when the content overflows.
scroll_view( ..., direction = "vertical", scrollbars = TRUE, focusable = TRUE, id = NULL, classes = NULL, style = NULL )scroll_view( ..., direction = "vertical", scrollbars = TRUE, focusable = TRUE, id = NULL, classes = NULL, style = NULL )
... |
Child widgets. |
direction |
|
scrollbars |
Draw scroll bars when the content overflows? |
focusable |
Can the scroll view take focus itself? |
id |
Optional identifier. |
classes |
Optional classes. |
style |
A |
Keys (when the scroll view or an unfocusable descendant has focus, or a
focused child does not use the key itself): arrows scroll by one cell,
Page Up / Page Down by a page, Home / End to the start / end. When focus
moves to a widget inside a scroll view, the view scrolls to reveal it.
Offset changes send a "scroll.changed" message.
A ScrollView widget with methods scroll_to(x, y),
scroll_by(dx, dy), scroll_home(), scroll_end() and
scroll_into_view(widget), and fields offset_x, offset_y,
viewport, virtual_size and max_scroll.
items <- lapply(1:100, function(i) label(paste("Item", i))) view <- scroll_view(items, id = "list") view$scroll_to(y = 50)items <- lapply(1:100, function(i) label(paste("Item", i))) view <- scroll_view(items, id = "list") view$scroll_to(y = 50)
A container whose content can be larger than the widget.
See scroll_view().
Widget -> ScrollView
focusableScroll views can take focus so they can be scrolled with the keyboard even without focusable children.
direction"vertical", "horizontal" or "both".
scrollbarsDraw scroll bars when the content overflows?
offset_x, offset_yScroll offsets in cells (reactive).
viewportThe visible content rectangle (after the last layout).
virtual_sizeSize of the scrollable content: c(width, height).
max_scrollLargest offsets: c(x, y).
Widget$add_class()Widget$ancestors()Widget$animate()Widget$bind()Widget$bind_reactive()Widget$bindings()Widget$blur()Widget$capture_mouse()Widget$clear()Widget$computed_style()Widget$content_height()Widget$content_width()Widget$focus()Widget$format()Widget$get_state()Widget$has_class()Widget$invalidate()Widget$invalidate_paint()Widget$is_displayed()Widget$is_enabled()Widget$layout_differs()Widget$matches()Widget$mount()Widget$on()Widget$post_message()Widget$print()Widget$pseudo_states()Widget$query()Widget$query_one()Widget$refresh()Widget$release_mouse()Widget$remove()Widget$remove_children()Widget$remove_class()Widget$render()Widget$render_lines()Widget$replace()Widget$run_action()Widget$run_process()Widget$run_worker()Widget$set()Widget$set_interval()Widget$set_state()Widget$set_timeout()Widget$toggle_class()Widget$walk()ScrollView$new()Create a scroll view. See scroll_view().
ScrollView$new( ..., direction = "vertical", scrollbars = TRUE, focusable = TRUE, id = NULL, classes = NULL, style = NULL, disabled = FALSE )
...Child widgets.
directionScroll direction.
scrollbarsShow scroll bars?
focusableCan the scroll view itself be focused?
id, classes, style, disabledSee Widget.
ScrollView$default_style()The built-in style.
ScrollView$default_style()
ScrollView$default_bindings()Arrow keys, Page Up/Down and Home/End scroll.
ScrollView$default_bindings()
ScrollView$scroll_to()Scroll to an absolute position (in cells). Positions are clamped to the scrollable range at the next layout.
ScrollView$scroll_to(x = NULL, y = NULL)
x, yNew offsets; NULL keeps the current one.
ScrollView$scroll_by()Scroll relative to the current position.
ScrollView$scroll_by(dx = 0L, dy = 0L)
dx, dyCells to scroll (negative: up/left).
ScrollView$scroll_home()Scroll to the top (and left).
ScrollView$scroll_home()
ScrollView$scroll_end()Scroll to the bottom.
ScrollView$scroll_end()
ScrollView$scroll_into_view()Scroll so that a descendant is fully visible (as far as possible). Uses the last layout; the app re-lays out afterwards.
ScrollView$scroll_into_view(widget)
widgetA descendant widget.
TRUE if the offsets changed.
ScrollView$on_mouse_scroll()The mouse wheel scrolls by three lines. When the view cannot scroll further, the event bubbles to outer scroll views.
ScrollView$on_mouse_scroll(event)
eventA MouseEvent.
ScrollView$action_scroll_up()Scroll one line up.
ScrollView$action_scroll_up()
ScrollView$action_scroll_down()Scroll one line down.
ScrollView$action_scroll_down()
ScrollView$action_scroll_left()Scroll one column left.
ScrollView$action_scroll_left()
ScrollView$action_scroll_right()Scroll one column right.
ScrollView$action_scroll_right()
ScrollView$action_page_up()Scroll one page up.
ScrollView$action_page_up()
ScrollView$action_page_down()Scroll one page down.
ScrollView$action_page_down()
ScrollView$action_scroll_home()Scroll to the top.
ScrollView$action_scroll_home()
ScrollView$action_scroll_end()Scroll to the bottom.
ScrollView$action_scroll_end()
ScrollView$arrange_children()Lay the children out in a virtual area, shifted by the scroll offsets; reserves space for scroll bars when needed.
ScrollView$arrange_children(children, inner, st)
childrenVisible children.
innerContent rectangle.
stComputed style.
ScrollView$layout_descend()Children entirely outside the viewport are not laid out in detail (unless a complete layout is needed, e.g. to scroll a focused widget into view).
ScrollView$layout_descend(rects)
rectsChild rectangles.
ScrollView$child_clip()Children are clipped to the viewport.
ScrollView$child_clip(st)
stComputed style.
ScrollView$paint()Paint background, border and scroll bars.
ScrollView$paint(buffer, area, st)
bufferA ScreenBuffer.
areaVisible part of the region.
stComputed style.
ScrollView$clone()The objects of this class are cloneable with this method.
ScrollView$clone(deep = FALSE)
deepWhether to make a deep clone.
A drop-down choice. See dropdown().
Widget -> Select
focusableSelects can be focused.
promptText shown when nothing is selected.
valueThe selected value or NULL (reactive; sends
"dropdown.changed").
choicesThe choice values.
Widget$add_class()Widget$ancestors()Widget$animate()Widget$arrange_children()Widget$bind()Widget$bind_reactive()Widget$bindings()Widget$blur()Widget$capture_mouse()Widget$child_clip()Widget$clear()Widget$computed_style()Widget$content_height()Widget$content_width()Widget$focus()Widget$format()Widget$get_state()Widget$has_class()Widget$invalidate()Widget$invalidate_paint()Widget$is_displayed()Widget$is_enabled()Widget$layout_descend()Widget$layout_differs()Widget$matches()Widget$mount()Widget$on()Widget$paint()Widget$post_message()Widget$print()Widget$pseudo_states()Widget$query()Widget$query_one()Widget$refresh()Widget$release_mouse()Widget$remove()Widget$remove_children()Widget$remove_class()Widget$render_lines()Widget$replace()Widget$run_action()Widget$run_process()Widget$run_worker()Widget$set()Widget$set_interval()Widget$set_state()Widget$set_timeout()Widget$toggle_class()Widget$walk()Select$new()Create a select. See dropdown().
Select$new( choices, value = NULL, prompt = "Select", id = NULL, classes = NULL, style = NULL, disabled = FALSE )
choicesChoices.
valueInitial value.
promptPrompt.
id, classes, style, disabledSee Widget.
Select$default_style()The built-in style.
Select$default_style()
Select$default_bindings()Enter, Space and Down open the list.
Select$default_bindings()
Select$open()Open the drop-down list.
Select$open()
Select$action_open()Action used by the bindings.
Select$action_open()
Select$on_click()Clicking opens the list.
Select$on_click(event)
eventA MouseEvent.
Select$render()The selected label and an arrow.
Select$render()
Select$clone()The objects of this class are cloneable with this method.
Select$clone(deep = FALSE)
deepWhether to make a deep clone.
Run a function later (set_timeout()) or repeatedly
(set_interval()). Timers are part of the event loop: callbacks run
between events, never concurrently, and never block the interface.
Widgets have their own widget$set_timeout() / widget$set_interval(),
whose timers are cancelled when the widget is removed.
set_timeout(delay, callback, app = current_app()) set_interval(interval, callback, app = current_app())set_timeout(delay, callback, app = current_app()) set_interval(interval, callback, app = current_app())
delay, interval
|
Seconds. |
callback |
|
app |
The app; defaults to the running app. |
A Timer; call $cancel() to stop it.
clock <- app(label("", id = "clock"), bind("q", "quit")) clock$set_interval(1, function(app) { app$query_one("#clock")$update(format(Sys.time(), "%H:%M:%S")) }) if (interactive()) run(clock)clock <- app(label("", id = "clock"), bind("q", "quit")) clock$set_interval(1, function(app) { app$query_one("#clock")$update(format(Sys.time(), "%H:%M:%S")) }) if (interactive()) run(clock)
A small reactive graph for application state. signal() holds a value,
computed() derives a value from signals (lazily, cached), and watch()
runs code whenever the signals it reads change. Widgets can be created
from functions that read signals - label(function() ...) - and are
re-rendered automatically.
signal(value = NULL, name = NULL) computed(fn, name = NULL) watch(fn, name = NULL) dispose(x) batch(expr) peek(x) untracked(expr) update_signal(x, fn)signal(value = NULL, name = NULL) computed(fn, name = NULL) watch(fn, name = NULL) dispose(x) batch(expr) peek(x) untracked(expr) update_signal(x, fn)
value |
Initial value of a signal. |
name |
Optional graph label used in diagnostics and cycle paths. |
fn |
Function applied to the current value. |
x |
A signal or computed. |
expr |
An expression. |
Read a signal with x(), write it with x(value). Writing the same
value (identical()) does nothing. Collections are replaced as a whole:
items(c(items(), "new")) - changes made inside an object are not
noticed.
computed(fn) re-evaluates only when read after a dependency changed.
A computed that depends on itself raises an error.
watch(fn) runs fn now and again after its dependencies changed, in
creation order. If it writes signals, the watchers depending on them run
afterwards; a loop is stopped with an error. Use dispose() to stop it.
batch(expr) defers watchers until expr is done, so several writes
cause one run. Event handlers of an app run in a batch automatically.
peek(x) reads a signal or computed without creating a dependency;
untracked(expr) does the same for an expression.
Watchers and bound widgets keep their signals' subscriber lists alive;
call dispose() (or remove the widget) when they are no longer needed.
This graph is independent of the widget-level reactive() fields. It is
experimental.
signal() and computed() return functions (classes
termr_signal / termr_computed); watch() returns a handle with a
$dispose() method.
count <- signal(1) double <- computed(function() count() * 2) seen <- c() w <- watch(function() seen <<- c(seen, double())) count(2) batch({ count(3); count(4) }) seen dispose(w)count <- signal(1) double <- computed(function() count() * 2) seen <- c() w <- watch(function() seen <<- c(seen, double())) count(2) batch({ count(3); count(4) }) seen dispose(w)
span() creates a piece of text with its own style. Spans can be
combined with c() and returned from a widget's render function or
passed to label(). Newlines start new lines.
span(x = "", style = NULL, link = NULL) ## S3 method for class 'termr_text' c(...)span(x = "", style = NULL, link = NULL) ## S3 method for class 'termr_text' c(...)
x |
Text. A character vector is joined with newlines. May also be spans, to nest styles. |
style |
A |
link |
Optional link target (a URL or any string). Stored as metadata on the text for widgets that support it; not rendered yet. |
... |
Spans or character strings to combine. |
Spans nest: span(c(span("a"), span("b", s1)), s2) applies s2 to both
pieces, with the inner style taking precedence.
An object of class termr_text.
c(span("Status: "), span("OK", style(foreground = "green", bold = TRUE))) span(c(span("bold "), span("and red", style(foreground = "red"))), style(bold = TRUE))c(span("Status: "), span("OK", style(foreground = "green", bold = TRUE))) span(c(span("bold "), span("and red", style(foreground = "red"))), style(bold = TRUE))
A tiny line chart made of block characters (\u2581 to \u2588), one
column per value. With more values than columns, the latest values are
shown (summary = "tail") or buckets are averaged ("mean"). Missing
values are blank. Use push() to stream values.
sparkline( data = numeric(), min = NULL, max = NULL, summary = "tail", max_length = 1000L, id = NULL, classes = NULL, style = NULL )sparkline( data = numeric(), min = NULL, max = NULL, summary = "tail", max_length = 1000L, id = NULL, classes = NULL, style = NULL )
data |
Numeric vector. |
min, max
|
Fixed scale; |
summary |
|
max_length |
Number of values kept by |
id |
Optional identifier. |
classes |
Optional classes. |
style |
A |
A Sparkline with reactive data and method push().
render_widget(sparkline(c(1, 4, 2, 8, 5, NA, 7)), 7, 1)render_widget(sparkline(c(1, 4, 2, 8, 5, NA, 7)), 7, 1)
See sparkline().
Widget -> Sparkline
min, maxFixed scale limits, or NULL to use the data range.
max_lengthValues kept by push().
summaryHow to fit more values than columns: "tail" (latest
values) or "mean" (average buckets).
dataThe values (reactive).
Widget$add_class()Widget$ancestors()Widget$animate()Widget$arrange_children()Widget$bind()Widget$bind_reactive()Widget$bindings()Widget$blur()Widget$capture_mouse()Widget$child_clip()Widget$clear()Widget$computed_style()Widget$content_height()Widget$default_bindings()Widget$focus()Widget$format()Widget$get_state()Widget$has_class()Widget$invalidate()Widget$invalidate_paint()Widget$is_displayed()Widget$is_enabled()Widget$layout_descend()Widget$layout_differs()Widget$matches()Widget$mount()Widget$on()Widget$paint()Widget$post_message()Widget$print()Widget$pseudo_states()Widget$query()Widget$query_one()Widget$refresh()Widget$release_mouse()Widget$remove()Widget$remove_children()Widget$remove_class()Widget$render()Widget$replace()Widget$run_action()Widget$run_process()Widget$run_worker()Widget$set()Widget$set_interval()Widget$set_state()Widget$set_timeout()Widget$toggle_class()Widget$walk()Sparkline$new()Create a sparkline. See sparkline().
Sparkline$new( data = numeric(), min = NULL, max = NULL, summary = "tail", max_length = 1000L, id = NULL, classes = NULL, style = NULL )
dataNumbers.
min, maxScale limits.
summaryFitting strategy.
max_lengthValues kept by push().
id, classes, styleSee Widget.
Sparkline$default_style()The built-in style.
Sparkline$default_style()
Sparkline$push()Append values (keeping at most max_length).
Sparkline$push(x)
xNumbers.
Sparkline$render_lines()The bars for a given width.
Sparkline$render_lines(width = NA_integer_)
widthContent width.
Sparkline$content_width()Natural width: one column per value.
Sparkline$content_width()
Sparkline$clone()The objects of this class are cloneable with this method.
Sparkline$clone(deep = FALSE)
deepWhether to make a deep clone.
A small animation showing that work is in progress. It runs on a timer of the widget, so it stops automatically when the widget is removed.
spinner( label = "", type = "dots", interval = 0.1, id = NULL, classes = NULL, style = NULL )spinner( label = "", type = "dots", interval = 0.1, id = NULL, classes = NULL, style = NULL )
label |
Text shown after the spinner. |
type |
|
interval |
Seconds per frame. |
id |
Optional identifier. |
classes |
Optional classes. |
style |
A |
A Spinner with reactive label and spinning.
spinner("Loading data...")spinner("Loading data...")
See spinner().
Widget -> Spinner
paint_statesAnimation frames only repaint.
framesAnimation frames.
intervalSeconds per frame.
labelText after the spinner (reactive).
spinningIs it animating? (reactive)
Widget$add_class()Widget$ancestors()Widget$animate()Widget$arrange_children()Widget$bind()Widget$bind_reactive()Widget$bindings()Widget$blur()Widget$capture_mouse()Widget$child_clip()Widget$clear()Widget$computed_style()Widget$content_height()Widget$content_width()Widget$default_bindings()Widget$focus()Widget$format()Widget$get_state()Widget$has_class()Widget$invalidate()Widget$invalidate_paint()Widget$is_displayed()Widget$is_enabled()Widget$layout_descend()Widget$layout_differs()Widget$matches()Widget$mount()Widget$on()Widget$paint()Widget$post_message()Widget$print()Widget$pseudo_states()Widget$query()Widget$query_one()Widget$refresh()Widget$release_mouse()Widget$remove()Widget$remove_children()Widget$remove_class()Widget$render_lines()Widget$replace()Widget$run_action()Widget$run_process()Widget$run_worker()Widget$set()Widget$set_interval()Widget$set_state()Widget$set_timeout()Widget$toggle_class()Widget$walk()Spinner$new()Create a spinner. See spinner().
Spinner$new( label = "", type = "dots", interval = 0.1, id = NULL, classes = NULL, style = NULL )
labelText after the spinner.
typeAnimation name.
intervalSeconds per frame.
id, classes, styleSee Widget.
Spinner$default_style()The built-in style.
Spinner$default_style()
Spinner$on_mount()Start the animation timer.
Spinner$on_mount(event)
eventA MountEvent.
Spinner$render()The current frame and the label.
Spinner$render()
Spinner$clone()The objects of this class are cloneable with this method.
Spinner$clone(deep = FALSE)
deepWhether to make a deep clone.
Two panes separated by a divider the user can drag with the mouse (press on the divider, move, release) or move with the keyboard (focus the divider with Tab; arrows move it, Shift+arrows ten cells, Home / End to the ends). Typical uses: a tree next to a preview, a table above a detail view, an editor above its output.
split_pane( first, second, direction = "horizontal", ratio = 0.5, min_size = 3L, id = NULL, classes = NULL, style = NULL )split_pane( first, second, direction = "horizontal", ratio = 0.5, min_size = 3L, id = NULL, classes = NULL, style = NULL )
first, second
|
The two panes. |
direction |
|
ratio |
Share of the first pane, between 0 and 1. |
min_size |
Smallest pane size in cells. |
id |
Optional identifier. |
classes |
Optional classes. |
style |
A |
The panes fill their share of the space regardless of their own size
styles. ratio is the share of the first pane; min_size keeps both
panes from collapsing. The pane sends "splitpane.resized" (ratio)
when the user finishes moving the divider. Experimental.
A SplitPane widget with $ratio and $sizes.
ui <- split_pane(label("left"), label("right"), ratio = 0.4) render_widget(ui, 20, 2)$to_text()ui <- split_pane(label("left"), label("right"), ratio = 0.4) render_widget(ui, 20, 2)$to_text()
Two panes with a draggable divider. See split_pane().
Widget -> SplitPane
direction"horizontal" (panes side by side) or "vertical"
(stacked).
min_sizeSmallest size of a pane in cells (when there is room).
ratioShare of the first pane (0 to 1). Assigning moves the
divider (limited by min_size).
sizesThe current sizes (cells) of the two panes.
Widget$add_class()Widget$ancestors()Widget$animate()Widget$bind()Widget$bind_reactive()Widget$bindings()Widget$blur()Widget$capture_mouse()Widget$child_clip()Widget$clear()Widget$computed_style()Widget$content_height()Widget$content_width()Widget$default_bindings()Widget$focus()Widget$format()Widget$get_state()Widget$has_class()Widget$invalidate()Widget$invalidate_paint()Widget$is_displayed()Widget$is_enabled()Widget$layout_descend()Widget$layout_differs()Widget$matches()Widget$mount()Widget$on()Widget$paint()Widget$post_message()Widget$print()Widget$pseudo_states()Widget$query()Widget$query_one()Widget$refresh()Widget$release_mouse()Widget$remove()Widget$remove_children()Widget$remove_class()Widget$render()Widget$render_lines()Widget$replace()Widget$run_action()Widget$run_process()Widget$run_worker()Widget$set()Widget$set_interval()Widget$set_state()Widget$set_timeout()Widget$toggle_class()Widget$walk()SplitPane$new()Create a split pane. See split_pane().
SplitPane$new( first, second, direction = "horizontal", ratio = 0.5, min_size = 3L, id = NULL, classes = NULL, style = NULL )
first, secondThe two panes (widgets).
direction, ratio, min_sizeSee split_pane().
id, classes, styleSee Widget.
SplitPane$default_style()The built-in style.
SplitPane$default_style()
SplitPane$arrange_children()Split the content area between the panes and the divider.
SplitPane$arrange_children(children, inner, st)
childrenVisible children.
innerContent rectangle.
stComputed style.
SplitPane$move_divider()Move the divider by some cells.
SplitPane$move_divider(cells)
cellsPositive: towards the second pane.
SplitPane$set_ratio()Set the share of the first pane.
SplitPane$set_ratio(ratio)
ratioA number between 0 and 1.
SplitPane$drag_to()Place the divider under a screen position (drags).
SplitPane$drag_to(x, y)
x, yScreen position.
SplitPane$announce()Send "splitpane.resized" with the current ratio.
SplitPane$announce()
SplitPane$clone()The objects of this class are cloneable with this method.
SplitPane$clone(deep = FALSE)
deepWhether to make a deep clone.
A thin text_area() subclass with SQL highlighting. When connection is
supplied, execute_key runs the selected SQL, or the full buffer if nothing
is selected. Queries run synchronously in the current R process.
sql_editor( value = "", id = NULL, connection = NULL, execute_key = "ctrl+enter", execution = c("query", "execute"), line_numbers = TRUE, tab_size = 2L, ..., result_mode = c("data", "lazy"), query_adapter = NULL )sql_editor( value = "", id = NULL, connection = NULL, execute_key = "ctrl+enter", execution = c("query", "execute"), line_numbers = TRUE, tab_size = 2L, ..., result_mode = c("data", "lazy"), query_adapter = NULL )
value |
Initial SQL text. |
id |
Optional widget id. |
connection |
A |
execute_key |
Key binding used to execute SQL. |
execution |
Either |
line_numbers |
Show line numbers? Defaults to |
tab_size |
Spaces inserted by Tab. |
... |
Additional arguments passed to TextArea. |
result_mode |
Query result mode: "data" materializes the result
(the default); "lazy" returns a |
query_adapter |
Optional backend pager callbacks passed to
|
A TextArea subclass with an execute() method.
A tolerant, line-oriented tokenizer for SQL text areas. dialect is
reserved for small dialect-specific extensions; token classes are shared.
sql_highlighter( dialect = c("generic", "postgres", "sqlite", "mysql", "sqlserver") )sql_highlighter( dialect = c("generic", "postgres", "sqlite", "mysql", "sqlserver") )
dialect |
SQL dialect: |
A highlighter function for text_area().
Displays left, centered and right status text in one terminal row. On a
narrow screen it preserves the left region first, then the right region,
and truncates the center region first. Truncation respects terminal cell
widths and grapheme boundaries. Each value may be a no-argument reactive
function that reads signal()s.
status_bar( left = "", center = "", right = "", id = NULL, classes = NULL, style = NULL, disabled = FALSE )status_bar( left = "", center = "", right = "", id = NULL, classes = NULL, style = NULL, disabled = FALSE )
left, center, right
|
Text for the three regions. |
id |
Optional identifier. |
classes |
Optional classes. |
style |
A |
disabled |
Disable the widget? |
A StatusBar widget with reactive left, center, and right
fields.
status_bar("SQLite :memory:", "127 rows", "8 ms")status_bar("SQLite :memory:", "127 rows", "8 ms")
See status_bar().
Widget -> StatusBar
paint_statesNames of state fields whose changes only need a
repaint (see invalidate_paint()); used by set_state().
leftText in the left region.
centerText in the center region.
rightText in the right region.
Widget$add_class()Widget$ancestors()Widget$animate()Widget$arrange_children()Widget$bind()Widget$bind_reactive()Widget$bindings()Widget$blur()Widget$capture_mouse()Widget$child_clip()Widget$clear()Widget$computed_style()Widget$content_height()Widget$content_width()Widget$default_bindings()Widget$focus()Widget$format()Widget$get_state()Widget$has_class()Widget$invalidate()Widget$invalidate_paint()Widget$is_displayed()Widget$is_enabled()Widget$layout_descend()Widget$layout_differs()Widget$matches()Widget$mount()Widget$on()Widget$post_message()Widget$print()Widget$pseudo_states()Widget$query()Widget$query_one()Widget$refresh()Widget$release_mouse()Widget$remove()Widget$remove_children()Widget$remove_class()Widget$render()Widget$render_lines()Widget$replace()Widget$run_action()Widget$run_process()Widget$run_worker()Widget$set()Widget$set_interval()Widget$set_state()Widget$set_timeout()Widget$toggle_class()Widget$walk()StatusBar$new()State fields are reactive and can be updated directly.
Create a status bar. See status_bar().
StatusBar$new( left = "", center = "", right = "", id = NULL, classes = NULL, style = NULL, disabled = FALSE )
left, center, rightRegion text.
id, classes, styleSee Widget.
disabledIs the widget disabled?
StatusBar$default_style()The built-in one-row style.
StatusBar$default_style()
StatusBar$paint()Paint the three text regions.
StatusBar$paint(buffer, area, st)
bufferA ScreenBuffer.
areaVisible rectangle.
stComputed style.
StatusBar$clone()The objects of this class are cloneable with this method.
StatusBar$clone(deep = FALSE)
deepWhether to make a deep clone.
Remove ANSI escape sequences from a string
strip_ansi(x)strip_ansi(x)
x |
A character vector. |
x without CSI/OSC escape sequences.
strip_ansi("\033[1mbold\033[0m")strip_ansi("\033[1mbold\033[0m")
style() describes how a widget looks and how much space it takes. Only
the properties you set are stored, so styles can be layered: a widget's
built-in default style is overridden by the style passed to its
constructor, and state styles (focus, disabled, ...) are applied on
top while the widget is in that state.
style( width = NULL, height = NULL, min_width = NULL, max_width = NULL, min_height = NULL, max_height = NULL, margin = NULL, padding = NULL, border = NULL, border_color = NULL, align = NULL, valign = NULL, wrap = NULL, layout = NULL, foreground = NULL, background = NULL, bold = NULL, italic = NULL, underline = NULL, reverse = NULL, dim = NULL, strike = NULL, grid_columns = NULL, grid_rows = NULL, grid_gap = NULL, column_span = NULL, row_span = NULL, focus = NULL, hover = NULL, disabled = NULL, states = NULL )style( width = NULL, height = NULL, min_width = NULL, max_width = NULL, min_height = NULL, max_height = NULL, margin = NULL, padding = NULL, border = NULL, border_color = NULL, align = NULL, valign = NULL, wrap = NULL, layout = NULL, foreground = NULL, background = NULL, bold = NULL, italic = NULL, underline = NULL, reverse = NULL, dim = NULL, strike = NULL, grid_columns = NULL, grid_rows = NULL, grid_gap = NULL, column_span = NULL, row_span = NULL, focus = NULL, hover = NULL, disabled = NULL, states = NULL )
width, height
|
Size, see above. |
min_width, max_width, min_height, max_height
|
Size limits in cells. |
margin, padding
|
Space outside / inside the border. One value (all sides), two values (vertical, horizontal) or four values (top, right, bottom, left). |
border |
Border type: |
border_color |
Border colour (defaults to the foreground colour). |
align |
Horizontal alignment of text, or of children inside a
container: |
valign |
Vertical alignment: |
wrap |
How text that is wider than the widget is wrapped: |
layout |
How a container arranges its children: |
foreground, background
|
Text and background colours. |
bold, italic, underline, reverse, dim, strike
|
Text attributes. |
grid_columns, grid_rows
|
Grid tracks for |
grid_gap |
Space between grid cells: one value, or |
column_span, row_span
|
How many grid cells a child occupies. |
focus, hover, disabled
|
Styles applied while the widget has focus, is under the mouse pointer, or is disabled. |
states |
A named list of styles for other widget states, e.g.
|
width and height accept:
a number: a fixed number of cells;
"auto": the natural size of the content;
"<n>fr": a share of the remaining space (e.g. "1fr", "2fr");
"<n>%": a percentage of the parent's content area.
foreground, background and border_color accept ANSI names
("red", "bright_blue", "grey"), integers 0-255 (xterm palette),
hex strings ("#ff8700") and R colour names ("steelblue").
An object of class termr_style.
style(width = 20, padding = c(0, 1), border = "round", foreground = "white", background = "blue", bold = TRUE, focus = style(background = "bright_blue"))style(width = 20, padding = c(0, 1), border = "round", foreground = "white", background = "blue", bold = TRUE, focus = style(background = "bright_blue"))
Parse termr stylesheets (RTCSS, a small CSS-like language) to style many
widgets at once by type, id, class and state. Pass them to
app(stylesheet = ) or app$add_stylesheet().
stylesheet(text, source = "<stylesheet>") stylesheet_file(path)stylesheet(text, source = "<stylesheet>") stylesheet_file(path)
text |
Stylesheet text. |
source |
Name used in error messages. |
path |
Path to a stylesheet file. |
Button { border: round; padding: 0 2; }
Button.danger { background: $error; }
#save { width: 20; }
Input:focus { border: heavy $accent; }
Vertical > Label { bold: true; }
Properties are the arguments of style() (border-color and
border_color both work). border also accepts a colour:
border: round cyan. Colours can refer to the theme: $primary.
Errors report the line, column and property.
Rules apply above a widget type's built-in style and below a widget's
own style. More specific selectors win (ids over classes and pseudo
classes over types); among equally specific rules, later ones win.
A termr_stylesheet.
sheet <- stylesheet("Button { border: round; } #save { background: $primary; }") sheetsheet <- stylesheet("Button { border: round; } #save { background: $primary; }") sheet
Filters combine with AND in filter_columns(). Predicates can
also be supplied directly as function(values) logical.
table_filter( type = c("equals", "contains", "regex", "range", "missing"), value = NULL, min = NULL, max = NULL, case_sensitive = FALSE, inclusive = TRUE )table_filter( type = c("equals", "contains", "regex", "range", "missing"), value = NULL, min = NULL, max = NULL, case_sensitive = FALSE, inclusive = TRUE )
type |
One of |
value |
Comparison value, text pattern, or regular expression. |
min, max
|
Inclusive or exclusive range bounds. |
case_sensitive |
Case-sensitive text matching? |
inclusive |
Include range endpoints? |
An object suitable for a named filter_columns() list.
A table source lets data_table() request only the rows it needs. All
callbacks are synchronous. get_rows() must return a data frame with the
requested columns in the requested order. Row counts are known.
table_source( row_count, column_names, get_rows, sort = NULL, filter = NULL, search = NULL, row_key = NULL, set_value = NULL, refresh = NULL, close = NULL, on_error = NULL )table_source( row_count, column_names, get_rows, sort = NULL, filter = NULL, search = NULL, row_key = NULL, set_value = NULL, refresh = NULL, close = NULL, on_error = NULL )
row_count |
Function returning the current number of rows, or a non-negative scalar count. |
column_names |
Function returning unique, non-empty names, or a character vector. |
get_rows |
Function |
sort, filter, search
|
Optional delegated operations. |
row_key |
Optional function mapping view positions to row keys. |
set_value |
Optional function |
refresh, close
|
Optional functions called by |
on_error |
Optional function returning a page-shaped placeholder when
|
Optional sort and filter callbacks change the source's current view.
They receive the sort keys or the named filter list used by
DataTable$sort() and DataTable$filter_columns(). Returning FALSE
rejects the operation; returning NULL or TRUE accepts it. A source
should expose only operations it can implement without materializing its
entire data set.
search receives a parsed query, column names, start, direction, and
include_current; it returns NULL or list(position, column). row_key
maps view positions to stable row identities. set_value(row, column, value) receives a current view position. refresh and close are
optional lifecycle callbacks. on_error(error, start, count, columns) may
return a correctly shaped placeholder data frame when a page read fails;
the table then displays the error instead of aborting a paint. Closing a
source is explicit and never closes resources the source does not own.
An experimental termr_table_source object.
The content of one tab. See tab().
labelThe tab label (reactive).
Widget$add_class()Widget$ancestors()Widget$animate()Widget$arrange_children()Widget$bind()Widget$bind_reactive()Widget$bindings()Widget$blur()Widget$capture_mouse()Widget$child_clip()Widget$clear()Widget$computed_style()Widget$content_height()Widget$content_width()Widget$default_bindings()Widget$focus()Widget$format()Widget$get_state()Widget$has_class()Widget$invalidate()Widget$invalidate_paint()Widget$is_displayed()Widget$is_enabled()Widget$layout_descend()Widget$layout_differs()Widget$matches()Widget$mount()Widget$on()Widget$paint()Widget$post_message()Widget$print()Widget$pseudo_states()Widget$query()Widget$query_one()Widget$refresh()Widget$release_mouse()Widget$remove()Widget$remove_children()Widget$remove_class()Widget$render()Widget$render_lines()Widget$replace()Widget$run_action()Widget$run_process()Widget$run_worker()Widget$set()Widget$set_interval()Widget$set_state()Widget$set_timeout()Widget$toggle_class()Widget$walk()Vertical$default_style()TabPane$new()Create a pane.
TabPane$new( label, ..., id = NULL, classes = NULL, style = NULL, disabled = FALSE )
labelTab label.
...Child widgets.
id, classes, style, disabledSee Widget.
TabPane$clone()The objects of this class are cloneable with this method.
TabPane$clone(deep = FALSE)
deepWhether to make a deep clone.
tabs() shows one of several panes, with a tab bar on top. Only the
active pane is laid out, painted and part of the focus chain. Switch tabs
by clicking a label, with Left/Right while the tab bar has focus, or
with Ctrl+PageUp / Ctrl+PageDown from anywhere inside. Switching sends a
"tabs.changed" message (event$data: index, previous, id,
label).
tabs(..., active = 1L, id = NULL, classes = NULL, style = NULL) tab(label, ..., id = NULL, classes = NULL, style = NULL)tabs(..., active = 1L, id = NULL, classes = NULL, style = NULL) tab(label, ..., id = NULL, classes = NULL, style = NULL)
... |
|
active |
Index or id of the initially active tab. |
id |
Optional identifier. |
classes |
Optional classes. |
style |
A |
label |
Tab label. |
A Tabs widget with methods activate(), add_tab(),
remove_tab() and fields active, active_tab, tab_count.
ui <- tabs( tab("Overview", label("Summary")), tab("Logs", label("No logs yet"), id = "logs") ) render_widget(ui, 30, 4)ui <- tabs( tab("Overview", label("Summary")), tab("Logs", label("No logs yet"), id = "logs") ) render_widget(ui, 30, 4)
Tabbed content. See tabs().
Widget -> Tabs
focusableThe tab bar can take focus (Left/Right switch tabs).
activeIndex of the active tab (assign to switch).
active_tabThe active TabPane, or NULL.
tab_countNumber of tabs.
Widget$add_class()Widget$ancestors()Widget$animate()Widget$bind()Widget$bind_reactive()Widget$bindings()Widget$blur()Widget$capture_mouse()Widget$clear()Widget$computed_style()Widget$focus()Widget$format()Widget$get_state()Widget$has_class()Widget$invalidate()Widget$invalidate_paint()Widget$is_displayed()Widget$is_enabled()Widget$layout_descend()Widget$layout_differs()Widget$matches()Widget$mount()Widget$on()Widget$post_message()Widget$print()Widget$pseudo_states()Widget$query()Widget$query_one()Widget$refresh()Widget$release_mouse()Widget$remove()Widget$remove_children()Widget$remove_class()Widget$render()Widget$render_lines()Widget$replace()Widget$run_action()Widget$run_process()Widget$run_worker()Widget$set()Widget$set_interval()Widget$set_state()Widget$set_timeout()Widget$toggle_class()Widget$walk()Tabs$new()Create tabs. See tabs().
Tabs$new( ..., active = 1L, id = NULL, classes = NULL, style = NULL, disabled = FALSE )
Tabs$default_style()The built-in style.
Tabs$default_style()
Tabs$default_bindings()Left/Right switch tabs when the bar is focused; Ctrl+PageUp / Ctrl+PageDown switch from anywhere inside.
Tabs$default_bindings()
Tabs$add_tab()Add a tab at the end.
Tabs$add_tab(pane, activate = FALSE)
paneA tab() (or any widget, wrapped in a tab named after
its id).
activateMake it the active tab?
Tabs$remove_tab()Remove a tab.
Tabs$remove_tab(which)
whichIndex or id of the tab.
Tabs$activate()Show a tab.
Tabs$activate(which)
whichIndex or id of the tab.
Tabs$action_next_tab()Show the next tab.
Tabs$action_next_tab()
Tabs$action_previous_tab()Show the previous tab.
Tabs$action_previous_tab()
Tabs$on_mouse_down()Clicking a label shows its tab.
Tabs$on_mouse_down(event)
eventA MouseEvent.
Tabs$arrange_children()Panes go below the tab bar.
Tabs$arrange_children(children, inner, st)
childrenVisible children.
innerContent rectangle.
stComputed style.
Tabs$child_clip()Panes are clipped below the tab bar.
Tabs$child_clip(st)
stComputed style.
Tabs$content_width()Natural width: the widest of the bar and the panes.
Tabs$content_width()
Tabs$content_height()Natural height: bar, rule and the active pane.
Tabs$content_height(width)
widthContent width.
Tabs$paint()Paint the tab bar.
Tabs$paint(buffer, area, st)
bufferA ScreenBuffer.
areaVisible part of the region.
stComputed style.
Tabs$clone()The objects of this class are cloneable with this method.
Tabs$clone(deep = FALSE)
deepWhether to make a deep clone.
What the terminal can do, detected once by the driver and consulted by
everything above it. Detection is conservative: a feature that cannot be
recognised from TERM, COLORTERM, NO_COLOR, CI or a few
terminal-specific variables is reported as unavailable and termr falls
back (e.g. to its internal clipboard instead of OSC 52).
terminal_capabilities( env = Sys.getenv(), windows = .Platform$OS.type == "windows", overrides = list() )terminal_capabilities( env = Sys.getenv(), windows = .Platform$OS.type == "windows", overrides = list() )
env |
Environment variables (named character vector or list); defaults to the current ones. |
windows |
Is this a Windows console? |
overrides |
Named list of capabilities that replace detected ones. |
Fields of the returned list:
colors: "truecolor", "256", "16" or "none";
truecolor, unicode, mouse, sgr_mouse, bracketed_paste,
alternate_screen, synchronized_output, cursor_shape,
hyperlinks (OSC 8), osc52 (clipboard write): logical.
Overrides (all optional): options(termr.color_mode = ),
options(termr.ascii = TRUE), options(termr.osc52 = TRUE/FALSE),
options(termr.hyperlinks = TRUE/FALSE), or the environment variables
TERMR_OSC52 and TERMR_HYPERLINKS set to 1 / 0.
An object of class termr_capabilities.
terminal_capabilities(env = c(TERM = "xterm-256color"), windows = FALSE) terminal_capabilities(env = c(TERM = "dumb"), windows = FALSE)$mouseterminal_capabilities(env = c(TERM = "xterm-256color"), windows = FALSE) terminal_capabilities(env = c(TERM = "dumb"), windows = FALSE)$mouse
A theme gives names to colours. Use them in styles and stylesheets as
"$name", e.g. style(background = "$primary"). Built-in widgets use
theme colours, so a theme restyles a whole app:
app(ui, theme = "dark") or app$theme <- termr_theme("light", accent = "purple").
termr_theme(base = "default", ..., name = base)termr_theme(base = "default", ..., name = base)
base |
Name of a built-in theme to start from. |
... |
Colours to set, e.g. |
name |
Name of the theme. |
Named termr_theme() so that it does not mask ggplot2::theme().
Colour names: foreground, background (screen background), surface
(headers, panels), muted (secondary text, guides, disabled widgets),
primary and on_primary (primary buttons, cursors), accent (focus),
success, warning, error, information, stripe (zebra rows).
Extra names can be added.
Built-in themes: "default" (the terminal's own 16-colour palette),
"dark" and "light" (24-bit colours) and "high-contrast" (black and
white with saturated yellow / cyan highlights and a heavier border around the
focused widget).
On a terminal without colour (NO_COLOR, TERM=dumb) selections and
cursors are drawn in reverse video, errors in bold underline and
secondary text dimmed, so nothing depends on colour alone.
A termr_theme.
termr_theme("dark", accent = "orange")termr_theme("dark", accent = "orange")
Starts the app with a headless driver and returns a Pilot that
simulates the user. Every action runs one tick of the real event loop
(input -> events -> timers -> repaint), and the output goes through the
real renderer into a virtual terminal, so tests see exactly what a user
would see.
test_app(app, width = 80L, height = 24L, color_mode = "truecolor")test_app(app, width = 80L, height = 24L, color_mode = "truecolor")
app |
An App or a widget. |
width, height
|
Virtual terminal size. |
color_mode |
Colour support of the virtual terminal: |
Pilot methods:
press(...): press keys, e.g. press("tab", "enter", "ctrl+c");
type(text): type characters;
resize(width, height): resize the terminal;
advance(seconds): let simulated time pass (fires timers);
click(target, y = NULL, button = "left"): click a widget (a selector
or widget; the centre of its visible part is used) or a position
click(x, y);
hover(target), scroll(target, direction = "down", times = 1):
move the pointer, turn the mouse wheel;
mouse(action, x, y, button, direction): send a raw mouse event;
drag(from, to, button = "left", steps = 3): press, move and release between two
positions (selectors, widgets or c(x, y));
paste(text): deliver a bracketed paste; system_clipboard(): text of the last OSC 52 write;
focus(target), find(selector): focus a widget, find one;
wait_for(condition, timeout = 5): step the event loop (simulated time, real time
while workers run) until condition(app) is TRUE;
run_worker(fn, ..., wait = TRUE): start a worker and wait for it;
wait_for_workers(timeout): wait for background workers to finish;
screen_text(): the visible screen as a character vector;
snapshot(): print the screen (for testthat::expect_snapshot());
query_one(selector), query(selector): find widgets;
stop(): exit the app and restore the (virtual) terminal.
Fields: app, driver, exited and value (the value passed to
app$exit()).
A Pilot object.
pilot <- test_app(app(input(id = "name")), width = 30, height = 5) pilot$type("Ada") pilot$query_one("#name")$value pilot$stop()pilot <- test_app(app(input(id = "name")), width = 30, height = 5) pilot$type("Ada") pilot$query_one("#name")$value pilot$stop()
An editable text area with a cursor, selection, undo/redo, search and scrolling. Text is stored as a vector of lines and edited by logical (row, grapheme) positions, so emoji, accents and CJK text are never split, and only the visible lines are formatted when drawing.
text_area( value = "", placeholder = "", id = NULL, classes = NULL, style = NULL, disabled = FALSE, line_numbers = FALSE, wrap = TRUE, read_only = FALSE, language = NULL, tab_size = 4L, tab_behavior = "focus", auto_indent = FALSE, validate = NULL, max_history = 200L, highlighter = NULL )text_area( value = "", placeholder = "", id = NULL, classes = NULL, style = NULL, disabled = FALSE, line_numbers = FALSE, wrap = TRUE, read_only = FALSE, language = NULL, tab_size = 4L, tab_behavior = "focus", auto_indent = FALSE, validate = NULL, max_history = 200L, highlighter = NULL )
value |
Initial text. |
placeholder |
Text shown while the area is empty. |
id |
Optional identifier. |
classes |
Optional classes. |
style |
A |
disabled |
Disabled areas cannot be focused or edited. |
line_numbers |
Show line numbers? |
wrap |
Wrap long lines? If |
read_only |
Block editing? |
language |
Optional language label supplied to the highlighter. |
tab_size |
Spaces per tab stop. |
tab_behavior |
|
auto_indent |
Keep the indentation on Enter? |
validate |
Optional |
max_history |
Maximum number of undo steps. |
highlighter |
Optional viewport-first syntax highlighter; see
|
Keys: arrows, Home/End, Ctrl+Home/End, Ctrl+Left/Right (words),
PageUp/PageDown, Shift+ to select, Ctrl+A select all, Enter, Backspace,
Delete, Ctrl+Backspace / Ctrl+Delete (words), Ctrl+U / Ctrl+K (to line
start / end), Ctrl+C / Ctrl+X / Ctrl+V (copy, cut, paste with the app
clipboard; copy also reaches the system clipboard via OSC 52 when the
terminal supports it), Ctrl+Z undo, Ctrl+Y redo, Ctrl+F find (Enter /
Down next, Up previous, Ctrl+R regex, Alt+C case, Esc close), F3 /
Shift+F3 next / previous match. Tab moves focus unless
tab_behavior = "indent". The mouse places the cursor, drags select and
the wheel scrolls. A bracketed paste is one undo step.
Messages (event$data): "textarea.changed" (version, lines,
valid; read the text with $value), "textarea.selection_changed"
(empty, start_row, start_column, end_row, end_column) and
"textarea.valid" / "textarea.invalid" (error).
Editing groups: typing is merged into undo steps per word, paste,
delete-selection and line operations are single steps. The history is
bounded (max_history steps and about 2 million characters).
Tabs in text are expanded to spaces. This widget is experimental.
A TextArea widget. Useful members: $value, $set_text(),
$insert(), $selection, $cursor_row, $cursor_column,
$goto_line(), $cursor_position(), $undo(), $redo(), $find(),
$replace(), $replace_all(), $find_next(), $find_previous(),
$match_count.
ed <- text_area("Hello\nworld", id = "editor", line_numbers = TRUE) ed$insert("!") ed$value ed$find("wor") ed$selectioned <- text_area("Hello\nworld", id = "editor", line_numbers = TRUE) ed$insert("!") ed$value ed$find("wor") ed$selection
A multi-line text editor. See text_area().
Widget -> TextArea
focusableText areas can be focused.
placeholderText shown while the area is empty.
line_numbersShow a line number gutter?
wrapWrap long lines (TRUE) or scroll horizontally?
read_onlyBlock editing (cursor, selection, copy and search still work)?
languageOptional language name passed to the configured highlighter.
tab_sizeSpaces inserted by Tab (and used for tabs in loaded text).
tab_behavior"focus": Tab moves focus (default, safe in
forms); "indent": Tab inserts spaces and Shift+Tab removes them.
auto_indentCopy the indentation of the current line on Enter?
highlighterOptional function (lines, state) returning a list
of per-line data frames with 1-based inclusive start, end, token.
validateNULL or function(value) returning NULL (valid)
or an error message.
valueThe text. Assigning replaces it (see set_text()).
textThe text (read-only alias of value).
linesThe lines as a character vector.
n_linesNumber of lines.
cursor_row, cursor_columnCursor position, 1-based (column 1 is before the first character).
selectionThe selected text ("" if none).
can_undo, can_redoIs there something to undo / redo?
history_sizeCharacters held by the undo history.
match_countNumber of matches of the current search.
find_openIs the find bar open?
validDoes the value pass validate?
errorThe validation message, or NULL.
Widget$add_class()Widget$ancestors()Widget$animate()Widget$arrange_children()Widget$bind()Widget$bind_reactive()Widget$bindings()Widget$blur()Widget$capture_mouse()Widget$child_clip()Widget$clear()Widget$computed_style()Widget$focus()Widget$format()Widget$get_state()Widget$has_class()Widget$invalidate()Widget$invalidate_paint()Widget$is_displayed()Widget$is_enabled()Widget$layout_descend()Widget$layout_differs()Widget$matches()Widget$mount()Widget$on()Widget$post_message()Widget$print()Widget$query()Widget$query_one()Widget$refresh()Widget$release_mouse()Widget$remove()Widget$remove_children()Widget$remove_class()Widget$render()Widget$render_lines()Widget$run_action()Widget$run_process()Widget$run_worker()Widget$set()Widget$set_interval()Widget$set_state()Widget$set_timeout()Widget$toggle_class()Widget$walk()TextArea$new()Create a text area.
TextArea$new( value = "", placeholder = "", id = NULL, classes = NULL, style = NULL, disabled = FALSE, line_numbers = FALSE, wrap = TRUE, read_only = FALSE, language = NULL, tab_size = 4L, tab_behavior = "focus", auto_indent = FALSE, validate = NULL, max_history = 200L, highlighter = NULL )
valueInitial text.
placeholderPlaceholder text.
id, classes, style, disabledSee Widget.
line_numbers, wrap, read_only, language, tab_size, tab_behavior, auto_indentSee the fields.
validateValidation function.
max_historyMaximum number of undo steps.
highlighterOptional function (lines, state) returning a list
of per-line data frames with 1-based inclusive start, end, token.
TextArea$default_style()The built-in style.
TextArea$default_style()
TextArea$pseudo_states()Active states: focus, hover, disabled and invalid.
TextArea$pseudo_states()
TextArea$default_bindings()Editing key bindings.
TextArea$default_bindings()
TextArea$on_key()Printable keys replace the selection or are inserted at the cursor; Ctrl+C / Ctrl+X copy / cut a selection. While the find bar is open, keys edit the search text.
TextArea$on_key(event)
eventA KeyEvent.
TextArea$on_paste()Pasted text is inserted as one undo step; line breaks are kept.
TextArea$on_paste(event)
eventA PasteEvent.
TextArea$on_mouse_down()Click to place the cursor, shift+click and drag to select.
TextArea$on_mouse_down(event)
eventA MouseEvent.
TextArea$on_mouse_move()Dragging with the left button extends the selection.
TextArea$on_mouse_move(event)
eventA MouseEvent.
TextArea$on_mouse_up()Ends a drag selection.
TextArea$on_mouse_up(event)
eventA MouseEvent.
TextArea$on_mouse_scroll()The mouse wheel scrolls three rows.
TextArea$on_mouse_scroll(event)
eventA MouseEvent.
TextArea$set_text()Replace the whole text. Clears the undo history and moves the cursor to the start.
TextArea$set_text(text)
textA string (or character vector of lines).
TextArea$insert()Insert text at the cursor, replacing the selection.
TextArea$insert(text, kind = NULL)
textA string; line breaks are kept.
kindInternal: "type" merges into undo groups, "paste"
does not.
TextArea$select_range()Select a range (1-based rows and columns; column 1 is before the first character).
TextArea$select_range(start_row, start_column, end_row, end_column)
start_row, start_column, end_row, end_columnThe range.
TextArea$goto_line()Move the cursor to a line.
TextArea$goto_line(row, column = 1L)
rowLine number (1-based).
columnColumn (1-based).
TextArea$cursor_position()Cursor position. Columns count grapheme clusters and terminal display cells, both 1-based.
TextArea$cursor_position()
TextArea$copy()Copy the selection to the app clipboard (and the system
clipboard via OSC 52 when system = TRUE and supported).
TextArea$copy(system = TRUE)
systemAlso write to the system clipboard?
TextArea$cut()Copy the selection and delete it.
TextArea$cut(system = TRUE)
systemAlso write to the system clipboard?
TextArea$undo()Undo the last edit group.
TextArea$undo()
TextArea$redo()Redo the last undone edit.
TextArea$redo()
TextArea$find()Search for text and select the first match at or after the cursor.
TextArea$find(query, case_sensitive = FALSE, regex = FALSE)
queryText or regular expression (PCRE).
case_sensitiveMatch case?
regexIs query a regular expression? Invalid expressions
raise an error.
TRUE if there is a match (invisibly).
TextArea$find_next()Select the next match (wrapping around).
TextArea$find_next()
TextArea$find_previous()Select the previous match (wrapping around).
TextArea$find_previous()
TextArea$replace()Replace the current search match, or find query and
replace its next match.
TextArea$replace( replacement, query = NULL, case_sensitive = FALSE, regex = FALSE )
replacementReplacement text.
queryOptional search text; defaults to the active search.
case_sensitive, regexSearch options used when query is given.
TextArea$replace_all()Replace all matches in one document edit. If the edit is larger than the bounded undo budget, it is applied without retaining an undo record.
TextArea$replace_all(query, replacement, case_sensitive = FALSE, regex = FALSE)
querySearch text or regular expression.
replacementReplacement text.
case_sensitiveMatch case?
regexInterpret query as a regular expression?
TextArea$clear_find()Remove the search highlights and close the find bar.
TextArea$clear_find()
TextArea$action_cursor_left()Move one character left.
TextArea$action_cursor_left()
TextArea$action_cursor_right()Move one character right.
TextArea$action_cursor_right()
TextArea$action_cursor_up()Move one row up.
TextArea$action_cursor_up()
TextArea$action_cursor_down()Move one row down.
TextArea$action_cursor_down()
TextArea$action_line_start()Move to the start of the line.
TextArea$action_line_start()
TextArea$action_line_end()Move to the end of the line.
TextArea$action_line_end()
TextArea$action_document_start()Move to the start of the text.
TextArea$action_document_start()
TextArea$action_document_end()Move to the end of the text.
TextArea$action_document_end()
TextArea$action_word_left()Move to the previous word.
TextArea$action_word_left()
TextArea$action_word_right()Move to the next word.
TextArea$action_word_right()
TextArea$action_page_up()Move one page up.
TextArea$action_page_up()
TextArea$action_page_down()Move one page down.
TextArea$action_page_down()
TextArea$action_select_left()Extend the selection left.
TextArea$action_select_left()
TextArea$action_select_right()Extend the selection right.
TextArea$action_select_right()
TextArea$action_select_up()Extend the selection up.
TextArea$action_select_up()
TextArea$action_select_down()Extend the selection down.
TextArea$action_select_down()
TextArea$action_select_line_start()Select to the start of the line.
TextArea$action_select_line_start()
TextArea$action_select_line_end()Select to the end of the line.
TextArea$action_select_line_end()
TextArea$action_select_document_start()Select to the start of the text.
TextArea$action_select_document_start()
TextArea$action_select_document_end()Select to the end of the text.
TextArea$action_select_document_end()
TextArea$action_select_word_left()Select to the previous word.
TextArea$action_select_word_left()
TextArea$action_select_word_right()Select to the next word.
TextArea$action_select_word_right()
TextArea$action_select_page_up()Extend the selection one page up.
TextArea$action_select_page_up()
TextArea$action_select_page_down()Extend the selection one page down.
TextArea$action_select_page_down()
TextArea$action_select_all()Select everything.
TextArea$action_select_all()
TextArea$action_newline()Insert a line break (keeping the indentation when
auto_indent is on).
TextArea$action_newline()
TextArea$action_delete_left()Delete the selection or the character before the cursor.
TextArea$action_delete_left()
TextArea$action_delete_right()Delete the selection or the character at the cursor.
TextArea$action_delete_right()
TextArea$action_delete_word_left()Delete the word before the cursor.
TextArea$action_delete_word_left()
TextArea$action_delete_word_right()Delete the word after the cursor.
TextArea$action_delete_word_right()
TextArea$action_delete_to_line_start()Delete from the start of the line to the cursor.
TextArea$action_delete_to_line_start()
TextArea$action_delete_to_line_end()Delete from the cursor to the end of the line (or the line break when the cursor is at the end).
TextArea$action_delete_to_line_end()
TextArea$action_paste()Insert the app clipboard.
TextArea$action_paste()
TextArea$action_indent()Insert spaces up to the next tab stop (or indent the selected lines).
TextArea$action_indent()
TextArea$action_dedent()Remove up to one tab stop of leading spaces.
TextArea$action_dedent()
TextArea$action_undo()Undo.
TextArea$action_undo()
TextArea$action_redo()Redo.
TextArea$action_redo()
TextArea$action_open_find()Open the find bar (Ctrl+F).
TextArea$action_open_find()
TextArea$action_find_next()Select the next match (F3).
TextArea$action_find_next()
TextArea$action_find_previous()Select the previous match (Shift+F3).
TextArea$action_find_previous()
TextArea$action_open_replace()Open the find and replace bar (Ctrl+H).
TextArea$action_open_replace()
TextArea$action_open_goto()Open the go-to-line bar (Ctrl+G).
TextArea$action_open_goto()
TextArea$content_width()Natural width: the longest line (at most 120 columns).
TextArea$content_width()
TextArea$content_height()Natural height: the number of lines (at most 1000).
TextArea$content_height(width)
widthContent width.
TextArea$paint()Draw the visible part of the text.
TextArea$paint(buffer, area, st)
bufferA ScreenBuffer.
areaVisible part of the region.
stComputed style.
TextArea$clone()The objects of this class are cloneable with this method.
TextArea$clone(deep = FALSE)
deepWhether to make a deep clone.
Returned by set_timeout() and set_interval().
delayDelay (or interval) in seconds.
repeatingDoes the timer repeat?
dueClock time of the next run.
callbackFunction called when the timer fires.
activeIs the timer still scheduled?
runsHow many times the timer has fired.
Timer$new()Create a timer (use set_timeout() instead).
Timer$new(delay, callback, repeating, now)
delaySeconds.
callbackFunction.
repeatingLogical.
nowCurrent clock time.
Timer$cancel()Stop the timer.
Timer$cancel()
Timer$print()Print the timer.
Timer$print(...)
...Ignored.
Timer$clone()The objects of this class are cloneable with this method.
Timer$clone(deep = FALSE)
deepWhether to make a deep clone.
A notification shown by app$notify().
severity"information", "success", "warning" or "error".
Widget$add_class()Widget$ancestors()Widget$animate()Widget$arrange_children()Widget$bind()Widget$bind_reactive()Widget$bindings()Widget$blur()Widget$capture_mouse()Widget$child_clip()Widget$clear()Widget$computed_style()Widget$content_height()Widget$content_width()Widget$default_bindings()Widget$focus()Widget$format()Widget$get_state()Widget$has_class()Widget$invalidate()Widget$invalidate_paint()Widget$is_displayed()Widget$is_enabled()Widget$layout_descend()Widget$layout_differs()Widget$matches()Widget$mount()Widget$on()Widget$paint()Widget$post_message()Widget$print()Widget$pseudo_states()Widget$query()Widget$query_one()Widget$refresh()Widget$release_mouse()Widget$remove()Widget$remove_children()Widget$remove_class()Widget$render_lines()Widget$replace()Widget$run_action()Widget$run_process()Widget$run_worker()Widget$set()Widget$set_interval()Widget$set_state()Widget$set_timeout()Widget$toggle_class()Widget$walk()Label$render()Label$update()Toast$new()Create a toast (use app$notify()).
Toast$new(message, title = NULL, severity = "information")
messageText.
titleOptional title.
severitySeverity.
Toast$default_style()The built-in style.
Toast$default_style()
Toast$on_click()Clicking closes the toast.
Toast$on_click(event)
eventA MouseEvent.
Toast$clone()The objects of this class are cloneable with this method.
Toast$clone(deep = FALSE)
deepWhether to make a deep clone.
Tree nodes
tree_node(label, ..., data = NULL, expanded = FALSE, id = NULL, loader = NULL)tree_node(label, ..., data = NULL, expanded = FALSE, id = NULL, loader = NULL)
label |
Text shown for the node. |
... |
Child nodes, or strings (leaf nodes). |
data |
Any R value attached to the node (e.g. a file path). |
expanded |
Start expanded? |
id |
Optional identifier (see |
loader |
Optional |
A TreeNode.
root <- tree_node("Project", tree_node("R", "app.R", "widget.R"), "README.md", expanded = TRUE) rootroot <- tree_node("Project", tree_node("R", "app.R", "widget.R"), "README.md", expanded = TRUE) root
Shows a tree_node() hierarchy with expand/collapse arrows and guide
lines. Only visible lines are painted, and children can be loaded lazily.
tree_view( root, show_root = TRUE, guides = TRUE, id = NULL, classes = NULL, style = NULL )tree_view( root, show_root = TRUE, guides = TRUE, id = NULL, classes = NULL, style = NULL )
root |
The root |
show_root |
Show the root itself (otherwise its children are the top level and it is always expanded). |
guides |
Draw guide lines? |
id |
Optional identifier. |
classes |
Optional classes. |
style |
A |
Keys: Up/Down/Page Up/Page Down/Home/End move; Right expands (or goes to
the first child); Left collapses (or goes to the parent); Space toggles;
Enter toggles and sends "tree.node_activated". Clicking selects a node;
clicking its arrow toggles it.
Messages (event$data: node, label, data, id):
"tree.node_selected", "tree.node_expanded", "tree.node_collapsed",
"tree.node_activated".
A TreeView widget with method select(node) and fields
root, cursor_node, visible_count.
root <- tree_node("Project", tree_node("R", "app.R", "widget.R", expanded = TRUE), "README.md", expanded = TRUE) render_widget(tree_view(root), 24, 5)root <- tree_node("Project", tree_node("R", "app.R", "widget.R", expanded = TRUE), "README.md", expanded = TRUE) render_widget(tree_view(root), 24, 5)
A node of a tree shown by tree_view(). See tree_node().
labelText shown for the node.
dataAny R value attached to the node.
idOptional identifier.
loaderNULL or function(node) returning children, called
the first time the node is expanded.
loadedHas the loader run?
parentThe parent node (read-only).
childrenChild nodes (read-only).
expandedIs the node expanded? (assign to expand / collapse)
TreeNode$new()Create a node. See tree_node().
TreeNode$new( label, children = list(), data = NULL, expanded = FALSE, id = NULL, loader = NULL )
labelLabel.
childrenChild nodes (or labels).
dataAttached value.
expandedStart expanded?
idIdentifier.
loaderLazy loader.
TreeNode$add()Add a child.
TreeNode$add(node, data = NULL, expanded = FALSE)
nodeA TreeNode or a label.
dataData for a node created from a label.
expandedExpanded state for a node created from a label.
The child node.
TreeNode$remove()Detach the node from its parent.
TreeNode$remove()
TreeNode$clear()Remove all children.
TreeNode$clear()
TreeNode$expand()Expand the node (running the loader if needed).
TreeNode$expand()
TreeNode$collapse()Collapse the node.
TreeNode$collapse()
TreeNode$toggle()Toggle between expanded and collapsed.
TreeNode$toggle()
TreeNode$expandable()Can the node be expanded?
TreeNode$expandable()
TreeNode$depth()Depth below the root (the root is 0).
TreeNode$depth()
TreeNode$ancestors()Parent, grandparent, ... up to the root.
TreeNode$ancestors()
TreeNode$path()Labels from the root to this node.
TreeNode$path()
TreeNode$walk()This node and all descendants (depth first).
TreeNode$walk()
TreeNode$find()Find a descendant by id.
TreeNode$find(id)
idIdentifier.
TreeNode$changed()Notify the tree view that the node changed.
TreeNode$changed()
TreeNode$print()Print the subtree.
TreeNode$print(...)
...Ignored.
TreeNode$clone()The objects of this class are cloneable with this method.
TreeNode$clone(deep = FALSE)
deepWhether to make a deep clone.
Shows a tree of tree_node()s. See tree_view().
Widget -> TreeView
paint_statesCursor and scroll changes only repaint.
focusableTrees can be focused.
show_rootShow the root node?
guidesDraw guide lines?
rootThe root node.
cursor_nodeThe node under the cursor, or NULL.
visible_countNumber of visible (expanded) lines.
offsetFirst visible line minus one.
Widget$add_class()Widget$ancestors()Widget$animate()Widget$arrange_children()Widget$bind()Widget$bind_reactive()Widget$bindings()Widget$blur()Widget$capture_mouse()Widget$child_clip()Widget$clear()Widget$computed_style()Widget$focus()Widget$format()Widget$get_state()Widget$has_class()Widget$invalidate()Widget$invalidate_paint()Widget$is_displayed()Widget$is_enabled()Widget$layout_descend()Widget$layout_differs()Widget$matches()Widget$mount()Widget$on()Widget$post_message()Widget$print()Widget$pseudo_states()Widget$query()Widget$query_one()Widget$refresh()Widget$release_mouse()Widget$remove()Widget$remove_children()Widget$remove_class()Widget$render()Widget$render_lines()Widget$replace()Widget$run_action()Widget$run_process()Widget$run_worker()Widget$set()Widget$set_interval()Widget$set_state()Widget$set_timeout()Widget$toggle_class()Widget$walk()TreeView$new()Create a tree view. See tree_view().
TreeView$new( root, show_root = TRUE, guides = TRUE, id = NULL, classes = NULL, style = NULL, disabled = FALSE )
TreeView$default_style()The built-in style.
TreeView$default_style()
TreeView$default_bindings()Navigation keys.
TreeView$default_bindings()
TreeView$tree_changed()Called by nodes when the tree changes.
TreeView$tree_changed()
TreeView$select()Move the cursor to a node (expanding its ancestors).
TreeView$select(node)
nodeA node of this tree.
TreeView$action_cursor_up()Move up.
TreeView$action_cursor_up()
TreeView$action_cursor_down()Move down.
TreeView$action_cursor_down()
TreeView$action_page_up()Move a page up.
TreeView$action_page_up()
TreeView$action_page_down()Move a page down.
TreeView$action_page_down()
TreeView$action_first()Go to the first node.
TreeView$action_first()
TreeView$action_last()Go to the last visible node.
TreeView$action_last()
TreeView$action_expand_or_child()Expand, or go to the first child.
TreeView$action_expand_or_child()
TreeView$action_collapse_or_parent()Collapse, or go to the parent.
TreeView$action_collapse_or_parent()
TreeView$action_toggle()Toggle the cursor node.
TreeView$action_toggle()
TreeView$action_activate()Toggle and send "tree.node_activated".
TreeView$action_activate()
TreeView$on_mouse_down()Clicking selects; clicking the arrow toggles.
TreeView$on_mouse_down(event)
eventA MouseEvent.
TreeView$on_mouse_scroll()The wheel scrolls three lines.
TreeView$on_mouse_scroll(event)
eventA MouseEvent.
TreeView$content_width()Natural width: the widest visible line.
TreeView$content_width()
TreeView$content_height()Natural height: visible lines (at most 1000).
TreeView$content_height(width)
widthContent width.
TreeView$paint()Draw the visible lines.
TreeView$paint(buffer, area, st)
bufferA ScreenBuffer.
areaVisible part of the region.
stComputed style.
TreeView$clone()The objects of this class are cloneable with this method.
TreeView$clone(deep = FALSE)
deepWhether to make a deep clone.
Built-in layouts cannot be removed.
unregister_layout(name)unregister_layout(name)
name |
A registered |
TRUE when the layout was removed.
vertical() stacks its children top to bottom; horizontal() places
them side by side. By default a vertical container fills the available
space, and a horizontal container is as tall as its tallest child.
vertical(..., id = NULL, classes = NULL, style = NULL) horizontal(..., id = NULL, classes = NULL, style = NULL)vertical(..., id = NULL, classes = NULL, style = NULL) horizontal(..., id = NULL, classes = NULL, style = NULL)
... |
Child widgets. |
id |
Optional identifier (for |
classes |
Optional classes (for |
style |
A |
Children sized "auto" take their natural size, fixed sizes are exact,
and "1fr", "2fr", ... share the remaining space. Use style(align =, valign =) on the container to position children that do not fill it.
A Vertical or Horizontal widget.
ui <- vertical( label("Title"), horizontal(label("left"), label("right")) ) render_widget(ui, 20, 3)ui <- vertical( label("Title"), horizontal(label("left"), label("right")) ) render_widget(ui, 20, 3)
Arranges children top to bottom. See vertical().
Widget -> Vertical
Widget$add_class()Widget$ancestors()Widget$animate()Widget$arrange_children()Widget$bind()Widget$bind_reactive()Widget$bindings()Widget$blur()Widget$capture_mouse()Widget$child_clip()Widget$clear()Widget$computed_style()Widget$content_height()Widget$content_width()Widget$default_bindings()Widget$focus()Widget$format()Widget$get_state()Widget$has_class()Widget$initialize()Widget$invalidate()Widget$invalidate_paint()Widget$is_displayed()Widget$is_enabled()Widget$layout_descend()Widget$layout_differs()Widget$matches()Widget$mount()Widget$on()Widget$paint()Widget$post_message()Widget$print()Widget$pseudo_states()Widget$query()Widget$query_one()Widget$refresh()Widget$release_mouse()Widget$remove()Widget$remove_children()Widget$remove_class()Widget$render()Widget$render_lines()Widget$replace()Widget$run_action()Widget$run_process()Widget$run_worker()Widget$set()Widget$set_interval()Widget$set_state()Widget$set_timeout()Widget$toggle_class()Widget$walk()Vertical$default_style()The built-in style.
Vertical$default_style()
Vertical$clone()The objects of this class are cloneable with this method.
Vertical$clone(deep = FALSE)
deepWhether to make a deep clone.
widget() creates a new widget type and returns its constructor. All
behaviour is given as plain functions that receive the widget as their
first argument, self.
widget( name, state = list(), render = NULL, compose = NULL, bindings = list(), actions = list(), on = list(), methods = list(), style = NULL, focusable = FALSE, inherit = Widget )widget( name, state = list(), render = NULL, compose = NULL, bindings = list(), actions = list(), on = list(), methods = list(), style = NULL, focusable = FALSE, inherit = Widget )
name |
Type name (used by type selectors, e.g. |
state |
A named list of state fields. Values created with
|
render |
|
compose |
|
bindings |
A list of |
actions |
A named list of |
on |
A named list of event handlers |
methods |
A named list of extra methods |
style |
Default |
focusable |
Can widgets of this type receive focus? |
inherit |
Parent class: Widget, Vertical or Horizontal. |
A constructor function
function(..., id = NULL, classes = NULL, style = NULL, disabled = FALSE).
Named arguments in ... set initial state values; unnamed arguments are
child widgets.
Counter <- widget( "Counter", state = list(count = reactive(0L)), render = function(self) sprintf("Count: %d", self$count), bindings = list(bind("up", "increment"), bind("down", "decrement")), actions = list( increment = function(self) self$count <- self$count + 1L, decrement = function(self) self$count <- self$count - 1L ), focusable = TRUE ) counter <- Counter(count = 5L) counter$count render_widget(counter, 12, 1)Counter <- widget( "Counter", state = list(count = reactive(0L)), render = function(self) sprintf("Count: %d", self$count), bindings = list(bind("up", "increment"), bind("down", "decrement")), actions = list( increment = function(self) self$count <- self$count + 1L, decrement = function(self) self$count <- self$count - 1L ), focusable = TRUE ) counter <- Counter(count = 5L) counter$count render_widget(counter, 12, 1)
Every element of a termr interface is a Widget. Widgets form a tree:
each widget has one parent and an ordered list of children. Most users
create widgets with constructor functions such as label() or
vertical(), and define new widget types with widget(). Subclassing
Widget with R6::R6Class() is also supported for advanced use.
A subclass usually overrides some of:
default_style(): the built-in style() of the widget type;
render(): returns the content as a string, a character vector of
lines or span()s;
on_key(event): handle a key press (return TRUE when handled);
paint(buffer, area, st): full control over drawing.
Widget state lives in reactive fields: assigning a new value invalidates the widget and schedules a repaint. Several assignments in one event loop tick produce a single repaint.
idUnique identifier used by #id selectors, or NULL.
classesCharacter vector of classes used by .class selectors.
helpOptional help text (Markdown) shown on the help screen (F1) while this widget or a descendant has focus.
paint_statesNames of state fields whose changes only need a
repaint (see invalidate_paint()); used by set_state().
focusableCan the widget receive keyboard focus?
regionBorder box assigned by the layout engine (region()).
parentThe parent widget (read-only).
childrenList of child widgets (read-only).
appThe App this widget belongs to, or NULL.
typeWidget type name used by type selectors.
visibleIs the widget shown? Hidden widgets take no space.
disabledDisabled widgets cannot be focused or used.
styleThe widget's own style() (layered over its defaults).
border_titleText shown in the top border (reactive), or NULL.
hoveredIs the mouse pointer over this widget (or a descendant)?
focusedDoes the widget currently have keyboard focus?
Widget$new()Create a widget.
Widget$new( ..., id = NULL, classes = NULL, style = NULL, disabled = FALSE, visible = TRUE )
...Child widgets.
idOptional identifier.
classesCharacter vector (or space separated string) of classes.
styleA style().
disabledIs the widget disabled?
visibleIs the widget visible?
Widget$default_style()The built-in style of this widget type.
Widget$default_style()
Widget$render()Content of the widget (string, lines or spans). Containers
return NULL.
Widget$render()
Widget$mount()Add child widgets, at the end or at a position. A widget that already has a parent is moved. Ids must be unique within a screen.
Widget$mount(..., before = NULL, after = NULL)
...Widgets or lists of widgets.
before, afterA child widget (or its index) to insert before / after.
Widget$replace()Remove all children and mount new ones.
Widget$replace(...)
...Widgets.
Widget$clear()Remove all children (containers). Some widgets redefine
clear() for their content (e.g. input(), log_view()).
Widget$clear()
Widget$remove()Detach this widget (and its children) from its parent.
Widget$remove()
Widget$remove_children()Remove all children.
Widget$remove_children()
Widget$walk()This widget followed by all descendants (depth first).
Widget$walk()
Widget$ancestors()Parent, grandparent, ... up to the root.
Widget$ancestors()
Widget$query()Find descendants matching a CSS-like selector.
Widget$query(selector)
selectorE.g. "Button", "#name", ".danger",
"Vertical > Button.primary", or several separated by commas.
A list of widgets.
Widget$query_one()The first descendant matching selector.
Widget$query_one(selector)
selectorA selector, see query().
Widget$matches()Does this widget match selector?
Widget$matches(selector)
selectorA selector, see query().
Widget$on()Handle events of a type that reach this widget (its own events and events bubbling up from descendants).
Widget$on(type, handler, selector = NULL)
typeEvent type, or "*" for all.
handlerfunction(event, app).
selectorOptional selector matched against the event sender.
The order of on() / app$on(), widget$on(type, selector, handler), is accepted too.
Widget$bind()Add a key binding to this widget, see bind().
Widget$bind(key, action = NULL, description = NULL)
keyKey name or a bind() binding.
actionAction name or function.
descriptionOptional description.
Widget$default_bindings()Built-in bindings of this widget type.
Widget$default_bindings()
Widget$bindings()All bindings of this widget (type bindings first, so instance bindings win).
Widget$bindings()
Widget$bind_reactive()Keep a field in sync with a reactive function: fn runs
now and again whenever the signal()s it reads change, and its
result is assigned to field (e.g. "text" for a label). The
binding ends when the widget is removed.
Widget$bind_reactive(field, fn)
fieldName of a widget field (an active binding such as text).
fnA function of no arguments.
Widget$capture_mouse()Receive all mouse events (also outside this widget's
region) until release_mouse() or the button is released.
Widget$capture_mouse()
Widget$release_mouse()Stop capturing the mouse.
Widget$release_mouse()
Widget$run_action()Run an action, looked up on this widget, its ancestors, then the app.
Widget$run_action(action)
actionAction name or function.
Widget$post_message()Send a message that bubbles up from this widget to the
app. Handlers receive a MessageEvent whose sender is this widget.
Widget$post_message(type, data = list(), bubbles = TRUE)
typeMessage name, e.g. "counter.changed".
dataA list of values.
bubblesShould the message bubble to ancestors?
The event (invisibly), or NULL when not attached to an app.
Widget$set_timeout()Call callback(self, app) once after delay seconds.
The timer is cancelled automatically when the widget is removed.
Widget$set_timeout(delay, callback)
delaySeconds.
callbackFunction.
A Timer.
Widget$set_interval()Call callback(self, app) every interval seconds
while the widget is mounted.
Widget$set_interval(interval, callback)
intervalSeconds.
callbackFunction.
A Timer.
Widget$animate()Animate a numeric field of this widget. See animate().
Widget$animate(property, to, ...)
propertyField name.
toTarget value.
...Other arguments of animate().
Widget$run_worker()Run a background worker owned by this widget (cancelled
when the widget is removed). See run_worker().
Widget$run_worker(fn, ...)
fnFunction to run.
...Other arguments of run_worker().
Widget$run_process()Run an external program owned by this widget. See
run_process().
Widget$run_process(command, ...)
commandProgram to run.
...Other arguments of run_process().
Widget$focus()Give keyboard focus to this widget.
Widget$focus()
Widget$blur()Remove keyboard focus from this widget.
Widget$blur()
Widget$add_class()Add classes.
Widget$add_class(...)
...Class names.
Widget$remove_class()Remove classes.
Widget$remove_class(...)
...Class names.
Widget$toggle_class()Add a class if absent, remove it if present.
Widget$toggle_class(name)
nameClass name.
Widget$has_class()Does the widget have this class?
Widget$has_class(name)
nameClass name.
Widget$set()Assign one or more fields, e.g.
app$query_one("#name")$set(value = ""). R does not allow
app$query_one("#name")$value <- "", so use this method when the
widget comes from a function call.
Widget$set(...)
...Named values.
The widget, invisibly (so calls can be chained).
Widget$get_state()Read a state field.
Widget$get_state(name)
nameField name.
Widget$set_state()Write a state field; invalidates the widget when the value changes.
Widget$set_state(name, value)
nameField name.
valueNew value.
Widget$layout_differs()Would the widget's size-related style differ if it were
in the pseudo states with rather than without? Used to decide
whether a focus / hover change needs a layout pass.
Widget$layout_differs(with, without)
with, withoutCharacter vectors of states.
Widget$invalidate()Mark the widget as needing a re-render and schedule a repaint, including a new layout pass (its size may have changed). Repaints are batched per event-loop tick.
Widget$invalidate()
Widget$invalidate_paint()Like invalidate() for changes that cannot affect the
size or position of anything (a cursor moved, a colour changed): the
widget is repainted but the layout is not recomputed.
Widget$invalidate_paint()
Widget$refresh()Force the widget to re-render on the next repaint.
Widget$refresh()
Widget$render_lines()Rendered content as lines of styled segments (cached until the widget is invalidated).
Widget$render_lines(width = NA_integer_)
widthAvailable content width (may be NA while measuring).
Widget$content_width()Natural width of the content area.
Widget$content_width()
Widget$content_height()Natural height of the content area for a given width.
Widget$content_height(width)
widthContent width.
Widget$arrange_children()Place the visible children inside the content box. Containers with special behaviour (scrolling, ...) override this.
Widget$arrange_children(children, inner, st)
childrenVisible child widgets.
innerContent rectangle of this widget.
stComputed style of this widget.
A list with one rectangle per child.
Widget$child_clip()The rectangle children are clipped to when painting.
Widget$child_clip(st)
stComputed style of this widget.
Widget$pseudo_states()Names of active states used to select state styles.
Widget$pseudo_states()
Widget$computed_style()The fully resolved style of the widget.
Widget$computed_style(inherited = NULL)
inheritedThe parent's computed style (computed if NULL).
Widget$layout_descend()Which children need their own layout? Containers that clip their children (scroll views) skip the ones that are entirely out of view; they get their region but not their descendants.
Widget$layout_descend(rects)
rectsThe rectangles arrange_children() returned.
Widget$paint()Paint the widget (not its children) into a buffer.
Widget$paint(buffer, area, st)
bufferA ScreenBuffer.
areaThe visible part of self$region.
stThe computed style.
Widget$is_enabled()Is the widget and every ancestor enabled?
Widget$is_enabled()
Widget$is_displayed()Is the widget and every ancestor visible?
Widget$is_displayed()
Widget$format()A one-line description used by print().
Widget$format(...)
...Ignored.
Widget$print()Print the widget tree.
Widget$print(...)
...Ignored.
Widget$clone()The objects of this class are cloneable with this method.
Widget$clone(deep = FALSE)
deepWhether to make a deep clone.
Arbitrary widget state and field values are intentionally omitted, so passwords, database credentials, and worker data are not serialized.
widget_snapshot(x)widget_snapshot(x)
x |
A deterministic nested list of widget descriptions.
The JSON form of widget_snapshot(). Requires the optional jsonlite
package.
widget_snapshot_json(x, pretty = TRUE)widget_snapshot_json(x, pretty = TRUE)
x |
|
pretty |
Format JSON for readability? |
A JSON string.
Returned by app$run_worker() and app$run_process(). See
run_worker().
nameName of the worker (used in events).
state"running", "completed", "failed" or "cancelled".
resultThe value returned by the function (workers) or the exit status (processes).
errorThe error message, if it failed.
timed_outDid the worker fail because its timeout expired?
progressLast reported progress value.
ownerWidget that owns the worker, or NULL.
stdout, stderrThe most recent output lines (at most 1000).
kind"worker" (an R function) or "process".
Worker$new()Create a worker (use app$run_worker()).
Worker$new(name, owner = NULL, callbacks = list())
nameName.
ownerOwner widget.
callbacksList of callbacks.
Worker$cancel()Stop the worker: an interrupt is sent first (Unix) and
the process tree is killed if it has not ended after grace
seconds.
Worker$cancel(grace = 0.3)
graceSeconds to wait before killing.
Worker$is_running()Is the worker still running?
Worker$is_running()
Worker$pid()Process id of the child (or NA).
Worker$pid()
Worker$print()Print the worker.
Worker$print(...)
...Ignored.
Worker$clone()The objects of this class are cloneable with this method.
Worker$clone(deep = FALSE)
deepWhether to make a deep clone.
Write a static rendering to a UTF-8 file
write_rendered( x, file, format = c("text", "markdown", "html", "svg", "json"), width = 80, height = 24 )write_rendered( x, file, format = c("text", "markdown", "html", "svg", "json"), width = 80, height = 24 )
x |
A widget, Screen, App, or ScreenBuffer. |
file |
Output path. |
format |
One of |
width, height
|
Frame size in cells. |