NewDriver#
func NewDriver(config Config, canvas *ui.Canvas) (*Driver, error)NewDriver creates a driver for config, painting into canvas (a fresh canvas when nil). The first frame has been painted when it returns.
type Driver struct {
// origin is where Config.Origin put the content area; MoveWindow changes it
// as a window manager would.
// virtual time the next requested frame is due
// modifierKeys is the modifier keys KeyDown holds, one bit per
// ui.KeyShiftLeft..ui.KeyMetaRight.
}Driver runs an application without a window: the same painter, input router, focus rules and text-input path a native window drives, fed by explicit calls instead of operating-system events, with an animation clock that only moves when told to. It exists so tools and tests can operate an application and look at it without opening anything on the user's screen.
Output is a Snapshot: the retained primitives, labels, native-editor overlay, hit regions and focus. Turning a Snapshot into pixels is the job of the platform's offscreen renderer (see package headless).
A Driver is not safe for concurrent use. Background goroutines reach it only through Config.Invalidator, exactly as with a window; the wake is applied the next time the driver is called (or by Pump).
NewDriver#func NewDriver(config Config, canvas *ui.Canvas) (*Driver, error)NewDriver creates a driver for config, painting into canvas (a fresh canvas when nil). The first frame has been painted when it returns.
Advance#func (driver *Driver) Advance(duration time.Duration) errorAdvance moves virtual time forward by duration, repainting at frame cadence while an animation is in flight and applying background wakes. An idle application repaints nothing, as in a window.
Chord#func (driver *Driver) Chord(modifiers ui.Modifiers, character string) errorChord delivers a modified printable character. Control and Meta chords are raw key events whose Text is the base character (Control+C is Key unknown, Text "c"). Alt is raw only when the focused terminal requested AltSendsEscape and no input-method composition is active. It fails unless a terminal has the keyboard. Characters typed with only Shift are text.
Click#func (driver *Driver) Click(x, y float32) errorClick moves to a point and presses and releases the primary button.
ClickButton#func (driver *Driver) ClickButton(x, y float32, button ui.PointerButton) errorClickButton moves to a point and presses and releases the given button once: ui.PointerButtonSecondary is the right button, whose press opens context menus.
ClickCount#func (driver *Driver) ClickCount(x, y float32, clicks int) errorClickCount performs a click sequence of the given length (1 for a click, 2 for a double click, 3 for a triple click); each press and release carries its position in the sequence.
Clipboard#func (driver *Driver) Clipboard() stringClipboard is the driver's private clipboard, including text an application returns through ui.EventResult.ClipboardText.
ClipboardImage#func (driver *Driver) ClipboardImage() []byteClipboardImage returns the PNG the driver's private clipboard holds, or nil. The slice is the driver's own; do not modify it.
Close#func (driver *Driver) Close()Close detaches the driver from its Invalidator and releases its resources.
DoubleClick#func (driver *Driver) DoubleClick(x, y float32) errorDoubleClick clicks twice at a point in quick succession: the second press and release carry a click count of 2.
Drop#func (driver *Driver) Drop(event ui.FileDropEvent) (bool, error)Drop delivers a drag of files from the system: a hover (FileDropOver) at a point, its end (FileDropLeave), or the drop with its paths. It reports whether the hit under the point took the files.
Frame#func (driver *Driver) Frame() ui.RectFrame is the window's content area in screen coordinates: where Config.Origin or the last MoveWindow put it (the screen's corner when neither), at the window's current size.
HitTest#func (driver *Driver) HitTest(x, y float32) (ui.ID, bool)HitTest returns the front-most enabled interaction target at a logical-pixel point. It applies the same focus-scope and blocking-region rules as pointer input without moving the pointer or repainting.
HoldsKeys#func (driver *Driver) HoldsKeys() boolHoldsKeys reports whether the focused terminal asked for presses and releases (TextInput.KeyReleases), the case in which KeyDown and KeyUp deliver key events with their Release flag.
Key#func (driver *Driver) Key(key ui.Key, modifiers ui.Modifiers) errorKey delivers a key press with its modifiers. While a text field is being edited the key goes where a native window would send it: Tab and Escape (and Enter in a single-line field) to the application, everything else to the text system as an editing command. A terminal gets every named key raw, as ui.KeyEvents.
KeyDown#func (driver *Driver) KeyDown(key ui.Key, character string) errorKeyDown presses a key and keeps it down until KeyUp, as a person holding it would. Modifier keys (ui.KeyShiftLeft and the like) stay held for every pointer, scroll and key the driver delivers meanwhile, so Shift-click and Ctrl-click work. A focused terminal that asked for releases (HoldsKeys) gets the press as a KeyEvent: a named key by Key, a printable key by Text, which character names; any other focus gets the key as Key or Chord would deliver it, and KeyUp then does nothing.
KeyUp#func (driver *Driver) KeyUp(key ui.Key, character string) errorKeyUp releases a key KeyDown pressed. A key that is not down is ignored.
LastOpenDirectoryRequest#func (driver *Driver) LastOpenDirectoryRequest() (OpenDirectoryOptions, bool)LastOpenDirectoryRequest returns the most recent OpenDirectory options observed by driver.
LastOpenFilesRequest#func (driver *Driver) LastOpenFilesRequest() (OpenFileOptions, bool)LastOpenFilesRequest returns the most recent OpenFiles options observed by driver. The returned Filters slice is borrowed from the application call.
LastOpenedPath#func (driver *Driver) LastOpenedPath() (string, bool)LastOpenedPath returns the most recent file passed to OpenPath while this driver was active. Like LastOpenedURL, driver-backed runs record the request and open nothing.
LastOpenedURL#func (driver *Driver) LastOpenedURL() (string, bool)LastOpenedURL returns the most recent target passed to OpenURL while this driver was active. Driver-backed runs record the request without asking the operating system to open anything.
LastSaveFileRequest#func (driver *Driver) LastSaveFileRequest() (SaveFileOptions, bool)LastSaveFileRequest returns the most recent SaveFile options observed by driver. The returned Filters slice is borrowed from the application call.
Leave#func (driver *Driver) Leave() errorLeave moves the pointer out of the window.
LoseFocus#func (driver *Driver) LoseFocus() errorLoseFocus makes the window lose the keyboard, as switching to another application does: keys held down are released first. Modifiers held by KeyDown are forgotten with them.
Maximized#func (driver *Driver) Maximized() boolMaximized reports the state SetMaximized last reported.
Minimized#func (driver *Driver) Minimized() boolMinimized reports the state SetMinimized last reported.
Move#func (driver *Driver) Move(x, y float32) errorMove moves the pointer to a point in logical pixels.
MoveWindow#func (driver *Driver) MoveWindow(x, y float32) errorMoveWindow places the content area at a screen point, as dragging the window would, and reports the new frame to OnFrameChange.
NativeAppearance#func (driver *Driver) NativeAppearance() AppearanceNativeAppearance is what the application last asked SetNativeAppearance for, AppearanceUnknown (the system's own) if it has not.
Now#func (driver *Driver) Now() time.DurationNow is the driver's virtual time, which starts at zero.
Press#func (driver *Driver) Press(x, y float32, button ui.PointerButton) errorPress presses a pointer button at a point (moving there first) as a lone click.
PressAt#func (driver *Driver) PressAt(x, y float32) PressKindPressAt reports what a press at a point would do in a custom-titlebar window: whether the platform moves the window from there, now or once the pointer drags, or the application takes the press. It applies the same rules as the platform's own question, so a test can assert that a title bar moves the window and that a menu's backdrop over it still takes the press.
PressCount#func (driver *Driver) PressCount(x, y float32, button ui.PointerButton, clicks int) errorPressCount presses a button as the clicks-th press of a click sequence (2 for the second press of a double click), the way the operating system reports it.
Pump#func (driver *Driver) Pump() errorPump applies a pending background repaint request, the way a window would on its next loop turn: OnWake runs, then the application repaints. Every input method pumps first, so state published by another goroutine is visible to the event that follows.
QueueOpenDirectory#func (driver *Driver) QueueOpenDirectory(path string, err error) errorQueueOpenDirectory queues the result returned by the next OpenDirectory call made while driver is active.
QueueOpenFiles#func (driver *Driver) QueueOpenFiles(paths []string, err error) errorQueueOpenFiles queues the result returned by the next OpenFiles call made while driver is active. Paths are copied so the queued response does not depend on caller-owned slice storage.
QueueSaveFile#func (driver *Driver) QueueSaveFile(path string, err error) errorQueueSaveFile queues the result returned by the next SaveFile call made while driver is active. It lets headless tools exercise native file-save workflows without opening an operating-system dialog.
Release#func (driver *Driver) Release(x, y float32, button ui.PointerButton) errorRelease releases a pointer button at a point, as the lone click's release.
ReleaseCount#func (driver *Driver) ReleaseCount(x, y float32, button ui.PointerButton, clicks int) errorReleaseCount releases a button with the count of the press it ends.
Resize#func (driver *Driver) Resize(width, height int) errorResize changes the content size in logical pixels and repaints.
Scroll#func (driver *Driver) Scroll(event ui.ScrollEvent) errorScroll delivers a scroll gesture at a logical-pixel window point. Positive deltas reveal content below and to the right. Target and Viewport are derived from the current frame; the other fields are delivered as supplied.
SelectText#func (driver *Driver) SelectText(start, end int) errorSelectText selects a rune range of the focused text field.
SetClipboard#func (driver *Driver) SetClipboard(value string)SetClipboard replaces the driver's private clipboard.
SetClipboardImage#func (driver *Driver) SetClipboardImage(png []byte) errorSetClipboardImage replaces the driver's private clipboard with a PNG image, as another application copying a picture would. The text it held is gone, as on a real clipboard. The bytes are copied. A nil or empty png empties the clipboard of images. The image must be a PNG within MaxClipboardImageBytes.
SetMaximized#func (driver *Driver) SetMaximized(maximized bool) errorSetMaximized reports the window as maximized or restored, as the window manager would, and calls OnMaximize.
SetMinimized#func (driver *Driver) SetMinimized(minimized bool) errorSetMinimized reports the window as minimized or restored, as the window manager would, and calls OnMinimize.
SetSystemAppearance#func (driver *Driver) SetSystemAppearance(appearance Appearance)SetSystemAppearance changes what SystemAppearance reports while this driver runs and tells the watchers, as the system would.
Shortcut#func (driver *Driver) Shortcut(character rune) (bool, error)Shortcut delivers a Command-key shortcut. It is retained as the compact editing helper; use ShortcutChord when the complete modifier set matters.
ShortcutChord#func (driver *Driver) ShortcutChord(modifiers ui.Modifiers, character rune) (bool, error)ShortcutChord handles ordinary text editing before offering other chords to the application and applying the terminal fallback. The complete modifier set is preserved, which lets headless tests exercise application shortcuts such as Command+Alt+X without bypassing the native text path.
Snapshot#func (driver *Driver) Snapshot() SnapshotSnapshot captures the current frame. The result is independent of later driver calls.
Transitioning#func (driver *Driver) Transitioning() boolTransitioning reports whether a transition is in flight: the last paint asked for the next frame at display cadence. A display that changes slowly (a spinner stepping every 125 ms) asks later and does not count, so waiting for the application to come to rest ends even with one on screen.
Type#func (driver *Driver) Type(value string) errorType inserts text into the focused text field, replacing its selection.
Wakes#func (driver *Driver) Wakes() <-chan struct{}Wakes receives a value whenever a background goroutine asked for a repaint since the last Pump. Tools use it to sleep until there is something to apply.