Skip to content

Commit

Permalink
feat(ad_client) adding some initial methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sminez committed Sep 8, 2024
1 parent a9bc58d commit aee8e13
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
11 changes: 11 additions & 0 deletions crates/ad_client/examples/demo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//! A simple demo of the client behaviour
use ad_client::Client;
use std::io;

fn main() -> io::Result<()> {
let mut client = Client::new()?;
client.echo("hello, world!")?;
client.open("README.md")?;

Ok(())
}
26 changes: 24 additions & 2 deletions crates/ad_client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! A simple 9p based client for interacting with ad
use ninep::client;
use std::io;
use std::{fmt, io};

/// A simple 9p client for ad
#[derive(Debug)]
Expand All @@ -15,8 +15,30 @@ impl Client {
})
}

/// Get the currently active buffer id
/// Get the currently active buffer id.
pub fn current_buffer(&mut self) -> io::Result<String> {
self.inner.read_str("buffers/current")
}

fn _ctl(&mut self, command: &str, args: impl fmt::Display) -> io::Result<()> {
self.inner
.write("ctl", 0, format!("{command} {args}").as_bytes())?;

Ok(())
}

/// Echo a string message in the status line.
pub fn echo(&mut self, msg: impl fmt::Display) -> io::Result<()> {
self._ctl("echo", msg)
}

/// Open the requested file.
pub fn open(&mut self, path: impl Into<String>) -> io::Result<()> {
self._ctl("open", path.into())
}

/// Reload the currently active buffer.
pub fn reload_current_buffer(&mut self) -> io::Result<()> {
self._ctl("reload", "")
}
}

0 comments on commit aee8e13

Please sign in to comment.