| App | R Documentation |
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 )
...Widgets, on() handlers and bind() bindings.
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 )
labelText shown in the palette, or a command() object.
actionAn action name or function(app).
category, shortcut, enabled, descriptionSee command().
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.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.