aboutsummaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
authordenis <denismaximov98@gmail.com>2021-01-29 06:24:59 +0200
committerdenis <denismaximov98@gmail.com>2021-01-29 06:24:59 +0200
commit6a3481f54f0ee789ceeb994d8f302e3ce119c031 (patch)
tree60d4ad8d08c2349571d29d68c357ac07c6acce63 /src/common
parentwip: oops shouldn't forget that (diff)
parentfeat(statusbar): max status bar height (#156) (diff)
downloadsl0ppij-6a3481f54f0ee789ceeb994d8f302e3ce119c031.tar.gz
sl0ppij-6a3481f54f0ee789ceeb994d8f302e3ce119c031.tar.xz
sl0ppij-6a3481f54f0ee789ceeb994d8f302e3ce119c031.zip
Merge branch 'main' into restructure
Diffstat (limited to 'src/common')
-rw-r--r--src/common/errors.rs2
-rw-r--r--src/common/pty_bus.rs34
-rw-r--r--src/common/screen.rs1
-rw-r--r--src/common/wasm_vm.rs12
4 files changed, 34 insertions, 15 deletions
diff --git a/src/common/errors.rs b/src/common/errors.rs
index cb483bbc..ad2ae7eb 100644
--- a/src/common/errors.rs
+++ b/src/common/errors.rs
@@ -167,6 +167,7 @@ pub enum ScreenContext {
CloseFocusedPane,
ToggleActiveTerminalFullscreen,
SetSelectable,
+ SetMaxHeight,
ClosePane,
ApplyLayout,
NewTab,
@@ -202,6 +203,7 @@ impl From<&ScreenInstruction> for ScreenContext {
ScreenContext::ToggleActiveTerminalFullscreen
}
ScreenInstruction::SetSelectable(..) => ScreenContext::SetSelectable,
+ ScreenInstruction::SetMaxHeight(..) => ScreenContext::SetMaxHeight,
ScreenInstruction::ClosePane(_) => ScreenContext::ClosePane,
ScreenInstruction::ApplyLayout(_) => ScreenContext::ApplyLayout,
ScreenInstruction::NewTab(_) => ScreenContext::NewTab,
diff --git a/src/common/pty_bus.rs b/src/common/pty_bus.rs
index ba5a608b..c7458cfe 100644
--- a/src/common/pty_bus.rs
+++ b/src/common/pty_bus.rs
@@ -163,6 +163,7 @@ pub struct PtyBus {
pub id_to_child_pid: HashMap<RawFd, RawFd>,
os_input: Box<dyn OsApi>,
debug_to_file: bool,
+ task_handles: HashMap<RawFd, JoinHandle<()>>,
}
fn stream_terminal_bytes(
@@ -170,7 +171,7 @@ fn stream_terminal_bytes(
mut send_screen_instructions: SenderWithContext<ScreenInstruction>,
os_input: Box<dyn OsApi>,
debug: bool,
-) {
+) -> JoinHandle<()> {
let mut err_ctx = OPENCALLS.with(|ctx| *ctx.borrow());
task::spawn({
async move {
@@ -203,9 +204,7 @@ fn stream_terminal_bytes(
Some(receive_time) => {
if receive_time.elapsed() > max_render_pause {
pending_render = false;
- send_screen_instructions
- .send(ScreenInstruction::Render)
- .unwrap();
+ let _ = send_screen_instructions.send(ScreenInstruction::Render);
last_byte_receive_time = Some(Instant::now());
} else {
pending_render = true;
@@ -219,17 +218,15 @@ fn stream_terminal_bytes(
} else {
if pending_render {
pending_render = false;
- send_screen_instructions
- .send(ScreenInstruction::Render)
- .unwrap();
+ let _ = send_screen_instructions.send(ScreenInstruction::Render);
}
last_byte_receive_time = None;
task::sleep(::std::time::Duration::from_millis(10)).await;
}
}
- send_screen_instructions
- .send(ScreenInstruction::Render)
- .unwrap();
+ if pending_render {
+ let _ = send_screen_instructions.send(ScreenInstruction::Render);
+ }
#[cfg(not(test))]
// this is a little hacky, and is because the tests end the file as soon as
// we read everything, rather than hanging until there is new data
@@ -238,7 +235,7 @@ fn stream_terminal_bytes(
.send(ScreenInstruction::ClosePane(PaneId::Terminal(pid)))
.unwrap();
}
- });
+ })
}
impl PtyBus {
@@ -256,17 +253,19 @@ impl PtyBus {
os_input,
id_to_child_pid: HashMap::new(),
debug_to_file,
+ task_handles: HashMap::new(),
}
}
pub fn spawn_terminal(&mut self, file_to_open: Option<PathBuf>) -> RawFd {
let (pid_primary, pid_secondary): (RawFd, RawFd) =
self.os_input.spawn_terminal(file_to_open);
- stream_terminal_bytes(
+ let task_handle = stream_terminal_bytes(
pid_primary,
self.send_screen_instructions.clone(),
self.os_input.clone(),
self.debug_to_file,
);
+ self.task_handles.insert(pid_primary, task_handle);
self.id_to_child_pid.insert(pid_primary, pid_secondary);
pid_primary
}
@@ -285,19 +284,24 @@ impl PtyBus {
)))
.unwrap();
for id in new_pane_pids {
- stream_terminal_bytes(
+ let task_handle = stream_terminal_bytes(
id,
self.send_screen_instructions.clone(),
self.os_input.clone(),
self.debug_to_file,
);
+ self.task_handles.insert(id, task_handle);
}
}
pub fn close_pane(&mut self, id: PaneId) {
match id {
PaneId::Terminal(id) => {
- let child_pid = self.id_to_child_pid.get(&id).unwrap();
- self.os_input.kill(*child_pid).unwrap();
+ let child_pid = self.id_to_child_pid.remove(&id).unwrap();
+ let handle = self.task_handles.remove(&id).unwrap();
+ self.os_input.kill(child_pid).unwrap();
+ task::block_on(async {
+ handle.cancel().await;
+ });
}
PaneId::Plugin(pid) => drop(
self.send_plugin_instructions
diff --git a/src/common/screen.rs b/src/common/screen.rs
index 7fb19b6c..551fff65 100644
--- a/src/common/screen.rs
+++ b/src/common/screen.rs
@@ -43,6 +43,7 @@ pub enum ScreenInstruction {
CloseFocusedPane,
ToggleActiveTerminalFullscreen,
SetSelectable(PaneId, bool),
+ SetMaxHeight(PaneId, usize),
ClosePane(PaneId),
ApplyLayout((Layout, Vec<RawFd>)),
NewTab(RawFd),
diff --git a/src/common/wasm_vm.rs b/src/common/wasm_vm.rs
index 97a1a587..5a68f636 100644
--- a/src/common/wasm_vm.rs
+++ b/src/common/wasm_vm.rs
@@ -35,6 +35,7 @@ pub fn mosaic_imports(store: &Store, plugin_env: &PluginEnv) -> ImportObject {
imports! {
"mosaic" => {
"host_open_file" => Function::new_native_with_env(store, plugin_env.clone(), host_open_file),
+ "host_set_max_height" => Function::new_native_with_env(store, plugin_env.clone(), host_set_max_height),
"host_set_selectable" => Function::new_native_with_env(store, plugin_env.clone(), host_set_selectable),
"host_get_help" => Function::new_native_with_env(store, plugin_env.clone(), host_get_help),
}
@@ -62,6 +63,17 @@ fn host_set_selectable(plugin_env: &PluginEnv, selectable: i32) {
.unwrap()
}
+fn host_set_max_height(plugin_env: &PluginEnv, max_height: i32) {
+ let max_height = max_height as usize;
+ plugin_env
+ .send_screen_instructions
+ .send(ScreenInstruction::SetMaxHeight(
+ PaneId::Plugin(plugin_env.plugin_id),
+ max_height,
+ ))
+ .unwrap()
+}
+
fn host_get_help(plugin_env: &PluginEnv) {
let (state_tx, state_rx) = channel();
// FIXME: If I changed the application so that threads were sent the termination