pub struct Command { /* private fields */ }Expand description
Kitty graphics protocol APC (Application Programming Command).
See documentation.
Implementations§
Source§impl Command
impl Command
Sourcepub fn add_control<ControlT>(&mut self, code: char, value: ControlT)where
ControlT: Into<ControlValue>,
pub fn add_control<ControlT>(&mut self, code: char, value: ControlT)where
ControlT: Into<ControlValue>,
Add control.
Sourcepub fn with_control<ControlT>(self, code: char, value: ControlT) -> Selfwhere
ControlT: Into<ControlValue>,
pub fn with_control<ControlT>(self, code: char, value: ControlT) -> Selfwhere
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
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}Sourcepub fn set_expect_response(&mut self)
pub fn set_expect_response(&mut self)
Set whether we expect a response.
Sourcepub fn with_expect_response(self) -> Self
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}Sourcepub fn execute(&self) -> Result<Option<Response>>
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}Sourcepub fn execute_with_payload(&self, payload: &[u8]) -> Result<Option<Response>>
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}Sourcepub fn execute_with_payload_from<ReadT>(
&self,
payload: ReadT,
) -> Result<Option<Response>>where
ReadT: Read,
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.
Sourcepub fn execute_with_path_payload<PathT>(
&self,
path: PathT,
) -> Result<Option<Response>>
pub fn execute_with_path_payload<PathT>( &self, path: PathT, ) -> Result<Option<Response>>
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}Sourcepub fn is_supported() -> Result<bool>
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§
Auto Trait Implementations§
impl Freeze for Command
impl RefUnwindSafe for Command
impl Send for Command
impl Sync for Command
impl Unpin for Command
impl UnsafeUnpin for Command
impl UnwindSafe for Command
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more