Skip to main content

Command

Struct Command 

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

Kitty graphics protocol APC (Application Programming Command).

See documentation.

Implementations§

Source§

impl Command

Source

pub fn add_control<ControlT>(&mut self, code: char, value: ControlT)
where ControlT: Into<ControlValue>,

Add control.

Source

pub fn with_control<ControlT>(self, code: char, value: ControlT) -> Self
where ControlT: Into<ControlValue>,

Add control.

Chainable.

Examples found in repository?
examples/simple.rs (line 9)
6fn main() {
7    Command::default()
8        // quiet (suppress OK response)
9        .with_control('q', 1)
10        // action = transmit and place
11        .with_control('a', 'T')
12        // format = PNG
13        .with_control('f', 100)
14        // transmission medium = file
15        .with_control('t', 'f')
16        .execute_with_path_payload(FILE)
17        .expect("execute_with_path_payload");
18}
More examples
Hide additional examples
examples/response.rs (line 10)
3fn main() {
4    println!("Kitty supported: {}", Command::is_supported().expect("is_supported"));
5
6    // This query should always return OK
7
8    let response = Command::default()
9        // Action = query
10        .with_control('a', 'q')
11        // Image ID
12        .with_control('i', 1)
13        .with_expect_response()
14        .execute()
15        .expect("execute")
16        .expect("response");
17
18    if response.is_ok() {
19        println!("OK!");
20    }
21
22    // This command should always return an error
23
24    let response = Command::default()
25        // Image ID
26        .with_control('i', 1)
27        // Transmission medium = shared memory object
28        .with_control('t', 's')
29        .with_expect_response()
30        .execute_with_payload(b"not a shared memory object")
31        .expect("execute_with_payload")
32        .expect("response");
33
34    println!("Error: {}", response.message.expect("message"));
35}
Source

pub fn set_expect_response(&mut self)

Set whether we expect a response.

Source

pub fn with_expect_response(self) -> Self

Set whether we expect a response.

Chainable.

Examples found in repository?
examples/response.rs (line 13)
3fn main() {
4    println!("Kitty supported: {}", Command::is_supported().expect("is_supported"));
5
6    // This query should always return OK
7
8    let response = Command::default()
9        // Action = query
10        .with_control('a', 'q')
11        // Image ID
12        .with_control('i', 1)
13        .with_expect_response()
14        .execute()
15        .expect("execute")
16        .expect("response");
17
18    if response.is_ok() {
19        println!("OK!");
20    }
21
22    // This command should always return an error
23
24    let response = Command::default()
25        // Image ID
26        .with_control('i', 1)
27        // Transmission medium = shared memory object
28        .with_control('t', 's')
29        .with_expect_response()
30        .execute_with_payload(b"not a shared memory object")
31        .expect("execute_with_payload")
32        .expect("response");
33
34    println!("Error: {}", response.message.expect("message"));
35}
Source

pub fn execute(&self) -> Result<Option<Response>>

Execute.

If we are expecting a response then we will wait for it.

Examples found in repository?
examples/response.rs (line 14)
3fn main() {
4    println!("Kitty supported: {}", Command::is_supported().expect("is_supported"));
5
6    // This query should always return OK
7
8    let response = Command::default()
9        // Action = query
10        .with_control('a', 'q')
11        // Image ID
12        .with_control('i', 1)
13        .with_expect_response()
14        .execute()
15        .expect("execute")
16        .expect("response");
17
18    if response.is_ok() {
19        println!("OK!");
20    }
21
22    // This command should always return an error
23
24    let response = Command::default()
25        // Image ID
26        .with_control('i', 1)
27        // Transmission medium = shared memory object
28        .with_control('t', 's')
29        .with_expect_response()
30        .execute_with_payload(b"not a shared memory object")
31        .expect("execute_with_payload")
32        .expect("response");
33
34    println!("Error: {}", response.message.expect("message"));
35}
Source

pub fn execute_with_payload(&self, payload: &[u8]) -> Result<Option<Response>>

Execute with payload.

If we are expecting a response then we will wait for it.

Examples found in repository?
examples/response.rs (line 30)
3fn main() {
4    println!("Kitty supported: {}", Command::is_supported().expect("is_supported"));
5
6    // This query should always return OK
7
8    let response = Command::default()
9        // Action = query
10        .with_control('a', 'q')
11        // Image ID
12        .with_control('i', 1)
13        .with_expect_response()
14        .execute()
15        .expect("execute")
16        .expect("response");
17
18    if response.is_ok() {
19        println!("OK!");
20    }
21
22    // This command should always return an error
23
24    let response = Command::default()
25        // Image ID
26        .with_control('i', 1)
27        // Transmission medium = shared memory object
28        .with_control('t', 's')
29        .with_expect_response()
30        .execute_with_payload(b"not a shared memory object")
31        .expect("execute_with_payload")
32        .expect("response");
33
34    println!("Error: {}", response.message.expect("message"));
35}
Source

pub fn execute_with_payload_from<ReadT>( &self, payload: ReadT, ) -> Result<Option<Response>>
where ReadT: Read,

Execute with payload from a reader.

If we are expecting a response then we will wait for it.

Source

pub fn execute_with_path_payload<PathT>( &self, path: PathT, ) -> Result<Option<Response>>
where PathT: AsRef<Path>,

Execute with path payload.

If we are expecting a response then we will wait for it.

Examples found in repository?
examples/simple.rs (line 16)
6fn main() {
7    Command::default()
8        // quiet (suppress OK response)
9        .with_control('q', 1)
10        // action = transmit and place
11        .with_control('a', 'T')
12        // format = PNG
13        .with_control('f', 100)
14        // transmission medium = file
15        .with_control('t', 'f')
16        .execute_with_path_payload(FILE)
17        .expect("execute_with_path_payload");
18}
Source

pub fn is_supported() -> Result<bool>

Whether the terminal supports the Kitty graphics protocol.

Examples found in repository?
examples/response.rs (line 4)
3fn main() {
4    println!("Kitty supported: {}", Command::is_supported().expect("is_supported"));
5
6    // This query should always return OK
7
8    let response = Command::default()
9        // Action = query
10        .with_control('a', 'q')
11        // Image ID
12        .with_control('i', 1)
13        .with_expect_response()
14        .execute()
15        .expect("execute")
16        .expect("response");
17
18    if response.is_ok() {
19        println!("OK!");
20    }
21
22    // This command should always return an error
23
24    let response = Command::default()
25        // Image ID
26        .with_control('i', 1)
27        // Transmission medium = shared memory object
28        .with_control('t', 's')
29        .with_expect_response()
30        .execute_with_payload(b"not a shared memory object")
31        .expect("execute_with_payload")
32        .expect("response");
33
34    println!("Error: {}", response.message.expect("message"));
35}

Trait Implementations§

Source§

impl Clone for Command

Source§

fn clone(&self) -> Command

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 Debug for Command

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Command

Source§

fn default() -> Command

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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.