Client

Struct Client 

Source
pub struct Client { /* private fields */ }
Expand description

Handles all interactions between the ccanvas server and your code.

Implementations§

Source§

impl Client

Source

pub async fn new(config: ClientConfig) -> Self

Create a new instance of self, will panic if connection fails.

Source

pub fn reqid() -> u32

Generates a never-before-seen unique request ID.

Source

pub async fn recv(&self) -> Event

Waits for an event from ccanvas.

There should only be one active recv() for each Client, more than one recv() at a time leads to undetermined behaviour on who gets the event.

Source

pub async fn send(&self, req: Request) -> ResponseContent

Send a request and waits for response This is a private method as the task specific functions should be used instead.

Source§

impl Client

Task specific functions.

Source

pub async fn subscribe<T: Into<(Subscription, Option<u32>)>>( &self, channel: T, ) -> ResponseContent

Subscribe to one channel.

Source

pub async fn subscribe_multiple<T: Into<(Subscription, Option<u32>)>>( &self, channels: Vec<T>, ) -> ResponseContent

Subscribe to multiple channels at once.

Source

pub async fn unsubscribe(&self, channel: Subscription) -> ResponseContent

Unsubscribe from one channels.

Source

pub async fn exit(&self) -> ResponseContent

Tell the ccanvas server to exit immetiately.

Alias to self.drop_component(Discriminator::master())

Source

pub async fn drop_component(&self, discrim: Discriminator) -> ResponseContent

Drop a single component.

Source

pub fn setchar(&self, x: u32, y: u32, c: char)

Add a set character task to the render queue.

Source

pub fn setcharcoloured(&self, x: u32, y: u32, c: char, fg: Colour, bg: Colour)

Add a set character (coloured) task to the render queue.

Source

pub fn setcursorstyle(&self, style: CursorStyle)

Add a set cursor style task to render queue.

Source

pub fn showcursor(&self)

Add a show cursor task to render queue.

Source

pub fn hidecursor(&self)

Add a hide cursor task to render queue.

Source

pub fn clear_all(&self)

Add a clear all task to render queue.

Source

pub fn clear_area(&self, x: u32, y: u32, width: u32, height: u32)

Add a clear area task to render queue.

Source

pub async fn renderall(&self) -> ResponseContent

Flush and complete all tasks in render queue.

Source

pub async fn spawn_at( &self, label: String, command: String, args: Vec<String>, parent: Discriminator, ) -> ResponseContent

Spawn a new process at a specific space.

Source

pub async fn spawn_with_env_at( &self, label: String, command: String, args: Vec<String>, parent: Discriminator, env: BTreeMap<String, String>, ) -> ResponseContent

Spawn a new process at a specific space with environment vars

Source

pub async fn spawn( &self, label: String, command: String, args: Vec<String>, ) -> ResponseContent

Spawn a new process in the same parent space.

Source

pub async fn spawn_with_env( &self, label: String, command: String, args: Vec<String>, env: BTreeMap<String, String>, ) -> ResponseContent

Spawn a new process in the same parent space.

Source

pub async fn focus_at(&self, discrim: Discriminator) -> ResponseContent

Set focus to a space.

Source

pub async fn new_space( &self, parent: Discriminator, label: String, ) -> ResponseContent

Create a new space.

Source

pub async fn message( &self, target: Discriminator, content: Value, tag: String, ) -> ResponseContent

Send a message to a component.

If the selected component is a space, then all its members (including subspaces) will also recieve the message. Including the sender copmonent.

Source

pub async fn broadcast(&self, content: Value, tag: String) -> ResponseContent

Send a message to all components, including self.

Alias to client.message(Discriminator::master(), message)

Source

pub fn discrim(&self) -> &Discriminator

Get the discriminator of the current (process) component.

Source

pub async fn is_focused(&self) -> bool

Check if parent space is in focus.

Returns true if it is the focused element, or child of the focused element.

Source

pub async fn focused(&self) -> Discriminator

Returns discriminator of the currently focused component.

Source

pub async fn term_size(&self) -> (u32, u32)

Returns terminal size (x, y)

Source

pub async fn current_directory(&self) -> PathBuf

Returns the full path to which the ccanvas command is ran.

Source

pub async fn watch( &self, label: String, target: Discriminator, ) -> ResponseContent

Subscribe to changes of a variable.

Source

pub async fn unwatch( &self, label: String, target: Discriminator, ) -> ResponseContent

Remove subscription to changes of a variable.

Source

pub async fn watch_self(&self, label: String) -> ResponseContent

Subscribe to changes of a variable owned by the current (process) component.

Source

pub async fn unwatch_self(&self, label: String) -> ResponseContent

Remove subscription to changes of a variable owned by the current (process) component.

Source

pub async fn set( &self, label: String, target: Discriminator, value: Value, ) -> ResponseContent

Set a variable.

Source

pub async fn set_self(&self, label: String, value: Value) -> ResponseContent

Set a variable owned by the current (process) component.

Source

pub async fn get_raw( &self, label: String, target: Discriminator, ) -> ResponseContent

Get a variable with raw responses.

Source

pub async fn get(&self, label: String, target: Discriminator) -> Option<Value>

Get a variable, returning an Option<Value>.

Source

pub async fn get_self(&self, label: String) -> Option<Value>

Get a variable owned by the current (process) component, returning an Option<Value>.

Source

pub async fn remove( &self, label: String, target: Discriminator, ) -> ResponseContent

Remove a variable.

Source

pub async fn remove_self(&self, label: String) -> ResponseContent

Remove a variable owned by the current (process) component.

Source

pub async fn suppress_at( &self, channel: Subscription, priority: u32, target: Discriminator, ) -> ResponseContent

Suppress all subscriptions of that channel with a lower than specified priority

Source

pub async fn unsuppress_at( &self, channel: Subscription, id: u32, target: Discriminator, ) -> ResponseContent

Remove suppress for a single suppressor

Source

pub async fn suppress( &self, channel: Subscription, priority: u32, target: Discriminator, ) -> Option<LifetimeSuppressor>

Suppress a channel within the lifetime of the returned LifetimeSuppressor

Source

pub async fn unsuppress(&self, suppressor: LifetimeSuppressor) -> bool

Remove suppress using a lifetime suppressor.

Source§

impl Client

Source

pub async fn spawn_layouted( &self, label: String, command: String, args: Vec<String>, ) -> ResponseContent

Spawn a new process in the same parent space to use ccanvas-layout

Source

pub async fn spawn_at_layouted( &self, label: String, command: String, args: Vec<String>, parent: Discriminator, ) -> ResponseContent

Spawn a new process at a specific space to use ccanvas-layout

Source

pub async fn spawn_with_env_at_layouted( &self, label: String, command: String, args: Vec<String>, parent: Discriminator, env: BTreeMap<String, String>, ) -> ResponseContent

Spawn a new process at a specific space with additional env to use ccanvas-layout

Source

pub async fn spawn_with_env_layouted( &self, label: String, command: String, args: Vec<String>, env: BTreeMap<String, String>, ) -> ResponseContent

Spawn a new process at a specific space with additional env to use ccanvas-layout

Source§

impl Client

Source

pub fn layout(&self, discrim: Discriminator) -> LayoutComponent

Return the LayoutComponent struct from a discriminator

Source

pub async fn layout_add( &self, layout: Discriminator, at: Vec<Direction>, split: Direction, constraint_1: Constraint, constraint_2: Constraint, component: Option<Discriminator>, border: Option<Border>, ) -> ResponseContent

Add a new layout section

Source

pub async fn layout_add_blank( &self, layout: Discriminator, at: Vec<Direction>, split: Direction, constraint_1: Constraint, constraint_2: Constraint, border: Option<Border>, ) -> ResponseContent

Add a new blank layout section

Source

pub async fn layout_add_component( &self, layout: Discriminator, at: Vec<Direction>, split: Direction, constraint_1: Constraint, constraint_2: Constraint, component: Discriminator, border: Option<Border>, ) -> ResponseContent

Add a new component layout section

Source

pub async fn layout_add_below( &self, layout: Discriminator, at: Vec<Direction>, constraint_top: Constraint, constraint_bottom: Constraint, component: Option<Discriminator>, border: Option<Border>, ) -> ResponseContent

Add a new layout section below target

Source

pub async fn layout_add_above( &self, layout: Discriminator, at: Vec<Direction>, constraint_top: Constraint, constraint_bottom: Constraint, component: Option<Discriminator>, border: Option<Border>, ) -> ResponseContent

Add a new layout section above target

Source

pub async fn layout_add_left( &self, layout: Discriminator, at: Vec<Direction>, constraint_left: Constraint, constraint_right: Constraint, component: Option<Discriminator>, border: Option<Border>, ) -> ResponseContent

Add a new layout section to the left of target

Source

pub async fn layout_add_right( &self, layout: Discriminator, at: Vec<Direction>, constraint_left: Constraint, constraint_right: Constraint, component: Option<Discriminator>, border: Option<Border>, ) -> ResponseContent

Add a new layout section to the right of target

Source

pub async fn layout_add_bordered( &self, layout: Discriminator, at: Vec<Direction>, split: Direction, constraint_1: Constraint, constraint_2: Constraint, component: Option<Discriminator>, border: Border, ) -> ResponseContent

Add a new bordered layout section

Source

pub async fn layout_add_unbordered( &self, layout: Discriminator, at: Vec<Direction>, split: Direction, constraint_1: Constraint, constraint_2: Constraint, component: Option<Discriminator>, ) -> ResponseContent

Add a new unbordered layout section

Source§

impl Client

Source

pub async fn layout_add_blank_above( &self, layout: Discriminator, at: Vec<Direction>, constraint_top: Constraint, constraint_bottom: Constraint, border: Option<Border>, ) -> ResponseContent

Add a new blank layout section above target

Source

pub async fn layout_add_blank_below( &self, layout: Discriminator, at: Vec<Direction>, constraint_top: Constraint, constraint_bottom: Constraint, border: Option<Border>, ) -> ResponseContent

Add a new blank layout section below target

Source

pub async fn layout_add_blank_left( &self, layout: Discriminator, at: Vec<Direction>, constraint_left: Constraint, constraint_right: Constraint, border: Option<Border>, ) -> ResponseContent

Add a new blank layout section to the left of target

Source

pub async fn layout_add_blank_right( &self, layout: Discriminator, at: Vec<Direction>, constraint_left: Constraint, constraint_right: Constraint, border: Option<Border>, ) -> ResponseContent

Add a new blank layout section to the right of target

Source

pub async fn layout_add_component_above( &self, layout: Discriminator, at: Vec<Direction>, constraint_top: Constraint, constraint_bottom: Constraint, component: Discriminator, border: Option<Border>, ) -> ResponseContent

Add a new component layout section above target

Source

pub async fn layout_add_component_below( &self, layout: Discriminator, at: Vec<Direction>, constraint_top: Constraint, constraint_bottom: Constraint, component: Discriminator, border: Option<Border>, ) -> ResponseContent

Add a new component layout section below target

Source

pub async fn layout_add_component_left( &self, layout: Discriminator, at: Vec<Direction>, constraint_left: Constraint, constraint_right: Constraint, component: Discriminator, border: Option<Border>, ) -> ResponseContent

Add a new component layout section to the left of target

Source

pub async fn layout_add_component_right( &self, layout: Discriminator, at: Vec<Direction>, constraint_left: Constraint, constraint_right: Constraint, component: Discriminator, border: Option<Border>, ) -> ResponseContent

Add a new component layout section to the right of target

Source

pub async fn layout_add_bordered_above( &self, layout: Discriminator, at: Vec<Direction>, constraint_top: Constraint, constraint_bottom: Constraint, component: Option<Discriminator>, border: Border, ) -> ResponseContent

Add a new bordered layout section above target

Source

pub async fn layout_add_bordered_below( &self, layout: Discriminator, at: Vec<Direction>, constraint_top: Constraint, constraint_bottom: Constraint, component: Option<Discriminator>, border: Border, ) -> ResponseContent

Add a new bordered layout section below target

Source

pub async fn layout_add_bordered_left( &self, layout: Discriminator, at: Vec<Direction>, constraint_left: Constraint, constraint_right: Constraint, component: Option<Discriminator>, border: Border, ) -> ResponseContent

Add a new bordered layout section to the left of target

Source

pub async fn layout_add_bordered_right( &self, layout: Discriminator, at: Vec<Direction>, constraint_left: Constraint, constraint_right: Constraint, component: Option<Discriminator>, border: Border, ) -> ResponseContent

Add a new bordered layout section to the right of target

Source

pub async fn layout_add_unbordered_above( &self, layout: Discriminator, at: Vec<Direction>, constraint_top: Constraint, constraint_bottom: Constraint, component: Option<Discriminator>, ) -> ResponseContent

Add a new unbordered layout section above target

Source

pub async fn layout_add_unbordered_below( &self, layout: Discriminator, at: Vec<Direction>, constraint_top: Constraint, constraint_bottom: Constraint, component: Option<Discriminator>, ) -> ResponseContent

Add a new unbordered layout section below target

Source

pub async fn layout_add_unbordered_left( &self, layout: Discriminator, at: Vec<Direction>, constraint_left: Constraint, constraint_right: Constraint, component: Option<Discriminator>, ) -> ResponseContent

Add a new unbordered layout section to the left of target

Source

pub async fn layout_add_unbordered_right( &self, layout: Discriminator, at: Vec<Direction>, constraint_left: Constraint, constraint_right: Constraint, component: Option<Discriminator>, ) -> ResponseContent

Add a new unbordered layout section to the right of target

Source§

impl Client

Source

pub async fn layout_add_bordered_blank( &self, layout: Discriminator, at: Vec<Direction>, split: Direction, constraint_1: Constraint, constraint_2: Constraint, border: Border, ) -> ResponseContent

Add a new bordered blank layout section

Source

pub async fn layout_add_unbordered_blank( &self, layout: Discriminator, at: Vec<Direction>, split: Direction, constraint_1: Constraint, constraint_2: Constraint, ) -> ResponseContent

Add a new unbordered blank layout section

Source

pub async fn layout_add_bordered_component( &self, layout: Discriminator, at: Vec<Direction>, split: Direction, constraint_1: Constraint, constraint_2: Constraint, component: Discriminator, border: Border, ) -> ResponseContent

Add a new bordered component layout section

Source

pub async fn layout_add_unbordered_component( &self, layout: Discriminator, at: Vec<Direction>, split: Direction, constraint_1: Constraint, constraint_2: Constraint, component: Discriminator, ) -> ResponseContent

Add a new unbordered component layout section

Source§

impl Client

Source

pub async fn layout_add_bordered_blank_above( &self, layout: Discriminator, at: Vec<Direction>, constraint_top: Constraint, constraint_bottom: Constraint, border: Border, ) -> ResponseContent

Add a new bordered blank layout section above target

Source

pub async fn layout_add_bordered_blank_below( &self, layout: Discriminator, at: Vec<Direction>, constraint_top: Constraint, constraint_bottom: Constraint, border: Border, ) -> ResponseContent

Add a new bordered blank layout section below target

Source

pub async fn layout_add_bordered_blank_left( &self, layout: Discriminator, at: Vec<Direction>, constraint_left: Constraint, constraint_right: Constraint, border: Border, ) -> ResponseContent

Add a new bordered blank layout section to the left of target

Source

pub async fn layout_add_bordered_blank_right( &self, layout: Discriminator, at: Vec<Direction>, constraint_left: Constraint, constraint_right: Constraint, border: Border, ) -> ResponseContent

Add a new bordered blank layout section to the right of target

Source

pub async fn layout_add_bordered_component_above( &self, layout: Discriminator, at: Vec<Direction>, constraint_top: Constraint, constraint_bottom: Constraint, component: Discriminator, border: Border, ) -> ResponseContent

Add a new bordered component layout section above target

Source

pub async fn layout_add_bordered_component_below( &self, layout: Discriminator, at: Vec<Direction>, constraint_top: Constraint, constraint_bottom: Constraint, component: Discriminator, border: Border, ) -> ResponseContent

Add a new bordered component layout section below target

Source

pub async fn layout_add_bordered_component_left( &self, layout: Discriminator, at: Vec<Direction>, constraint_left: Constraint, constraint_right: Constraint, component: Discriminator, border: Border, ) -> ResponseContent

Add a new bordered component layout section to the left of target

Source

pub async fn layout_add_bordered_component_right( &self, layout: Discriminator, at: Vec<Direction>, constraint_left: Constraint, constraint_right: Constraint, component: Discriminator, border: Border, ) -> ResponseContent

Add a new bordered component layout section to the right of target

Source

pub async fn layout_add_unbordered_blank_above( &self, layout: Discriminator, at: Vec<Direction>, constraint_top: Constraint, constraint_bottom: Constraint, ) -> ResponseContent

Add a new unbordered blank layout section above target

Source

pub async fn layout_add_unbordered_blank_below( &self, layout: Discriminator, at: Vec<Direction>, constraint_top: Constraint, constraint_bottom: Constraint, ) -> ResponseContent

Add a new unbordered blank layout section below target

Source

pub async fn layout_add_unbordered_blank_left( &self, layout: Discriminator, at: Vec<Direction>, constraint_left: Constraint, constraint_right: Constraint, ) -> ResponseContent

Add a new unbordered blank layout section to the left of target

Source

pub async fn layout_add_unbordered_blank_right( &self, layout: Discriminator, at: Vec<Direction>, constraint_left: Constraint, constraint_right: Constraint, ) -> ResponseContent

Add a new unbordered blank layout section to the right of target

Source

pub async fn layout_add_unbordered_component_above( &self, layout: Discriminator, at: Vec<Direction>, constraint_top: Constraint, constraint_bottom: Constraint, component: Discriminator, ) -> ResponseContent

Add a new unbordered component layout section above target

Source

pub async fn layout_add_unbordered_component_below( &self, layout: Discriminator, at: Vec<Direction>, constraint_top: Constraint, constraint_bottom: Constraint, component: Discriminator, ) -> ResponseContent

Add a new unbordered component layout section below target

Source

pub async fn layout_add_unbordered_component_left( &self, layout: Discriminator, at: Vec<Direction>, constraint_left: Constraint, constraint_right: Constraint, component: Discriminator, ) -> ResponseContent

Add a new unbordered component layout section to the left of target

Source

pub async fn layout_add_unbordered_component_right( &self, layout: Discriminator, at: Vec<Direction>, constraint_left: Constraint, constraint_right: Constraint, component: Discriminator, ) -> ResponseContent

Add a new unbordered component layout section to the right of target

Source§

impl Client

Source

pub async fn layout_remove( &self, layout: Discriminator, at: Vec<Direction>, ) -> ResponseContent

Remove a layout section

Source

pub async fn layout_set( &self, layout: Discriminator, at: Vec<Direction>, overwrite: Layout, ) -> ResponseContent

Overwrite a layout section

Source

pub async fn layout_set_root( &self, layout: Discriminator, overwrite: Layout, ) -> ResponseContent

Overwrite the root layout section

Source§

impl Client

Source

pub async fn enable_saver(&self, min_width: u32, min_height: u32)

Enable screen saver with a specific dimension.

Source

pub async fn disable_saver(&self)

Disable screeen saver.

Source

pub async fn saver_ison(&self) -> bool

Returns true if the overlay is currently drawn.

Source§

impl Client

Source

pub fn scroll(&self, discrim: Discriminator) -> ScrollComponent

Returns a scroll component from a discrim of ccanvas-scroll

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Drop for Client

Let the ccanvas server know when the client gets dropped.

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.