pub struct Context { /* private fields */ }Expand description
What a plugin is called with besides a frame: its configuration, and handles to every interface.
Implementations§
Source§impl Context
impl Context
pub const fn new() -> Self
Sourcepub fn config_json(&self) -> Json
pub fn config_json(&self) -> Json
The configuration document activate was called with.
Sourcepub fn config<T: DeserializeOwned>(&self) -> Result<T>
pub fn config<T: DeserializeOwned>(&self) -> Result<T>
The configuration, deserialized (an empty document is null).
pub fn live(&self) -> Live
Sourcepub fn calls(&self) -> Calls
pub fn calls(&self) -> Calls
Examples found in repository?
83 fn event(&mut self, event: Event, cx: &mut Context) {
84 match event {
85 Event::Plugin { name, .. } if name == "together.changed" => {
86 self.reload(cx);
87 self.paint();
88 // A commit from an event is sampled on the next frame;
89 // ask for one.
90 cx.request_frame();
91 }
92 Event::Resize { .. } => {
93 self.paint();
94 cx.request_frame();
95 }
96 Event::Pointer(pointer) if pointer.kind == PointerKind::Down => {
97 // Side-effect free unless this viewer is the one the user
98 // is driving, and then exactly once across viewers.
99 if !view::is_driving() {
100 return;
101 }
102 // `send` returns at once: the companion's answer arrives as
103 // the value it writes, not here.
104 let _ = claims().once("together.rebuild", 5_000, || {
105 let _ = cx.calls().send("rebuild", &(), Target::Singleton);
106 });
107 }
108 _ => {}
109 }
110 }pub fn claims(&self) -> Claims
pub fn is_driving(&self) -> bool
pub fn capabilities(&self) -> Capabilities
Sourcepub fn request_frame(&self)
pub fn request_frame(&self)
Asks for a frame on the next paced frame, from an event handler
(inside UiPlugin::frame, use Frame::request_frame). A commit
in event is otherwise sampled on the next frame something else
causes.
Examples found in repository?
131 fn event(&mut self, event: Event, cx: &mut Context) {
132 match event {
133 // A new, empty buffer, and perhaps a new cell pixel size. The
134 // theme's accent colours the image, so a new theme repaints too,
135 // and a viewer that gains or loses graphics gets the other paint.
136 Event::Resize { .. } | Event::ThemeChanged | Event::CapabilitiesChanged => {
137 self.paint();
138 cx.request_frame();
139 }
140 _ => {}
141 }
142 }More examples
83 fn event(&mut self, event: Event, cx: &mut Context) {
84 match event {
85 Event::Plugin { name, .. } if name == "together.changed" => {
86 self.reload(cx);
87 self.paint();
88 // A commit from an event is sampled on the next frame;
89 // ask for one.
90 cx.request_frame();
91 }
92 Event::Resize { .. } => {
93 self.paint();
94 cx.request_frame();
95 }
96 Event::Pointer(pointer) if pointer.kind == PointerKind::Down => {
97 // Side-effect free unless this viewer is the one the user
98 // is driving, and then exactly once across viewers.
99 if !view::is_driving() {
100 return;
101 }
102 // `send` returns at once: the companion's answer arrives as
103 // the value it writes, not here.
104 let _ = claims().once("together.rebuild", 5_000, || {
105 let _ = cx.calls().send("rebuild", &(), Target::Singleton);
106 });
107 }
108 _ => {}
109 }
110 }106 fn event(&mut self, event: Event, cx: &mut Context) {
107 match event {
108 // The surface has a new, empty buffer.
109 Event::Resize { .. } => self.dirty = true,
110 Event::Key(key) if key.phase != KeyPhase::Release => match key.code {
111 KeyCode::Up => self.select(self.selected.saturating_sub(1)),
112 KeyCode::Down => self.select(self.selected.saturating_add(1)),
113 KeyCode::PageUp => self.select(self.selected.saturating_sub(self.page())),
114 KeyCode::PageDown => self.select(self.selected.saturating_add(self.page())),
115 KeyCode::Home => self.select(0),
116 KeyCode::End => self.select(ITEMS - 1),
117 _ => return,
118 },
119 // The pointer arrives in the surface's own rows, wherever the
120 // list is scrolled to, so the row names the item.
121 Event::Pointer(pointer) if pointer.kind == PointerKind::Down => {
122 let Some(item) = pointer.row.checked_sub(TITLE_ROWS) else {
123 return;
124 };
125 if item >= ITEMS {
126 return;
127 }
128 self.selected = item;
129 self.dirty = true;
130 }
131 _ => return,
132 }
133 cx.request_frame();
134 }Sourcepub fn open(&self, surface: &str) -> Result<()>
pub fn open(&self, surface: &str) -> Result<()>
Opens a stage surface. Only while handling a user gesture: a key,
a paste, a pointer press on one of the plugin’s surfaces, or one of
its commands.
Sourcepub fn focus_pane(&self, pane: &str) -> Result<()>
pub fn focus_pane(&self, pane: &str) -> Result<()>
Shows a pane in this viewer’s workspace and gives it focus, as a
click on its sidebar row does. Only while handling a user gesture,
as Context::open; a pane the viewer does not know is ignored.
Sourcepub fn create_pane(
&self,
project: &str,
argv: &[String],
title: &str,
) -> Result<String>
pub fn create_pane( &self, project: &str, argv: &[String], title: &str, ) -> Result<String>
Creates a pane through this driving viewer’s normal action, including
on a remote project’s machine. Needs view.pane-create and a gesture.
Returns its permanent id; wait for crate::view::PANE_CREATE_RESULT
before treating it as created. Never takes controller authority.
Sourcepub fn open_url(&self, url: &str) -> Result<()>
pub fn open_url(&self, url: &str) -> Result<()>
Opens an https:// URL in the user’s browser (crate::url::open):
while handling user input, or within a second after it.
Sourcepub fn open_instance(
&self,
surface: &str,
key: &str,
after: Option<&str>,
) -> Result<String>
pub fn open_instance( &self, surface: &str, key: &str, after: Option<&str>, ) -> Result<String>
Opens an instance of the declared pane or window surface
surface, named <surface>@<key>, and returns that name: a surface
of its own for events, Surface and
Context::close. A pane instance with after opens right after
that pane without taking focus. It needs a user gesture, as
Context::open, unless the plugin holds
surface.open-unprompted and names after.
Sourcepub fn request_size(&self, surface: &str, cols: u32, rows: u32) -> Result<()>
pub fn request_size(&self, surface: &str, cols: u32, rows: u32) -> Result<()>
Asks for surface to be cols by rows cells (0: the viewer’s
choice in that dimension) instead of the manifest’s size. The
viewer clamps it where it places the surface and sends
Event::Resize when the size changes. A card grows to show more
rows; a popover fits its content.
Sourcepub fn set_label(&self, surface: &str, label: Option<&str>) -> Result<()>
pub fn set_label(&self, surface: &str, label: Option<&str>) -> Result<()>
Sets a short label the viewer shows at the right end of surface’s
chrome title: a boxed card’s top border, a pane’s header, a column’s
title row. None removes it. At most 48 characters with no control
characters.
Sourcepub fn set_caret(&self, surface: &str, caret: Option<(u32, u32)>) -> Result<()>
pub fn set_caret(&self, surface: &str, caret: Option<(u32, u32)>) -> Result<()>
Places the viewer’s own text cursor at (col, row) of surface
while the surface takes keys (an open stage, popover or pane
overlay, or the surface a click or open gave input focus), so a
text field draws no cursor of its own; the cursor trail moves to it.
None removes it. Stays until set again.
Sourcepub fn set_scroll(&self, surface: &str, scroll: Option<Scroll>) -> Result<()>
pub fn set_scroll(&self, surface: &str, scroll: Option<Scroll>) -> Result<()>
Paints the cells surface surface scroll.rows rows tall, taller
than where it shows, for the viewer to scroll as it scrolls its own
lists: wheel and trackpad, a finger’s drag and glide, the rubber
band at each end, and pixel motion where the terminal has it. The
fixed rows at the top and bottom stay in place. The viewer sends
Event::Resize with the new height, so paint the whole surface as
usual; pointer events arrive in the surface’s own rows and the
viewer keeps the vertical wheel over the scrolling rows. None
returns it to the size it shows at. Stays until set again.
Sourcepub fn reveal(&self, surface: &str, first: u32, last: u32) -> Result<()>
pub fn reveal(&self, surface: &str, first: u32, last: u32) -> Result<()>
Brings rows first..=last of the scrolling surface into view,
gliding there as the viewer’s lists follow a selection. Rows in view
stay put. Call it when a key moves a selection.
Sourcepub fn viewport(&self, surface: &str) -> Result<Option<Viewport>>
pub fn viewport(&self, surface: &str) -> Result<Option<Viewport>>
The scrolling rows of surface that show now, for keys that move a
page; None for a surface that does not scroll or has not been laid
out yet.
Sourcepub fn set_agent_pointer(
&self,
surface: &str,
pointer: Option<AgentPointer>,
) -> Result<()>
pub fn set_agent_pointer( &self, surface: &str, pointer: Option<AgentPointer>, ) -> Result<()>
Shows an agent at work in surface the way the viewer shows its own
agent acting: an arrow with a name tag that glides to each place set
here (it jumps under reduced motion) and plays a press when
pointer.press is set. Report what the agent does, such as the
clicks it sends an embedded page; the viewer draws the pointer over
the surface, clipped to it. None removes it. Invalid for a place
outside the surface, Unavailable while the viewer has no cell
pixel size. Stays until set again.