aboutsummaryrefslogtreecommitdiffstats
path: root/src/client
diff options
context:
space:
mode:
authorBrooks Rady <b.j.rady@gmail.com>2021-03-26 13:20:06 +0000
committerGitHub <noreply@github.com>2021-03-26 13:20:06 +0000
commitd818661c727a59312e1a43432e84fbeec79fc145 (patch)
treee8ab04124ee7f5c87cd88be63c1867c7d9b2289c /src/client
parentfix(render): various rendering issues (#238) (diff)
parentFix some overzealous format!() removals and a stray comment (diff)
downloadsl0ppij-d818661c727a59312e1a43432e84fbeec79fc145.tar.gz
sl0ppij-d818661c727a59312e1a43432e84fbeec79fc145.tar.xz
sl0ppij-d818661c727a59312e1a43432e84fbeec79fc145.zip
feat(plugin): refactored to a new and more general plugin API
- Changed `init()` to `load()` - Deduplicated structs that are in both `zellij` and `zellij-tile` - WASM thread now keeps a mapping of plugins and event subscriptions - Added host-functions for subscribing and unsubscribing from events - Introduced the `update(event)` callback into the API (which is called to handle plugin events) - Made mode changes send an event to the WASM thread - Removed the `AppInstruction::Get/SetState` calls (and any global state) - Removed the `get_help()` host function - Added an event system for key-presses - Added an event for updating tabs - Ported support for renaming tabs - Removed every plugin callback other than `load()`, `update(event)`, and `draw(rows, cols)` - Removed every WASM thread event other than Load, Draw, Update, Unload, and Quit - Calls render after a plugin is updated - Switched back to upstream `termion` - Loads of lint fixing - Shrunk and simplified the code!
Diffstat (limited to 'src/client')
-rw-r--r--src/client/boundaries.rs135
-rw-r--r--src/client/layout.rs8
-rw-r--r--src/client/panes/plugin_pane.rs2
-rw-r--r--src/client/panes/terminal_character.rs10
-rw-r--r--src/client/tab.rs184
5 files changed, 156 insertions, 183 deletions
diff --git a/src/client/boundaries.rs b/src/client/boundaries.rs
index 19a1058d..e498da89 100644
--- a/src/client/boundaries.rs
+++ b/src/client/boundaries.rs
@@ -1,6 +1,7 @@
-use crate::{common::input::handler::InputMode, tab::Pane};
+use crate::tab::Pane;
use ansi_term::Colour;
use std::collections::HashMap;
+use zellij_tile::data::InputMode;
use std::fmt::{Display, Error, Formatter};
@@ -82,7 +83,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::TOP_RIGHT, boundary_type::VERTICAL) => {
@@ -91,7 +92,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::TOP_RIGHT, boundary_type::HORIZONTAL) => {
@@ -100,7 +101,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::TOP_RIGHT, boundary_type::TOP_LEFT) => {
@@ -109,7 +110,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::TOP_RIGHT, boundary_type::BOTTOM_RIGHT) => {
@@ -118,7 +119,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::TOP_RIGHT, boundary_type::BOTTOM_LEFT) => {
@@ -127,7 +128,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::TOP_RIGHT, boundary_type::VERTICAL_LEFT) => {
@@ -136,7 +137,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::TOP_RIGHT, boundary_type::VERTICAL_RIGHT) => {
@@ -145,7 +146,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::TOP_RIGHT, boundary_type::HORIZONTAL_DOWN) => {
@@ -154,7 +155,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::TOP_RIGHT, boundary_type::HORIZONTAL_UP) => {
@@ -163,7 +164,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::TOP_RIGHT, boundary_type::CROSS) => {
@@ -172,7 +173,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::HORIZONTAL, boundary_type::HORIZONTAL) => {
@@ -181,7 +182,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::HORIZONTAL, boundary_type::VERTICAL) => {
@@ -190,7 +191,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::HORIZONTAL, boundary_type::TOP_LEFT) => {
@@ -199,7 +200,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::HORIZONTAL, boundary_type::BOTTOM_RIGHT) => {
@@ -208,7 +209,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::HORIZONTAL, boundary_type::BOTTOM_LEFT) => {
@@ -217,7 +218,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::HORIZONTAL, boundary_type::VERTICAL_LEFT) => {
@@ -226,7 +227,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::HORIZONTAL, boundary_type::VERTICAL_RIGHT) => {
@@ -235,7 +236,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::HORIZONTAL, boundary_type::HORIZONTAL_DOWN) => {
@@ -244,7 +245,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::HORIZONTAL, boundary_type::HORIZONTAL_UP) => {
@@ -253,7 +254,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::HORIZONTAL, boundary_type::CROSS) => {
@@ -262,7 +263,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::VERTICAL, boundary_type::VERTICAL) => {
@@ -271,7 +272,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::VERTICAL, boundary_type::TOP_LEFT) => {
@@ -280,7 +281,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::VERTICAL, boundary_type::BOTTOM_RIGHT) => {
@@ -289,7 +290,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::VERTICAL, boundary_type::BOTTOM_LEFT) => {
@@ -298,7 +299,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::VERTICAL, boundary_type::VERTICAL_LEFT) => {
@@ -307,7 +308,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::VERTICAL, boundary_type::VERTICAL_RIGHT) => {
@@ -316,7 +317,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::VERTICAL, boundary_type::HORIZONTAL_DOWN) => {
@@ -325,7 +326,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::VERTICAL, boundary_type::HORIZONTAL_UP) => {
@@ -334,7 +335,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::VERTICAL, boundary_type::CROSS) => {
@@ -343,7 +344,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::TOP_LEFT, boundary_type::TOP_LEFT) => {
@@ -352,7 +353,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::TOP_LEFT, boundary_type::BOTTOM_RIGHT) => {
@@ -361,7 +362,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::TOP_LEFT, boundary_type::BOTTOM_LEFT) => {
@@ -370,7 +371,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::TOP_LEFT, boundary_type::VERTICAL_LEFT) => {
@@ -379,7 +380,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::TOP_LEFT, boundary_type::VERTICAL_RIGHT) => {
@@ -388,7 +389,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::TOP_LEFT, boundary_type::HORIZONTAL_DOWN) => {
@@ -397,7 +398,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::TOP_LEFT, boundary_type::HORIZONTAL_UP) => {
@@ -406,7 +407,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::TOP_LEFT, boundary_type::CROSS) => {
@@ -415,7 +416,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::BOTTOM_RIGHT, boundary_type::BOTTOM_RIGHT) => {
@@ -424,7 +425,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::BOTTOM_RIGHT, boundary_type::BOTTOM_LEFT) => {
@@ -433,7 +434,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::BOTTOM_RIGHT, boundary_type::VERTICAL_LEFT) => {
@@ -442,7 +443,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::BOTTOM_RIGHT, boundary_type::VERTICAL_RIGHT) => {
@@ -451,7 +452,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::BOTTOM_RIGHT, boundary_type::HORIZONTAL_DOWN) => {
@@ -460,7 +461,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::BOTTOM_RIGHT, boundary_type::HORIZONTAL_UP) => {
@@ -469,7 +470,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::BOTTOM_RIGHT, boundary_type::CROSS) => {
@@ -478,7 +479,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::BOTTOM_LEFT, boundary_type::BOTTOM_LEFT) => {
@@ -487,7 +488,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::BOTTOM_LEFT, boundary_type::VERTICAL_LEFT) => {
@@ -496,7 +497,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::BOTTOM_LEFT, boundary_type::VERTICAL_RIGHT) => {
@@ -505,7 +506,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::BOTTOM_LEFT, boundary_type::HORIZONTAL_DOWN) => {
@@ -514,7 +515,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::BOTTOM_LEFT, boundary_type::HORIZONTAL_UP) => {
@@ -523,7 +524,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::BOTTOM_LEFT, boundary_type::CROSS) => {
@@ -532,7 +533,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::VERTICAL_LEFT, boundary_type::VERTICAL_LEFT) => {
@@ -541,7 +542,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::VERTICAL_LEFT, boundary_type::VERTICAL_RIGHT) => {
@@ -550,7 +551,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::VERTICAL_LEFT, boundary_type::HORIZONTAL_DOWN) => {
@@ -559,7 +560,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::VERTICAL_LEFT, boundary_type::HORIZONTAL_UP) => {
@@ -568,7 +569,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::VERTICAL_LEFT, boundary_type::CROSS) => {
@@ -577,7 +578,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::VERTICAL_RIGHT, boundary_type::VERTICAL_RIGHT) => {
@@ -586,7 +587,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::VERTICAL_RIGHT, boundary_type::HORIZONTAL_DOWN) => {
@@ -595,7 +596,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::VERTICAL_RIGHT, boundary_type::HORIZONTAL_UP) => {
@@ -604,7 +605,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::VERTICAL_RIGHT, boundary_type::CROSS) => {
@@ -613,7 +614,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::HORIZONTAL_DOWN, boundary_type::HORIZONTAL_DOWN) => {
@@ -622,7 +623,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::HORIZONTAL_DOWN, boundary_type::HORIZONTAL_UP) => {
@@ -631,7 +632,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::HORIZONTAL_DOWN, boundary_type::CROSS) => {
@@ -640,7 +641,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::HORIZONTAL_UP, boundary_type::HORIZONTAL_UP) => {
@@ -649,7 +650,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::HORIZONTAL_UP, boundary_type::CROSS) => {
@@ -658,7 +659,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(boundary_type::CROSS, boundary_type::CROSS) => {
@@ -667,7 +668,7 @@ fn combine_symbols(
Some(BoundarySymbol {
boundary_type,
invisible,
- color: color,
+ color,
})
}
(_, _) => None,
diff --git a/src/client/layout.rs b/src/client/layout.rs
index 1b383540..2d1daaf4 100644
--- a/src/client/layout.rs
+++ b/src/client/layout.rs
@@ -1,10 +1,8 @@
-use crate::utils::consts::ZELLIJ_ROOT_LAYOUT_DIR;
use directories_next::ProjectDirs;
use serde::{Deserialize, Serialize};
-use std::path::{Path, PathBuf};
+use std::path::PathBuf;
use std::{fs::File, io::prelude::*};
-use crate::common::wasm_vm::EventType;
use crate::panes::PositionAndSize;
fn split_space_to_parts_vertically(
@@ -181,19 +179,15 @@ pub struct Layout {
pub plugin: Option<PathBuf>,
#[serde(default)]
pub expansion_boundary: bool,
- #[serde(default, skip_serializing_if = "Vec::is_empty")]
- pub events: Vec<EventType>,
}
impl Layout {
pub fn new(layout_path: PathBuf) -> Self {
let project_dirs = ProjectDirs::from("org", "Zellij Contributors", "Zellij").unwrap();
let layout_dir = project_dirs.data_dir().join("layouts/");
- let root_layout_dir = Path::new(ZELLIJ_ROOT_LAYOUT_DIR);
let mut layout_file = File::open(&layout_path)
.or_else(|_| File::open(&layout_path.with_extension("yaml")))
.or_else(|_| File::open(&layout_dir.join(&layout_path).with_extension("yaml")))
- .or_else(|_| File::open(root_layout_dir.join(&layout_path).with_extension("yaml")))
.unwrap_or_else(|_| panic!("cannot find layout {}", &layout_path.display()));
let mut layout = String::new();
diff --git a/src/client/panes/plugin_pane.rs b/src/client/panes/plugin_pane.rs
index 588cffd6..4cffff5f 100644
--- a/src/client/panes/plugin_pane.rs
+++ b/src/client/panes/plugin_pane.rs
@@ -120,7 +120,7 @@ impl Pane for PluginPane {
let (buf_tx, buf_rx) = channel();
self.send_plugin_instructions
- .send(PluginInstruction::Draw(
+ .send(PluginInstruction::Render(
buf_tx,
self.pid,
self.rows(),
diff --git a/src/client/panes/terminal_character.rs b/src/client/panes/terminal_character.rs
index 80c3162b..053ebd3f 100644
--- a/src/client/panes/terminal_character.rs
+++ b/src/client/panes/terminal_character.rs
@@ -23,7 +23,7 @@ pub enum AnsiCode {
On,
Reset,
NamedColor(NamedColor),
- RGBCode((u8, u8, u8)),
+ RgbCode((u8, u8, u8)),
ColorIndex(u8),
}
@@ -336,7 +336,7 @@ impl CharacterStyles {
[36, ..] => *self = self.foreground(Some(AnsiCode::NamedColor(NamedColor::Cyan))),
[37, ..] => *self = self.foreground(Some(AnsiCode::NamedColor(NamedColor::White))),
[38, 2, ..] => {
- let ansi_code = AnsiCode::RGBCode((
+ let ansi_code = AnsiCode::RgbCode((
*ansi_params.get(2).unwrap() as u8,
*ansi_params.get(3).unwrap() as u8,
*ansi_params.get(4).unwrap() as u8,
@@ -364,7 +364,7 @@ impl CharacterStyles {
[46, ..] => *self = self.background(Some(AnsiCode::NamedColor(NamedColor::Cyan))),
[47, ..] => *self = self.background(Some(AnsiCode::NamedColor(NamedColor::White))),
[48, 2, ..] => {
- let ansi_code = AnsiCode::RGBCode((
+ let ansi_code = AnsiCode::RgbCode((
*ansi_params.get(2).unwrap() as u8,
*ansi_params.get(3).unwrap() as u8,
*ansi_params.get(4).unwrap() as u8,
@@ -416,7 +416,7 @@ impl Display for CharacterStyles {
}
if let Some(ansi_code) = self.foreground {
match ansi_code {
- AnsiCode::RGBCode((r, g, b)) => {
+ AnsiCode::RgbCode((r, g, b)) => {
write!(f, "\u{1b}[38;2;{};{};{}m", r, g, b)?;
}
AnsiCode::ColorIndex(color_index) => {
@@ -433,7 +433,7 @@ impl Display for CharacterStyles {
};
if let Some(ansi_code) = self.background {
match ansi_code {
- AnsiCode::RGBCode((r, g, b)) => {
+ AnsiCode::RgbCode((r, g, b)) => {
write!(f, "\u{1b}[48;2;{};{};{}m", r, g, b)?;
}
AnsiCode::ColorIndex(color_index) => {
diff --git a/src/client/tab.rs b/src/client/tab.rs
index 081194ed..1e56fd8b 100644
--- a/src/client/tab.rs
+++ b/src/client/tab.rs
@@ -1,23 +1,21 @@
//! `Tab`s holds multiple panes. It tracks their coordinates (x/y) and size,
//! as well as how they should be resized
-use crate::common::{input::handler::InputMode, AppInstruction, SenderWithContext};
+use crate::boundaries::colors;
+use crate::common::{input::handler::parse_keys, AppInstruction, SenderWithContext};
use crate::layout::Layout;
use crate::panes::{PaneId, PositionAndSize, TerminalPane};
use crate::pty_bus::{PtyInstruction, VteEvent};
-use crate::wasm_vm::{PluginInputType, PluginInstruction};
-use crate::{
- boundaries::{colors, Boundaries},
- panes::PluginPane,
-};
+use crate::wasm_vm::PluginInstruction;
+use crate::{boundaries::Boundaries, panes::PluginPane};
use crate::{os_input_output::OsApi, utils::shared::pad_to_size};
-use serde::{Deserialize, Serialize};
use std::os::unix::io::RawFd;
use std::{
cmp::Reverse,
collections::{BTreeMap, HashSet},
};
use std::{io::Write, sync::mpsc::channel};
+use zellij_tile::data::{Event, InputMode};
const CURSOR_HEIGHT_WIDTH_RATIO: usize = 4; // this is not accurate and kind of a magic number, TODO: look into this
const MIN_TERMINAL_HEIGHT: usize = 2;
@@ -71,14 +69,6 @@ pub struct Tab {
pub input_mode: InputMode,
}
-#[derive(Clone, Debug, Default, Serialize, Deserialize)]
-pub struct TabData {
- /* subset of fields to publish to plugins */
- pub position: usize,
- pub name: String,
- pub active: bool,
-}
-
// FIXME: Use a struct that has a pane_type enum, to reduce all of the duplication
pub trait Pane {
fn x(&self) -> usize;
@@ -268,11 +258,7 @@ impl Tab {
if let Some(plugin) = &layout.plugin {
let (pid_tx, pid_rx) = channel();
self.send_plugin_instructions
- .send(PluginInstruction::Load(
- pid_tx,
- plugin.clone(),
- layout.events.clone(),
- ))
+ .send(PluginInstruction::Load(pid_tx, plugin.clone()))
.unwrap();
let pid = pid_rx.recv().unwrap();
let new_plugin = PluginPane::new(
@@ -311,7 +297,6 @@ impl Tab {
self.toggle_active_pane_fullscreen();
}
if !self.has_panes() {
- // FIXME: This could use a second look
if let PaneId::Terminal(term_pid) = pid {
let new_terminal = TerminalPane::new(term_pid, self.full_screen_ws);
self.os_api.set_terminal_size_using_fd(
@@ -362,7 +347,6 @@ impl Tab {
if terminal_to_split.rows() * CURSOR_HEIGHT_WIDTH_RATIO > terminal_to_split.columns()
&& terminal_to_split.rows() > terminal_to_split.min_height() * 2
{
- // FIXME: This could use a second look
if let PaneId::Terminal(term_pid) = pid {
let (top_winsize, bottom_winsize) = split_horizontally_with_gap(&terminal_ws);
let new_terminal = TerminalPane::new(term_pid, bottom_winsize);
@@ -383,7 +367,6 @@ impl Tab {
self.active_terminal = Some(pid);
}
} else if terminal_to_split.columns() > terminal_to_split.min_width() * 2 {
- // FIXME: This could use a second look
if let PaneId::Terminal(term_pid) = pid {
let (left_winsize, right_winsize) = split_vertically_with_gap(&terminal_ws);
let new_terminal = TerminalPane::new(term_pid, right_winsize);
@@ -413,7 +396,6 @@ impl Tab {
self.toggle_active_pane_fullscreen();
}
if !self.has_panes() {
- // FIXME: This could use a second look
if let PaneId::Terminal(term_pid) = pid {
let new_terminal = TerminalPane::new(term_pid, self.full_screen_ws);
self.os_api.set_terminal_size_using_fd(
@@ -424,47 +406,44 @@ impl Tab {
self.panes.insert(pid, Box::new(new_terminal));
self.active_terminal = Some(pid);
}
- } else {
- // FIXME: This could use a second look
- if let PaneId::Terminal(term_pid) = pid {
- // TODO: check minimum size of active terminal
- let active_pane_id = &self.get_active_pane_id().unwrap();
- let active_pane = self.panes.get_mut(active_pane_id).unwrap();
- if active_pane.rows() < MIN_TERMINAL_HEIGHT * 2 + 1 {
- self.send_pty_instructions
- .send(PtyInstruction::ClosePane(pid)) // we can't open this pane, close the pty
- .unwrap();
- return;
- }
- let terminal_ws = PositionAndSize {
- x: active_pane.x(),
- y: active_pane.y(),
- rows: active_pane.rows(),
- columns: active_pane.columns(),
- };
- let (top_winsize, bottom_winsize) = split_horizontally_with_gap(&terminal_ws);
+ } else if let PaneId::Terminal(term_pid) = pid {
+ // TODO: check minimum size of active terminal
+ let active_pane_id = &self.get_active_pane_id().unwrap();
+ let active_pane = self.panes.get_mut(active_pane_id).unwrap();
+ if active_pane.rows() < MIN_TERMINAL_HEIGHT * 2 + 1 {
+ self.send_pty_instructions
+ .send(PtyInstruction::ClosePane(pid)) // we can't open this pane, close the pty
+ .unwrap();
+ return;
+ }
+ let terminal_ws = PositionAndSize {
+ x: active_pane.x(),
+ y: active_pane.y(),
+ rows: active_pane.rows(),
+ columns: active_pane.columns(),
+ };
+ let (top_winsize, bottom_winsize) = split_horizontally_with_gap(&terminal_ws);
+
+ active_pane.change_pos_and_size(&top_winsize);
- active_pane.change_pos_and_size(&top_winsize);
+ let new_terminal = TerminalPane::new(term_pid, bottom_winsize);
+ self.os_api.set_terminal_size_using_fd(
+ new_terminal.pid,
+ bottom_winsize.columns as u16,
+ bottom_winsize.rows as u16,
+ );
+ self.panes.insert(pid, Box::new(new_terminal));
- let new_terminal = TerminalPane::new(term_pid, bottom_winsize);
+ if let PaneId::Terminal(active_terminal_pid) = active_pane_id {
self.os_api.set_terminal_size_using_fd(
- new_terminal.pid,
- bottom_winsize.columns as u16,
- bottom_winsize.rows as u16,
+ *active_terminal_pid,
+ top_winsize.columns as u16,
+ top_winsize.rows as u16,
);
- self.panes.insert(pid, Box::new(new_terminal));
-
- if let PaneId::Terminal(active_terminal_pid) = active_pane_id {
- self.os_api.set_terminal_size_using_fd(
- *active_terminal_pid,
- top_winsize.columns as u16,
- top_winsize.rows as u16,
- );
- }
-
- self.active_terminal = Some(pid);
- self.render();
}
+
+ self.active_terminal = Some(pid);
+ self.render();
}
}
pub fn vertical_split(&mut self, pid: PaneId) {
@@ -473,7 +452,6 @@ impl Tab {
self.toggle_active_pane_fullscreen();
}
if !self.has_panes() {
- // FIXME: This could use a second look
if let PaneId::Terminal(term_pid) = pid {
let new_terminal = TerminalPane::new(term_pid, self.full_screen_ws);
self.os_api.set_terminal_size_using_fd(
@@ -484,47 +462,44 @@ impl Tab {
self.panes.insert(pid, Box::new(new_terminal));
self.active_terminal = Some(pid);
}
- } else {
- // FIXME: This could use a second look
- if let PaneId::Terminal(term_pid) = pid {
- // TODO: check minimum size of active terminal
- let active_pane_id = &self.get_active_pane_id().unwrap();
- let active_pane = self.panes.get_mut(active_pane_id).unwrap();
- if active_pane.columns() < MIN_TERMINAL_WIDTH * 2 + 1 {
- self.send_pty_instructions
- .send(PtyInstruction::ClosePane(pid)) // we can't open this pane, close the pty
- .unwrap();
- return;
- }
- let terminal_ws = PositionAndSize {
- x: active_pane.x(),
- y: active_pane.y(),
- rows: active_pane.rows(),
- columns: active_pane.columns(),
- };
- let (left_winsize, right_winsize) = split_vertically_with_gap(&terminal_ws);
+ } else if let PaneId::Terminal(term_pid) = pid {
+ // TODO: check minimum size of active terminal
+ let active_pane_id = &self.get_active_pane_id().unwrap();
+ let active_pane = self.panes.get_mut(active_pane_id).unwrap();
+ if active_pane.columns() < MIN_TERMINAL_WIDTH * 2 + 1 {
+ self.send_pty_instructions
+ .send(PtyInstruction::ClosePane(pid)) // we can't open this pane, close the pty
+ .unwrap();
+ return;
+ }
+ let terminal_ws = PositionAndSize {
+ x: active_pane.x(),
+ y: active_pane.y(),
+ rows: active_pane.rows(),
+ columns: active_pane.columns(),
+ };
+ let (left_winsize, right_winsize) = split_vertically_with_gap(&terminal_ws);
- active_pane.change_pos_and_size(&left_winsize);
+ active_pane.change_pos_and_size(&left_winsize);
- let new_terminal = TerminalPane::new(term_pid, right_winsize);
+ let new_terminal = TerminalPane::new(term_pid, right_winsize);
+ self.os_api.set_terminal_size_using_fd(
+ new_terminal.pid,
+ right_winsize.columns as u16,
+ right_winsize.rows as u16,
+ );
+ self.panes.insert(pid, Box::new(new_terminal));
+
+ if let PaneId::Terminal(active_terminal_pid) = active_pane_id {
self.os_api.set_terminal_size_using_fd(
- new_terminal.pid,
- right_winsize.columns as u16,
- right_winsize.rows as u16,
+ *active_terminal_pid,
+ left_winsize.columns as u16,
+ left_winsize.rows as u16,
);
- self.panes.insert(pid, Box::new(new_terminal));
-
- if let PaneId::Terminal(active_terminal_pid) = active_pane_id {
- self.os_api.set_terminal_size_using_fd(
- *active_terminal_pid,
- left_winsize.columns as u16,
- left_winsize.rows as u16,
- );
- }
-
- self.active_terminal = Some(pid);
- self.render();
}
+
+ self.active_terminal = Some(pid);
+ self.render();
}
}
pub fn get_active_pane(&self) -> Option<&dyn Pane> {
@@ -568,12 +543,11 @@ impl Tab {
.expect("failed to drain terminal");
}
Some(PaneId::Plugin(pid)) => {
- self.send_plugin_instructions
- .send(PluginInstruction::Input(
- PluginInputType::Normal(pid),
- input_bytes,
- ))
- .unwrap();
+ for key in parse_keys(&input_bytes) {
+ self.send_plugin_instructions
+ .send(PluginInstruction::Update(Some(pid), Event::KeyPress(key)))
+ .unwrap()
+ }
}
_ => {}
}
@@ -1691,6 +1665,7 @@ impl Tab {
self.reduce_pane_and_surroundings_right(&active_pane_id, count);
}
}
+ self.render();
}
pub fn resize_left(&mut self) {
// TODO: find out by how much we actually reduced and only reduce by that much
@@ -1702,6 +1677,7 @@ impl Tab {
self.reduce_pane_and_surroundings_left(&active_pane_id, count);
}
}
+ self.render();
}
pub fn resize_down(&mut self) {
// TODO: find out by how much we actually reduced and only reduce by that much
@@ -1713,6 +1689,7 @@ impl Tab {
self.reduce_pane_and_surroundings_down(&active_pane_id, count);
}
}
+ self.render();
}
pub fn resize_up(&mut self) {
// TODO: find out by how much we actually reduced and only reduce by that much
@@ -1724,6 +1701,7 @@ impl Tab {
self.reduce_pane_and_surroundings_up(&active_pane_id, count);
}
}
+ self.render();
}
pub fn move_focus(&mut self) {
if !self.has_selectable_panes() {