Skip to content

Commit

Permalink
feat: allow setting the current buffer by writing to buffers/current
Browse files Browse the repository at this point in the history
  • Loading branch information
sminez committed Nov 15, 2024
1 parent 07b1c38 commit f4490c2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
5 changes: 0 additions & 5 deletions crates/ad_repl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ include = [
keywords = [ "terminal", "editor", "text-editor", ]
categories = [ "development-tools", "text-editors", "command-line-utilities" ]

[profile.release]
strip = true
lto = true


[dependencies]
ad_client = { version = "0.2", path = "../ad_client" }
subprocess = "0.2.9"
2 changes: 1 addition & 1 deletion data/lib/ad.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ adLog() { 9p read ad/log; }
currentBufferId() { 9p read ad/buffers/current; }

# Set focus to the buffer with the specified id
focusBuffer() { adCtl "buffer $1"; }
focusBuffer() { echo "$1" | 9p write ad/buffers/current; }

# Clear the contents of the current buffer
clearBuffer() {
Expand Down
22 changes: 20 additions & 2 deletions src/fsys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
//! body
//! event
//! ```
use crate::{config_handle, input::Event};
use crate::{config_handle, editor::Action, input::Event};
use ninep::{
fs::{FileMeta, IoUnit, Mode, Perm, Stat},
server::{socket_path, ClientId, ReadOutcome, Serve9p, Server},
Expand Down Expand Up @@ -267,6 +267,23 @@ impl AdFs {
Ok(n_bytes)
}

fn set_active_buffer(&mut self, s: String) -> Result<usize> {
let id: usize = match s.trim().parse() {
Ok(n) => n,
Err(_) => {
trace!("invalid buffer id submitted to buffers/current: {s}");
return Ok(0);
}
};

if let Err(e) = self.tx.send(Event::Action(Action::FocusBuffer { id })) {
error!("unable to send event to main loop: {e}");
return Ok(0);
}

Ok(s.len())
}

fn minibuffer_read(&mut self, offset: usize, count: usize) -> ReadOutcome {
match &mut self.minibuffer_content {
MiniBufferContent::Buffering(lines_bytes) => {
Expand Down Expand Up @@ -540,8 +557,9 @@ impl Serve9p for AdFs {
},

MINIBUFFER_QID => self.minibuffer_write(s),
CURRENT_BUFFER_QID => self.set_active_buffer(s),

CURRENT_BUFFER_QID | LOG_FILE_QID | INDEX_BUFFER_QID => Err(E_NOT_ALLOWED.to_string()),
LOG_FILE_QID | INDEX_BUFFER_QID => Err(E_NOT_ALLOWED.to_string()),

qid => self.buffer_nodes.write(qid, s, offset),
}
Expand Down

1 comment on commit f4490c2

@sminez
Copy link
Owner Author

@sminez sminez commented on f4490c2 Nov 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davcam you mentioned that you expected this to work and I think you're correct that it should.

Please sign in to comment.