Skip to content

Commit

Permalink
ensuring that output buffers are visible when they are appended to
Browse files Browse the repository at this point in the history
  • Loading branch information
sminez committed Nov 15, 2024
1 parent f4490c2 commit a503f46
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 34 deletions.
18 changes: 5 additions & 13 deletions src/buffer/buffers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,26 +259,18 @@ impl Buffers {
}

/// Append to the +output buffer assigned to the buffer with provided id.
pub(crate) fn write_output_for_buffer(
&mut self,
id: usize,
s: String,
cwd: &Path,
) -> Option<BufferId> {
pub(crate) fn write_output_for_buffer(&mut self, id: usize, s: String, cwd: &Path) -> BufferId {
let key = match self.with_id(id) {
Some(b) => b.output_file_key(cwd),
None => format!("{}/DEFAULT_OUTPUT_BUFFER", cwd.display()),
};

match self
.inner
.iter_mut()
.find(|(_, b)| b.kind == BufferKind::Output(key.clone()))
{
let k = BufferKind::Output(key.clone());
match self.inner.iter_mut().find(|(_, b)| b.kind == k) {
Some((_, b)) => {
b.append(s, Source::Fsys);

None
b.id
}

None => {
Expand All @@ -288,7 +280,7 @@ impl Buffers {
self.record_jump_position();
self.inner.insert(b);

Some(id)
id
}
}
}
Expand Down
14 changes: 8 additions & 6 deletions src/editor/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,13 +713,15 @@ where
}

if !buf.is_empty() {
let s = match String::from_utf8(buf) {
Ok(s) => s,
Err(e) => {
error!(%e, "edit command produced invalid utf8 output");
return;
}
};
let id = self.active_buffer_id();
self.layout.write_output_for_buffer(
id,
String::from_utf8(buf).unwrap(),
&self.cwd,
true,
);
self.layout.write_output_for_buffer(id, s, &self.cwd);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/editor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ where
}),

AppendOutput { id, s } => {
self.layout.write_output_for_buffer(id, s, &self.cwd, true);
self.layout.write_output_for_buffer(id, s, &self.cwd);
default_handled();
}

Expand Down Expand Up @@ -365,7 +365,7 @@ where
match action {
AppendToOutputBuffer { bufid, content } => self
.layout
.write_output_for_buffer(bufid, content, &self.cwd, true),
.write_output_for_buffer(bufid, content, &self.cwd),
ChangeDirectory { path } => self.change_directory(path),
CommandMode => self.command_mode(),
DeleteBuffer { force } => self.delete_buffer(self.active_buffer_id(), force),
Expand Down
19 changes: 6 additions & 13 deletions src/ui/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,19 +268,12 @@ impl Layout {
None
}

pub(crate) fn write_output_for_buffer(
&mut self,
id: usize,
s: String,
cwd: &Path,
new_window: bool,
) {
if let Some(id) = self.buffers.write_output_for_buffer(id, s, cwd) {
if new_window {
self.show_buffer_in_new_window(id);
} else {
self.show_buffer_in_active_window(id);
}
pub(crate) fn write_output_for_buffer(&mut self, id: usize, s: String, cwd: &Path) {
let id = self.buffers.write_output_for_buffer(id, s, cwd);
if !self.buffer_is_visible(id) {
self.show_buffer_in_new_window(id);
} else {
self.show_buffer_in_active_window(id);
}
}

Expand Down

0 comments on commit a503f46

Please sign in to comment.