diff options
| author | Brooks J Rady <b.j.rady@gmail.com> | 2021-01-06 12:53:12 +0000 |
|---|---|---|
| committer | Brooks J Rady <b.j.rady@gmail.com> | 2021-01-06 12:53:12 +0000 |
| commit | a6ba792e89e1e2b7afca7025529c97266e903fd4 (patch) | |
| tree | 3ca52274d672c3b5a26192d322c211768b986b8c /src | |
| parent | fix(render): properly render plugin borders and content (diff) | |
| download | sl0ppij-a6ba792e89e1e2b7afca7025529c97266e903fd4.tar.gz sl0ppij-a6ba792e89e1e2b7afca7025529c97266e903fd4.tar.xz sl0ppij-a6ba792e89e1e2b7afca7025529c97266e903fd4.zip | |
Also borken
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 8 | ||||
| -rw-r--r-- | src/tab.rs | 45 | ||||
| -rw-r--r-- | src/terminal_pane/plugin_pane.rs | 14 | ||||
| -rw-r--r-- | src/terminal_pane/terminal_pane.rs | 1 | ||||
| -rw-r--r-- | src/utils/mod.rs | 1 | ||||
| -rw-r--r-- | src/utils/shared.rs | 17 |
6 files changed, 44 insertions, 42 deletions
diff --git a/src/main.rs b/src/main.rs index fdf4d585..ab2ae809 100644 --- a/src/main.rs +++ b/src/main.rs @@ -466,13 +466,7 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: Opt) { draw.call(&[Value::I32(rows as i32), Value::I32(cols as i32)]).unwrap(); - buf_tx.send(format!( - "{}\n\r", - wasi_stdout(&wasi_env) - .lines() - .collect::<Vec<_>>() - .join("\n\r") - )).unwrap(); + buf_tx.send(wasi_stdout(&wasi_env)).unwrap(); } PluginInstruction::Quit => break, i => panic!("Yo, dawg, nice job calling the wasm thread!\n {:?} is defo not implemented yet...", i), @@ -1,8 +1,8 @@ -use crate::os_input_output::OsApi; use crate::pty_bus::{PtyInstruction, VteEvent}; use crate::terminal_pane::{PositionAndSize, TerminalPane}; use crate::{boundaries::Boundaries, terminal_pane::PluginPane}; use crate::{layout::Layout, wasm_vm::PluginInstruction}; +use crate::{os_input_output::OsApi, utils::shared::pad_to_size}; use crate::{AppInstruction, SenderWithContext}; use std::collections::{BTreeMap, HashSet}; use std::os::unix::io::RawFd; @@ -215,10 +215,8 @@ impl Tab { } let mut new_pids = new_pids.iter(); for (layout, position_and_size) in positions_and_size { - dbg!("Loopy", &layout.plugin, position_and_size); // Just a regular terminal if let Some(plugin) = &layout.plugin { - dbg!("Starting here!"); let (pid_tx, pid_rx) = channel(); self.send_plugin_instructions .send(PluginInstruction::Load(pid_tx, plugin.clone())) @@ -229,13 +227,12 @@ impl Tab { *position_and_size, self.send_plugin_instructions.clone(), ); - dbg!(pid, position_and_size, plugin); self.panes .insert(PaneKind::PluginPane(pid), Box::new(new_plugin)); } else { // there are still panes left to fill, use the pids we received in this method let pid = new_pids.next().unwrap(); // if this crashes it means we got less pids than there are panes in this layout - let mut new_terminal = TerminalPane::new(*pid, *position_and_size); + let new_terminal = TerminalPane::new(*pid, *position_and_size); self.os_api.set_terminal_size_using_fd( new_terminal.pid, new_terminal.columns() as u16, @@ -547,31 +544,19 @@ impl Tab { self.full_screen_ws.columns as u16, self.full_screen_ws.rows as u16, ); - for (pane_kind, terminal) in self.panes.iter_mut() { - match pane_kind { - PaneKind::Terminal(pid) => { - if !self.panes_to_hide.contains(pid) { - boundaries.add_rect(&terminal); - if let Some(vte_output) = terminal.render() { - stdout - .write_all(&vte_output.as_bytes()) - .expect("cannot write to stdout"); - } - } - } - PaneKind::BuiltInPane(builtin_id) => { - // TBD - } - PaneKind::PluginPane(_) => { - boundaries.add_rect(&terminal); - if let Some(output) = terminal.render() { - write!( - stdout, - "{}\n\r", - output.lines().collect::<Vec<_>>().join("\n\r") - ) - .unwrap(); - } + for (_, terminal) in self.panes.iter_mut() { + if !self.panes_to_hide.contains(&terminal.pid()) { + boundaries.add_rect(&terminal); + if let Some(vte_output) = terminal.render() { + // FIXME: Use Termion for cursor and style clearing? + write!( + stdout, + "\u{1b}[{};{}H\u{1b}[m{}", + terminal.y() + 1, + terminal.x() + 1, + pad_to_size(&vte_output, terminal.rows(), terminal.columns()) + ) + .expect("cannot write to stdout"); } } } diff --git a/src/terminal_pane/plugin_pane.rs b/src/terminal_pane/plugin_pane.rs index 3da072eb..3d525fa7 100644 --- a/src/terminal_pane/plugin_pane.rs +++ b/src/terminal_pane/plugin_pane.rs @@ -1,8 +1,10 @@ #![allow(clippy::clippy::if_same_then_else)] -use crate::{pty_bus::VteEvent, tab::Pane, wasm_vm::PluginInstruction, SenderWithContext}; +use crate::{ + pty_bus::VteEvent, tab::Pane, utils::shared::*, wasm_vm::PluginInstruction, SenderWithContext, +}; -use std::{os::unix::prelude::RawFd, sync::mpsc::channel}; +use std::{iter, os::unix::prelude::RawFd, sync::mpsc::channel}; use crate::terminal_pane::PositionAndSize; @@ -111,9 +113,10 @@ impl Pane for PluginPane { .unwrap(); self.should_render = false; - let goto_plugin_coordinates = format!("\u{1b}[{};{}H", self.position_and_size.y + 1, self.position_and_size.x + 1); // goto row/col and reset styles + let goto_plugin_coordinates = format!("\u{1b}[{};{}H", self.y() + 1, self.x() + 1); // goto row/col and reset styles let reset_styles = "\u{1b}[m"; - let vte_output = format!("{}{}{}", goto_plugin_coordinates, reset_styles, buf_rx.recv().unwrap()); + let buf = pad_to_size(&buf_rx.recv().unwrap(), self.rows(), self.columns()); + let vte_output = format!("{}{}{}", goto_plugin_coordinates, reset_styles, buf); Some(vte_output) } else { None @@ -121,7 +124,8 @@ impl Pane for PluginPane { } // FIXME: Really shouldn't be in this trait... fn pid(&self) -> RawFd { - todo!() + // FIXME: This looks like a really bad idea! + 100 + self.pid as RawFd } fn reduce_height_down(&mut self, count: usize) { self.position_and_size.y += count; diff --git a/src/terminal_pane/terminal_pane.rs b/src/terminal_pane/terminal_pane.rs index 70711a0e..fda74c2a 100644 --- a/src/terminal_pane/terminal_pane.rs +++ b/src/terminal_pane/terminal_pane.rs @@ -193,6 +193,7 @@ impl Pane for TerminalPane { } } character_styles.clear(); + vte_output.push('\n'); } self.mark_for_rerender(); Some(vte_output) diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 140eec18..0ea4c76f 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,2 +1,3 @@ pub mod consts; pub mod logging; +pub mod shared; diff --git a/src/utils/shared.rs b/src/utils/shared.rs new file mode 100644 index 00000000..3b8b5fbd --- /dev/null +++ b/src/utils/shared.rs @@ -0,0 +1,17 @@ +use std::iter; + +use strip_ansi_escapes::strip; + +// FIXME: Should this be an extension trait? Or here at all? +pub fn ansi_len(s: &str) -> usize { + strip(s.as_bytes()).unwrap().len() +} + +pub fn pad_to_size(s: &str, rows: usize, columns: usize) -> String { + s.lines() + .map(|l| [l, &str::repeat(" ", dbg!(columns) - dbg!(ansi_len(l)))].concat()) + .chain(iter::repeat(str::repeat(" ", columns))) + .take(rows) + .collect::<Vec<_>>() + .join("\n\r") +} |
