Skip to main content

KittyBuilder

Struct KittyBuilder 

Source
pub struct KittyBuilder { /* private fields */ }

Implementations§

Source§

impl KittyBuilder

Source

pub fn new() -> Self

Source

pub fn socket_path<P: AsRef<Path>>(self, path: P) -> Self

Examples found in repository?
examples/test-connectivity.rs (line 12)
4async fn main() -> Result<(), Box<dyn std::error::Error>> {
5    // Find kitty socket
6    let socket_path = find_kitty_socket()?;
7
8    println!("Connecting to: {}", socket_path);
9
10    // Test basic connection
11    let mut kitty = Kitty::builder()
12        .socket_path(&socket_path)
13        .connect()
14        .await
15        .map_err(|e| format!("Connection failed: {}", e))?;
16
17    println!("✓ Connected successfully!");
18
19    // Test sending a simple command
20    use kitty_rc::command::CommandBuilder;
21
22    let cmd = CommandBuilder::new("ls")
23        .build();
24
25    match kitty.execute(&cmd).await {
26        Ok(response) => {
27            println!("✓ Command executed successfully!");
28            if let Some(data) = response.data {
29                println!("Response: {}", data);
30            }
31        }
32        Err(e) => {
33            eprintln!("✗ Command failed: {}", e);
34        }
35    }
36
37    Ok(())
38}
More examples
Hide additional examples
examples/test-encrypted.rs (line 13)
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6    // Find kitty socket
7    let socket_path = find_kitty_socket()?;
8
9    println!("Connecting to: {}", socket_path);
10
11    // Test encrypted connection
12    let mut kitty = Kitty::builder()
13        .socket_path(&socket_path)
14        .password(&read_password()?)
15        .connect()
16        .await
17        .map_err(|e| format!("Connection failed: {}", e))?;
18
19    println!("✓ Connected successfully (encrypted)!");
20
21    // Test sending a simple command
22    use kitty_rc::command::CommandBuilder;
23
24    let cmd = CommandBuilder::new("ls")
25        .build();
26
27    match kitty.execute(&cmd).await {
28        Ok(response) => {
29            println!("✓ Encrypted command executed successfully!");
30            println!("  Response: {:?}", response);
31        }
32        Err(e) => {
33            eprintln!("✗ Encrypted command failed: {}", e);
34            if let Some(source) = Error::source(&e) {
35                eprintln!("  Error source: {}", source);
36            }
37        }
38    }
39
40    Ok(())
41}
Source

pub fn timeout(self, duration: Duration) -> Self

Source

pub fn password(self, password: impl Into<String>) -> Self

Examples found in repository?
examples/test-encrypted.rs (line 14)
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6    // Find kitty socket
7    let socket_path = find_kitty_socket()?;
8
9    println!("Connecting to: {}", socket_path);
10
11    // Test encrypted connection
12    let mut kitty = Kitty::builder()
13        .socket_path(&socket_path)
14        .password(&read_password()?)
15        .connect()
16        .await
17        .map_err(|e| format!("Connection failed: {}", e))?;
18
19    println!("✓ Connected successfully (encrypted)!");
20
21    // Test sending a simple command
22    use kitty_rc::command::CommandBuilder;
23
24    let cmd = CommandBuilder::new("ls")
25        .build();
26
27    match kitty.execute(&cmd).await {
28        Ok(response) => {
29            println!("✓ Encrypted command executed successfully!");
30            println!("  Response: {:?}", response);
31        }
32        Err(e) => {
33            eprintln!("✗ Encrypted command failed: {}", e);
34            if let Some(source) = Error::source(&e) {
35                eprintln!("  Error source: {}", source);
36            }
37        }
38    }
39
40    Ok(())
41}
Source

pub fn public_key(self, public_key: impl Into<String>) -> Self

Set kitty’s public key explicitly.

Format: 1:<base85_encoded_key> where 1 is protocol version.

When set, this key is used instead of querying KITTY_PUBLIC_KEY env var or kitty-pubkey-db database.

Example:

use kitty_rc::Kitty;
let kitty = Kitty::builder()
    .socket_path("/run/user/1000/kitty-12345.sock")
    .password("your-password")
    .public_key("1:z3;{}!NzNzgiXreB&ywA!8y1H8hq^$cMG!OE$QNa")
    .connect()
    .await?;
Source

pub async fn connect(self) -> Result<Kitty, KittyError>

Connect to kitty instance with configured authentication.

Public key resolution order (when password is set):

  1. Explicit key set via .public_key() method
  2. Query kitty-pubkey-db database (extracts PID from socket path)
  3. KITTY_PUBLIC_KEY environment variable (set by kitty when launching subprocesses)

When no password is set, no encryption is used.

Examples found in repository?
examples/test-connectivity.rs (line 13)
4async fn main() -> Result<(), Box<dyn std::error::Error>> {
5    // Find kitty socket
6    let socket_path = find_kitty_socket()?;
7
8    println!("Connecting to: {}", socket_path);
9
10    // Test basic connection
11    let mut kitty = Kitty::builder()
12        .socket_path(&socket_path)
13        .connect()
14        .await
15        .map_err(|e| format!("Connection failed: {}", e))?;
16
17    println!("✓ Connected successfully!");
18
19    // Test sending a simple command
20    use kitty_rc::command::CommandBuilder;
21
22    let cmd = CommandBuilder::new("ls")
23        .build();
24
25    match kitty.execute(&cmd).await {
26        Ok(response) => {
27            println!("✓ Command executed successfully!");
28            if let Some(data) = response.data {
29                println!("Response: {}", data);
30            }
31        }
32        Err(e) => {
33            eprintln!("✗ Command failed: {}", e);
34        }
35    }
36
37    Ok(())
38}
More examples
Hide additional examples
examples/test-encrypted.rs (line 15)
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6    // Find kitty socket
7    let socket_path = find_kitty_socket()?;
8
9    println!("Connecting to: {}", socket_path);
10
11    // Test encrypted connection
12    let mut kitty = Kitty::builder()
13        .socket_path(&socket_path)
14        .password(&read_password()?)
15        .connect()
16        .await
17        .map_err(|e| format!("Connection failed: {}", e))?;
18
19    println!("✓ Connected successfully (encrypted)!");
20
21    // Test sending a simple command
22    use kitty_rc::command::CommandBuilder;
23
24    let cmd = CommandBuilder::new("ls")
25        .build();
26
27    match kitty.execute(&cmd).await {
28        Ok(response) => {
29            println!("✓ Encrypted command executed successfully!");
30            println!("  Response: {:?}", response);
31        }
32        Err(e) => {
33            eprintln!("✗ Encrypted command failed: {}", e);
34            if let Some(source) = Error::source(&e) {
35                eprintln!("  Error source: {}", source);
36            }
37        }
38    }
39
40    Ok(())
41}

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> 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> Same for T

Source§

type Output = T

Should always be Self
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.