aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Maximov <denismaximov98@gmail.com>2020-11-14 19:59:37 +0200
committerGitHub <noreply@github.com>2020-11-14 18:59:37 +0100
commita2914066bf0e2e2bf5caee263d2378b7d77f477f (patch)
tree2a87397c32e2d9f512ad0c886107aa5c2e57d68e
parentHOTFIX: do not get os input unless we're starting the app (diff)
downloadsl0ppij-a2914066bf0e2e2bf5caee263d2378b7d77f477f.tar.gz
sl0ppij-a2914066bf0e2e2bf5caee263d2378b7d77f477f.tar.xz
sl0ppij-a2914066bf0e2e2bf5caee263d2378b7d77f477f.zip
feat: add rustfmt, update action workflow to check for formatting (#45)
-rw-r--r--.github/workflows/rust.yml16
-rw-r--r--rustfmt.toml0
-rw-r--r--src/boundaries.rs173
-rw-r--r--src/main.rs355
-rw-r--r--src/os_input_output.rs89
-rw-r--r--src/pty_bus.rs150
-rw-r--r--src/screen.rs742
-rw-r--r--src/terminal_pane/mod.rs8
-rw-r--r--src/terminal_pane/scroll.rs189
-rw-r--r--src/terminal_pane/terminal_character.rs312
-rw-r--r--src/terminal_pane/terminal_pane.rs376
-rw-r--r--src/tests/fakes.rs39
-rw-r--r--src/tests/integration/basic.rs100
-rw-r--r--src/tests/integration/close_pane.rs113
-rw-r--r--src/tests/integration/compatibility.rs46
-rw-r--r--src/tests/integration/mod.rs6
-rw-r--r--src/tests/integration/resize_down.rs101
-rw-r--r--src/tests/integration/resize_left.rs103
-rw-r--r--src/tests/integration/resize_right.rs102
-rw-r--r--src/tests/integration/resize_up.rs107
-rw-r--r--src/tests/mod.rs2
-rw-r--r--src/tests/possible_tty_inputs.rs15
-rw-r--r--src/tests/utils.rs5
23 files changed, 2055 insertions, 1094 deletions
diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml
index 7ae98f3b..64441fc3 100644
--- a/.github/workflows/rust.yml
+++ b/.github/workflows/rust.yml
@@ -20,3 +20,19 @@ jobs:
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
+ fmt:
+ name: Rustfmt
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v2
+ - uses: actions-rs/toolchain@v1
+ with:
+ profile: minimal
+ toolchain: stable
+ override: true
+ - run: rustup component add rustfmt
+ - uses: actions-rs/cargo@v1
+ with:
+ command: fmt
+ args: --all -- --check
+
diff --git a/rustfmt.toml b/rustfmt.toml
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/rustfmt.toml
diff --git a/src/boundaries.rs b/src/boundaries.rs
index 880c9061..436d767b 100644
--- a/src/boundaries.rs
+++ b/src/boundaries.rs
@@ -1,9 +1,13 @@
use std::collections::HashMap;
-fn _debug_log_to_file (message: String) {
+fn _debug_log_to_file(message: String) {
use std::fs::OpenOptions;
use std::io::prelude::*;
- let mut file = OpenOptions::new().append(true).create(true).open("/tmp/mosaic-log.txt").unwrap();
+ let mut file = OpenOptions::new()
+ .append(true)
+ .create(true)
+ .open("/tmp/mosaic-log.txt")
+ .unwrap();
file.write_all(message.as_bytes()).unwrap();
file.write_all("\n".as_bytes()).unwrap();
}
@@ -28,81 +32,139 @@ fn combine_symbols(current_symbol: &str, next_symbol: &str) -> Option<&'static s
match (current_symbol, next_symbol) {
(boundary_type::TOP_RIGHT, boundary_type::TOP_RIGHT) => Some(boundary_type::TOP_RIGHT), // (┐, ┐) => Some(┐)
(boundary_type::TOP_RIGHT, boundary_type::VERTICAL) => Some(boundary_type::VERTICAL_LEFT), // (┐, │) => Some(┤)
- (boundary_type::TOP_RIGHT, boundary_type::HORIZONTAL) => Some(boundary_type::HORIZONTAL_DOWN), // (┐, ─) => Some(┬)
+ (boundary_type::TOP_RIGHT, boundary_type::HORIZONTAL) => {
+ Some(boundary_type::HORIZONTAL_DOWN)
+ } // (┐, ─) => Some(┬)
(boundary_type::TOP_RIGHT, boundary_type::TOP_LEFT) => Some(boundary_type::HORIZONTAL_DOWN), // (┐, ┌) => Some(┬)
- (boundary_type::TOP_RIGHT, boundary_type::BOTTOM_RIGHT) => Some(boundary_type::VERTICAL_LEFT), // (┐, ┘) => Some(┤)
+ (boundary_type::TOP_RIGHT, boundary_type::BOTTOM_RIGHT) => {
+ Some(boundary_type::VERTICAL_LEFT)
+ } // (┐, ┘) => Some(┤)
(boundary_type::TOP_RIGHT, boundary_type::BOTTOM_LEFT) => Some(boundary_type::CROSS), // (┐, └) => Some(┼)
- (boundary_type::TOP_RIGHT, boundary_type::VERTICAL_LEFT) => Some(boundary_type::VERTICAL_LEFT), // (┐, ┤) => Some(┤)
+ (boundary_type::TOP_RIGHT, boundary_type::VERTICAL_LEFT) => {
+ Some(boundary_type::VERTICAL_LEFT)
+ } // (┐, ┤) => Some(┤)
(boundary_type::TOP_RIGHT, boundary_type::VERTICAL_RIGHT) => Some(boundary_type::CROSS), // (┐, ├) => Some(┼)
- (boundary_type::TOP_RIGHT, boundary_type::HORIZONTAL_DOWN) => Some(boundary_type::HORIZONTAL_DOWN), // (┐, ┬) => Some(┬)
+ (boundary_type::TOP_RIGHT, boundary_type::HORIZONTAL_DOWN) => {
+ Some(boundary_type::HORIZONTAL_DOWN)
+ } // (┐, ┬) => Some(┬)
(boundary_type::TOP_RIGHT, boundary_type::HORIZONTAL_UP) => Some(boundary_type::CROSS), // (┐, ┴) => Some(┼)
(boundary_type::TOP_RIGHT, boundary_type::CROSS) => Some(boundary_type::CROSS), // (┐, ┼) => Some(┼)
(boundary_type::HORIZONTAL, boundary_type::HORIZONTAL) => Some(boundary_type::HORIZONTAL), // (─, ─) => Some(─)
(boundary_type::HORIZONTAL, boundary_type::VERTICAL) => Some(boundary_type::CROSS), // (─, │) => Some(┼)
- (boundary_type::HORIZONTAL, boundary_type::TOP_LEFT) => Some(boundary_type::HORIZONTAL_DOWN), // (─, ┌) => Some(┬)
- (boundary_type::HORIZONTAL, boundary_type::BOTTOM_RIGHT) => Some(boundary_type::HORIZONTAL_UP), // (─, ┘) => Some(┴)
- (boundary_type::HORIZONTAL, boundary_type::BOTTOM_LEFT) => Some(boundary_type::HORIZONTAL_UP), // (─, └) => Some(┴)
+ (boundary_type::HORIZONTAL, boundary_type::TOP_LEFT) => {
+ Some(boundary_type::HORIZONTAL_DOWN)
+ } // (─, ┌) => Some(┬)
+ (boundary_type::HORIZONTAL, boundary_type::BOTTOM_RIGHT) => {
+ Some(boundary_type::HORIZONTAL_UP)
+ } // (─, ┘) => Some(┴)
+ (boundary_type::HORIZONTAL, boundary_type::BOTTOM_LEFT) => {
+ Some(boundary_type::HORIZONTAL_UP)
+ } // (─, └) => Some(┴)
(boundary_type::HORIZONTAL, boundary_type::VERTICAL_LEFT) => Some(boundary_type::CROSS), // (─, ┤) => Some(┼)
(boundary_type::HORIZONTAL, boundary_type::VERTICAL_RIGHT) => Some(boundary_type::CROSS), // (─, ├) => Some(┼)
- (boundary_type::HORIZONTAL, boundary_type::HORIZONTAL_DOWN) => Some(boundary_type::HORIZONTAL_DOWN), // (─, ┬) => Some(┬)
- (boundary_type::HORIZONTAL, boundary_type::HORIZONTAL_UP) => Some(boundary_type::HORIZONTAL_UP), // (─, ┴) => Some(┴)
+ (boundary_type::HORIZONTAL, boundary_type::HORIZONTAL_DOWN) => {
+ Some(boundary_type::HORIZONTAL_DOWN)
+ } // (─, ┬) => Some(┬)
+ (boundary_type::HORIZONTAL, boundary_type::HORIZONTAL_UP) => {
+ Some(boundary_type::HORIZONTAL_UP)
+ } // (─, ┴) => Some(┴)
(boundary_type::HORIZONTAL, boundary_type::CROSS) => Some(boundary_type::CROSS), // (─, ┼) => Some(┼)
(boundary_type::VERTICAL, boundary_type::VERTICAL) => Some(boundary_type::VERTICAL), // (│, │) => Some(│)
(boundary_type::VERTICAL, boundary_type::TOP_LEFT) => Some(boundary_type::VERTICAL_RIGHT), // (│, ┌) => Some(├)
- (boundary_type::VERTICAL, boundary_type::BOTTOM_RIGHT) => Some(boundary_type::VERTICAL_LEFT), // (│, ┘) => Some(┤)
- (boundary_type::VERTICAL, boundary_type::BOTTOM_LEFT) => Some(boundary_type::VERTICAL_RIGHT), // (│, └) => Some(├)
- (boundary_type::VERTICAL, boundary_type::VERTICAL_LEFT) => Some(boundary_type::VERTICAL_LEFT), // (│, ┤) => Some(┤)
- (boundary_type::VERTICAL, boundary_type::VERTICAL_RIGHT) => Some(boundary_type::VERTICAL_RIGHT), // (│, ├) => Some(├)
+ (boundary_type::VERTICAL, boundary_type::BOTTOM_RIGHT) => {
+ Some(boundary_type::VERTICAL_LEFT)
+ } // (│, ┘) => Some(┤)
+ (boundary_type::VERTICAL, boundary_type::BOTTOM_LEFT) => {
+ Some(boundary_type::VERTICAL_RIGHT)
+ } // (│, └) => Some(├)
+ (boundary_type::VERTICAL, boundary_type::VERTICAL_LEFT) => {
+ Some(boundary_type::VERTICAL_LEFT)
+ } // (│, ┤) => Some(┤)
+ (boundary_type::VERTICAL, boundary_type::VERTICAL_RIGHT) => {
+ Some(boundary_type::VERTICAL_RIGHT)
+ } // (│, ├) => Some(├)
(boundary_type::VERTICAL, boundary_type::HORIZONTAL_DOWN) => Some(boundary_type::CROSS), // (│, ┬) => Some(┼)
(boundary_type::VERTICAL, boundary_type::HORIZONTAL_UP) => Some(boundary_type::CROSS), // (│, ┴) => Some(┼)
(boundary_type::VERTICAL, boundary_type::CROSS) => Some(boundary_type::CROSS), // (│, ┼) => Some(┼)
(boundary_type::TOP_LEFT, boundary_type::TOP_LEFT) => Some(boundary_type::TOP_LEFT), // (┌, ┌) => Some(┌)
(boundary_type::TOP_LEFT, boundary_type::BOTTOM_RIGHT) => Some(boundary_type::CROSS), // (┌, ┘) => Some(┼)
- (boundary_type::TOP_LEFT, boundary_type::BOTTOM_LEFT) => Some(boundary_type::VERTICAL_RIGHT), // (┌, └) => Some(├)
+ (boundary_type::TOP_LEFT, boundary_type::BOTTOM_LEFT) => {
+ Some(boundary_type::VERTICAL_RIGHT)
+ } // (┌, └) => Some(├)
(boundary_type::TOP_LEFT, boundary_type::VERTICAL_LEFT) => Some(boundary_type::CROSS), // (┌, ┤) => Some(┼)
- (boundary_type::TOP_LEFT, boundary_type::VERTICAL_RIGHT) => Some(boundary_type::VERTICAL_RIGHT), // (┌, ├) => Some(├)
- (boundary_type::TOP_LEFT, boundary_type::HORIZONTAL_DOWN) => Some(boundary_type::HORIZONTAL_DOWN), // (┌, ┬) => Some(┬)
+ (boundary_type::TOP_LEFT, boundary_type::VERTICAL_RIGHT) => {
+ Some(boundary_type::VERTICAL_RIGHT)
+ } // (┌, ├) => Some(├)
+ (boundary_type::TOP_LEFT, boundary_type::HORIZONTAL_DOWN) => {
+ Some(boundary_type::HORIZONTAL_DOWN)
+ } // (┌, ┬) => Some(┬)
(boundary_type::TOP_LEFT, boundary_type::HORIZONTAL_UP) => Some(boundary_type::CROSS), // (┌, ┴) => Some(┼)
(boundary_type::TOP_LEFT, boundary_type::CROSS) => Some(boundary_type::CROSS), // (┌, ┼) => Some(┼)
- (boundary_type::BOTTOM_RIGHT, boundary_type::BOTTOM_RIGHT) => Some(boundary_type::BOTTOM_RIGHT), // (┘, ┘) => Some(┘)
- (boundary_type::BOTTOM_RIGHT, boundary_type::BOTTOM_LEFT) => Some(boundary_type::HORIZONTAL_UP), // (┘, └) => Some(┴)
- (boundary_type::BOTTOM_RIGHT, boundary_type::VERTICAL_LEFT) => Some(boundary_type::VERTICAL_LEFT), // (┘, ┤) => Some(┤)
+ (boundary_type::BOTTOM_RIGHT, boundary_type::BOTTOM_RIGHT) => {
+ Some(boundary_type::BOTTOM_RIGHT)
+ } // (┘, ┘) => Some(┘)
+ (boundary_type::BOTTOM_RIGHT, boundary_type::BOTTOM_LEFT) => {
+ Some(boundary_type::HORIZONTAL_UP)
+ } // (┘, └) => Some(┴)
+ (boundary_type::BOTTOM_RIGHT, boundary_type::VERTICAL_LEFT) => {
+ Some(boundary_type::VERTICAL_LEFT)
+ } // (┘, ┤) => Some(┤)
(boundary_type::BOTTOM_RIGHT, boundary_type::VERTICAL_RIGHT) => Some(boundary_type::CROSS), // (┘, ├) => Some(┼)
(boundary_type::BOTTOM_RIGHT, boundary_type::HORIZONTAL_DOWN) => Some(boundary_type::CROSS), // (┘, ┬) => Some(┼)
- (boundary_type::BOTTOM_RIGHT, boundary_type::HORIZONTAL_UP) => Some(boundary_type::HORIZONTAL_UP), // (┘, ┴) => Some(┴)
+ (boundary_type::BOTTOM_RIGHT, boundary_type::HORIZONTAL_UP) => {
+ Some(boundary_type::HORIZONTAL_UP)
+ } // (┘, ┴) => Some(┴)
(boundary_type::BOTTOM_RIGHT, boundary_type::CROSS) => Some(boundary_type::CROSS), // (┘, ┼) => Some(┼)
- (boundary_type::BOTTOM_LEFT, boundary_type::BOTTOM_LEFT) => Some(boundary_type::BOTTOM_LEFT), // (└, └) => Some(└)
+ (boundary_type::BOTTOM_LEFT, boundary_type::BOTTOM_LEFT) => {
+ Some(boundary_type::BOTTOM_LEFT)
+ } // (└, └) => Some(└)
(boundary_type::BOTTOM_LEFT, boundary_type::VERTICAL_LEFT) => Some(boundary_type::CROSS), // (└, ┤) => Some(┼)
- (boundary_type::BOTTOM_LEFT, boundary_type::VERTICAL_RIGHT) => Some(boundary_type::VERTICAL_RIGHT), // (└, ├) => Some(├)
+ (boundary_type::BOTTOM_LEFT, boundary_type::VERTICAL_RIGHT) => {
+ Some(boundary_type::VERTICAL_RIGHT)
+ } // (└, ├) => Some(├)
(boundary_type::BOTTOM_LEFT, boundary_type::HORIZONTAL_DOWN) => Some(boundary_type::CROSS), // (└, ┬) => Some(┼)
- (boundary_type::BOTTOM_LEFT, boundary_type::HORIZONTAL_UP) => Some(boundary_type::HORIZONTAL_UP), // (└, ┴) => Some(┴)
+ (boundary_type::BOTTOM_LEFT, boundary_type::HORIZONTAL_UP) => {
+ Some(boundary_type::HORIZONTAL_UP)
+ } // (└, ┴) => Some(┴)
(boundary_type::BOTTOM_LEFT, boundary_type::CROSS) => Some(boundary_type::CROSS), // (└, ┼) => Some(┼)
- (boundary_type::VERTICAL_LEFT, boundary_type::VERTICAL_LEFT) => Some(boundary_type::VERTICAL_LEFT), // (┤, ┤) => Some(┤)
+ (boundary_type::VERTICAL_LEFT, boundary_type::VERTICAL_LEFT) => {
+ Some(boundary_type::VERTICAL_LEFT)
+ } // (┤, ┤) => Some(┤)
(boundary_type::VERTICAL_LEFT, boundary_type::VERTICAL_RIGHT) => Some(boundary_type::CROSS), // (┤, ├) => Some(┼)
- (boundary_type::VERTICAL_LEFT, boundary_type::HORIZONTAL_DOWN) => Some(boundary_type::CROSS), // (┤, ┬) => Some(┼)
- (boundary_type::VERTICAL_LEFT, boundary_type::HORIZONTAL_UP) => Some(boundary_type::HORIZONTAL_UP), // (┤, ┴) => Some(┼)
+ (boundary_type::VERTICAL_LEFT, boundary_type::HORIZONTAL_DOWN) => {
+ Some(boundary_type::CROSS)
+ } // (┤, ┬) => Some(┼)
+ (boundary_type::VERTICAL_LEFT, boundary_type::HORIZONTAL_UP) => {
+ Some(boundary_type::HORIZONTAL_UP)
+ } // (┤, ┴) => Some(┼)
(boundary_type::VERTICAL_LEFT, boundary_type::CROSS) => Some(boundary_type::CROSS), // (┤, ┼) => Some(┼)
(boundary_type::VERTICAL_RIGHT, boundary_type::VERTICAL_RIGHT) => {
Some(boundary_type::VERTICAL_RIGHT)
} // (├, ├) => Some(├)
- (boundary_type::VERTICAL_RIGHT, boundary_type::HORIZONTAL_DOWN) => Some(boundary_type::CROSS), // (├, ┬) => Some(┼)
+ (boundary_type::VERTICAL_RIGHT, boundary_type::HORIZONTAL_DOWN) => {
+ Some(boundary_type::CROSS)
+ } // (├, ┬) => Some(┼)
(boundary_type::VERTICAL_RIGHT, boundary_type::HORIZONTAL_UP) => Some(boundary_type::CROSS), // (├, ┴) => Some(┼)
(boundary_type::VERTICAL_RIGHT, boundary_type::CROSS) => Some(boundary_type::CROSS), // (├, ┼) => Some(┼)
(boundary_type::HORIZONTAL_DOWN, boundary_type::HORIZONTAL_DOWN) => {
Some(boundary_type::HORIZONTAL_DOWN)
} // (┬, ┬) => Some(┬)
- (boundary_type::HORIZONTAL_DOWN, boundary_type::HORIZONTAL_UP) => Some(boundary_type::CROSS), // (┬, ┴) => Some(┼)
+ (boundary_type::HORIZONTAL_DOWN, boundary_type::HORIZONTAL_UP) => {
+ Some(boundary_type::CROSS)
+ } // (┬, ┴) => Some(┼)
(boundary_type::HORIZONTAL_DOWN, boundary_type::CROSS) => Some(boundary_type::CROSS), // (┬, ┼) => Some(┼)
- (boundary_type::HORIZONTAL_UP, boundary_type::HORIZONTAL_UP) => Some(boundary_type::HORIZONTAL_UP), // (┴, ┴) => Some(┴)
+ (boundary_type::HORIZONTAL_UP, boundary_type::HORIZONTAL_UP) => {
+ Some(boundary_type::HORIZONTAL_UP)
+ } // (┴, ┴) => Some(┴)
(boundary_type::HORIZONTAL_UP, boundary_type::CROSS) => Some(boundary_type::CROSS), // (┴, ┼) => Some(┼)
(boundary_type::CROSS, boundary_type::CROSS) => Some(boundary_type::CROSS), // (┼, ┼) => Some(┼)
@@ -127,7 +189,7 @@ pub struct Coordinates {
impl Coordinates {
pub fn new(x: usize, y: usize) -> Self {
- Coordinates {x, y}
+ Coordinates { x, y }
}
}
@@ -136,10 +198,10 @@ pub trait Rect {
fn y(&self) -> usize;
fn rows(&self) -> usize;
fn columns(&self) -> usize;
- fn right_boundary_x_coords (&self) -> usize {
+ fn right_boundary_x_coords(&self) -> usize {
self.x() + self.columns()
}
- fn bottom_boundary_y_coords (&self) -> usize {
+ fn bottom_boundary_y_coords(&self) -> usize {
self.y() + self.rows()
}
}
@@ -175,7 +237,9 @@ impl Boundaries {
} else {
boundary_type::VERTICAL
};
- let next_symbol = self.boundary_characters.get(&coordinates)
+ let next_symbol = self
+ .boundary_characters
+ .get(&coordinates)
.and_then(|current_symbol| find_next_symbol(current_symbol, symbol_to_add))
.unwrap_or(symbol_to_add);
self.boundary_characters.insert(coordinates, next_symbol);
@@ -194,42 +258,65 @@ impl Boundaries {
} else {
boundary_type::HORIZONTAL
};
- let next_symbol = self.boundary_characters.get(&coordinates)
+ let next_symbol = self
+ .boundary_characters
+ .get(&coordinates)
.and_then(|current_symbol| find_next_symbol(current_symbol, symbol_to_add))
.unwrap_or(symbol_to_add);
self.boundary_characters.insert(coordinates, next_symbol);
}
}
}
- pub fn vte_output (&self) -> String {
+ pub fn vte_output(&self) -> String {
let mut vte_output = String::new();
for (coordinates, boundary_character) in &self.boundary_characters {
- vte_output.push_str(&format!("\u{1b}[{};{}H\u{1b}[m{}", coordinates.y + 1, coordinates.x + 1, boundary_character)); // goto row/col + boundary character
+ vte_output.push_str(&format!(
+ "\u{1b}[{};{}H\u{1b}[m{}",
+ coordinates.y + 1,
+ coordinates.x + 1,
+ boundary_character
+ )); // goto row/col + boundary character
}
vte_output
}
- fn rect_right_boundary_is_before_screen_edge <R: Rect>(&self, rect: &R) -> bool {
+ fn rect_right_boundary_is_before_screen_edge<R: Rect>(&self, rect: &R) -> bool {
rect.x() + rect.columns() < self.columns
}
fn rect_bottom_boundary_is_before_screen_edge<R: Rect>(&self, rect: &R) -> bool {
rect.y() + rect.rows() < self.rows
}
fn rect_right_boundary_row_start<R: Rect>(&self, rect: &R) -> usize {
- if rect.y() == 0 { 0 } else { rect.y() - 1 }
+ if rect.y() == 0 {
+ 0
+ } else {
+ rect.y() - 1
+ }
}
fn rect_right_boundary_row_end<R: Rect>(&self, rect: &R) -> usize {
let rect_bottom_row = rect.y() + rect.rows();
// we do this because unless we're on the screen edge, we'd like to go one extra row to
// connect to whatever boundary is beneath us
- if rect_bottom_row == self.rows { rect_bottom_row } else { rect_bottom_row + 1 }
+ if rect_bottom_row == self.rows {
+ rect_bottom_row
+ } else {
+ rect_bottom_row + 1
+ }
}
fn rect_bottom_boundary_col_start<R: Rect>(&self, rect: &R) -> usize {
- if rect.x() == 0 { 0 } else { rect.x() - 1 }
+ if rect.x() == 0 {
+ 0
+ } else {
+ rect.x() - 1
+ }
}
fn rect_bottom_boundary_col_end<R: Rect>(&self, rect: &R) -> usize {
let rect_right_col = rect.x() + rect.columns();
// we do this because unless we're on the screen edge, we'd like to go one extra column to
// connect to whatever boundary is right of us
- if rect_right_col == self.columns { rect_right_col } else { rect_right_col + 1 }
+ if rect_right_col == self.columns {
+ rect_right_col
+ } else {
+ rect_right_col + 1
+ }
}
}
diff --git a/src/main.rs b/src/main.rs
index d996df1b..b964efa7 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,23 +1,23 @@
#[cfg(test)]
mod tests;
+mod boundaries;
mod os_input_output;
-mod terminal_pane;
mod pty_bus;
mod screen;
-mod boundaries;
+mod terminal_pane;
use std::io::{Read, Write};
-use std::thread;
use std::os::unix::net::UnixStream;
use std::path::PathBuf;
-use std::sync::mpsc::{channel, Sender, Receiver};
+use std::sync::mpsc::{channel, Receiver, Sender};
+use std::thread;
-use serde::{Serialize, Deserialize};
+use serde::{Deserialize, Serialize};
use structopt::StructOpt;
use crate::os_input_output::{get_os_input, OsApi};
-use crate::pty_bus::{VteEvent, PtyBus, PtyInstruction};
+use crate::pty_bus::{PtyBus, PtyInstruction, VteEvent};
use crate::screen::{Screen, ScreenInstruction};
#[derive(Serialize, Deserialize, Debug)]
@@ -45,13 +45,17 @@ pub struct Opt {
max_panes: Option<usize>,
#[structopt(short, long)]
- debug: bool
+ debug: bool,
}
-fn _debug_log_to_file (message: String) {
+fn _debug_log_to_file(message: String) {
use std::fs::OpenOptions;
use std::io::prelude::*;
- let mut file = OpenOptions::new().append(true).create(true).open("/tmp/mosaic-log.txt").unwrap();
+ let mut file = OpenOptions::new()
+ .append(true)
+ .create(true)
+ .open("/tmp/mosaic-log.txt")
+ .unwrap();
file.write_all(message.as_bytes()).unwrap();
file.write_all("\n".as_bytes()).unwrap();
}
@@ -70,12 +74,12 @@ pub fn main() {
let mut stream = UnixStream::connect("/tmp/mosaic").unwrap();
let api_command = bincode::serialize(&ApiCommand::SplitHorizontally).unwrap();
stream.write_all(&api_command).unwrap();
- },
+ }
Some('v') => {
let mut stream = UnixStream::connect("/tmp/mosaic").unwrap();
let api_command = bincode::serialize(&ApiCommand::SplitVertically).unwrap();
stream.write_all(&api_command).unwrap();
- },
+ }
_ => {}
};
} else if opts.move_focus {
@@ -94,7 +98,7 @@ pub fn main() {
}
pub enum AppInstruction {
- Exit
+ Exit,
}
pub fn start(mut os_input: Box<dyn OsApi>, opts: Opt) {
@@ -104,11 +108,32 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: Opt) {
let full_screen_ws = os_input.get_terminal_size_using_fd(0);
os_input.into_raw_mode(0);
- let (send_screen_instructions, receive_screen_instructions): (Sender<ScreenInstruction>, Receiver<ScreenInstruction>) = channel();
- let (send_pty_instructions, receive_pty_instructions): (Sender<PtyInstruction>, Receiver<PtyInstruction>) = channel();
- let (send_app_instructions, receive_app_instructions): (Sender<AppInstruction>, Receiver<AppInstruction>) = channel();
- let mut screen = Screen::new(receive_screen_instructions, send_pty_instructions.clone(), send_app_instructions.clone(), &full_screen_ws, os_input.clone(), opts.max_panes);
- let mut pty_bus = PtyBus::new(receive_pty_instructions, send_screen_instructions.clone(), os_input.clone(), opts.debug);
+ let (send_screen_instructions, receive_screen_instructions): (
+ Sender<ScreenInstruction>,
+ Receiver<ScreenInstruction>,
+ ) = channel();
+ let (send_pty_instructions, receive_pty_instructions): (
+ Sender<PtyInstruction>,
+ Receiver<PtyInstruction>,
+ ) = channel();
+ let (send_app_instructions, receive_app_instructions): (
+ Sender<AppInstruction>,
+ Receiver<AppInstruction>,
+ ) = channel();
+ let mut screen = Screen::new(
+ receive_screen_instructions,
+ send_pty_instructions.clone(),
+ send_app_instructions.clone(),
+ &full_screen_ws,
+ os_input.clone(),
+ opts.max_panes,
+ );
+ let mut pty_bus = PtyBus::new(
+ receive_pty_instructions,
+ send_screen_instructions.clone(),
+ os_input.clone(),
+ opts.debug,
+ );
active_threads.push(
thread::Builder::new()
@@ -117,7 +142,8 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: Opt) {
move || {
pty_bus.spawn_terminal_vertically(None);
loop {
- let event = pty_bus.receive_pty_instructions
+ let event = pty_bus
+ .receive_pty_instructions
.recv()
.expect("failed to receive event on channel");
match event {
@@ -139,77 +165,78 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: Opt) {
}
}
}
- }).unwrap()
+ })
+ .unwrap(),
);
active_threads.push(
thread::Builder::new()
.name("screen".to_string())
.spawn({
- move || {
- loop {
- let event = screen.receiver
- .recv()
- .expect("failed to receive event on channel");
- match event {
- ScreenInstruction::Pty(pid, vte_event) => {
- screen.handle_pty_event(pid, vte_event);
- },
- ScreenInstruction::Render => {
- screen.render();
- },
- ScreenInstruction::NewPane(pid) => {
- screen.new_pane(pid);
- }
- ScreenInstruction::HorizontalSplit(pid) => {
- screen.horizontal_split(pid);
- }
- ScreenInstruction::VerticalSplit(pid) => {
- screen.vertical_split(pid);
- }
- ScreenInstruction::WriteCharacter(bytes) => {
- screen.write_to_active_terminal(bytes);
- }
- ScreenInstruction::ResizeLeft => {
- screen.resize_left();
- }
- ScreenInstruction::ResizeRight => {
- screen.resize_right();
- }
- ScreenInstruction::ResizeDown => {
- screen.resize_down();
- }
- ScreenInstruction::ResizeUp => {
- screen.resize_up();
- }
- ScreenInstruction::MoveFocus => {
- screen.move_focus();
- }
- ScreenInstruction::ScrollUp => {
- screen.scroll_active_terminal_up();
- }
- ScreenInstruction::ScrollDown => {
- screen.scroll_active_terminal_down();
- }
- ScreenInstruction::ClearScroll => {
- screen.clear_active_terminal_scroll();
- }
- ScreenInstruction::CloseFocusedPane => {
- screen.close_focused_pane();
- }
- ScreenInstruction::ClosePane(id) => {
- screen.close_pane(id);
- }
- ScreenInstruction::ToggleActiveTerminalFullscreen => {
- screen.toggle_active_terminal_fullscreen();
- }
- ScreenInstruction::Quit => {
- break;
- }
+ move || loop {
+ let event = screen
+ .receiver
+ .recv()
+ .expect("failed to receive event on channel");
+ match event {
+ ScreenInstruction::Pty(pid, vte_event) => {
+ screen.handle_pty_event(pid, vte_event);
+ }
+ ScreenInstruction::Render => {
+ screen.render();
+ }
+ ScreenInstruction::NewPane(pid) => {
+ screen.new_pane(pid);
+ }
+ ScreenInstruction::HorizontalSplit(pid) => {
+ screen.horizontal_split(pid);
+ }
+ ScreenInstruction::VerticalSplit(pid) => {
+ screen.vertical_split(pid);
+ }
+ ScreenInstruction::WriteCharacter(bytes) => {
+ screen.write_to_active_terminal(bytes);
+ }
+ ScreenInstruction::ResizeLeft => {
+ screen.resize_left();
+ }
+ ScreenInstruction::ResizeRight => {
+ screen.resize_right();
+ }
+ ScreenInstruction::ResizeDown => {
+ screen.resize_down();
+ }
+ ScreenInstruction::ResizeUp => {
+ screen.resize_up();
+ }
+ ScreenInstruction::MoveFocus => {
+ screen.move_focus();
+ }
+ ScreenInstruction::ScrollUp => {
+ screen.scroll_active_terminal_up();
+ }
+ ScreenInstruction::ScrollDown => {
+ screen.scroll_active_terminal_down();
+ }
+ ScreenInstruction::ClearScroll => {
+ screen.clear_active_terminal_scroll();
+ }
+ ScreenInstruction::CloseFocusedPane => {
+ screen.close_focused_pane();
+ }
+ ScreenInstruction::ClosePane(id) => {
+ screen.close_pane(id);
+ }
+ ScreenInstruction::ToggleActiveTerminalFullscreen => {
+ screen.toggle_active_terminal_fullscreen();
+ }
+ ScreenInstruction::Quit => {
+ break;
}
}
}
- }).unwrap()
+ })
+ .unwrap(),
);
// TODO: currently we don't push this into active_threads
@@ -223,27 +250,39 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: Opt) {
let send_screen_instructions = send_screen_instructions.clone();
move || {
::std::fs::remove_file("/tmp/mosaic").ok();
- let listener = ::std::os::unix::net::UnixListener::bind("/tmp/mosaic").expect("could not listen on ipc socket");
+ let listener = ::std::os::unix::net::UnixListener::bind("/tmp/mosaic")
+ .expect("could not listen on ipc socket");
for stream in listener.incoming() {
match stream {
Ok(mut stream) => {
let mut buffer = [0; 65535]; // TODO: more accurate
- stream.read(&mut buffer).expect("failed to parse ipc message");
- let decoded: ApiCommand = bincode::deserialize(&buffer).expect("failed to deserialize ipc message");
+ stream
+ .read(&mut buffer)
+ .expect("failed to parse ipc message");
+ let decoded: ApiCommand = bincode::deserialize(&buffer)
+ .expect("failed to deserialize ipc message");
match &decoded {
ApiCommand::OpenFile(file_name) => {
let path = PathBuf::from(file_name);
- send_pty_instructions.send(PtyInstruction::SpawnTerminal(Some(path))).unwrap();
+ send_pty_instructions
+ .send(PtyInstruction::SpawnTerminal(Some(path)))
+ .unwrap();
}
ApiCommand::SplitHorizontally => {
- send_pty_instructions.send(PtyInstruction::SpawnTerminalHorizontally(None)).unwrap();
+ send_pty_instructions
+ .send(PtyInstruction::SpawnTerminalHorizontally(None))
+ .unwrap();
}
ApiCommand::SplitVertically => {
- send_pty_instructions.send(PtyInstruction::SpawnTerminalVertically(None)).unwrap();
+ send_pty_instructions
+ .send(PtyInstruction::SpawnTerminalVertically(None))
+ .unwrap();
}
ApiCommand::MoveFocus => {
- send_screen_instructions.send(ScreenInstruction::MoveFocus).unwrap();
+ send_screen_instructions
+ .send(ScreenInstruction::MoveFocus)
+ .unwrap();
}
}
}
@@ -253,7 +292,8 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: Opt) {
}
}
}
- }).unwrap();
+ })
+ .unwrap();
let _stdin_thread = thread::Builder::new()
.name("ipc_server".to_string())
@@ -270,66 +310,109 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: Opt) {
// uncomment this to print the entered character to a log file (/tmp/mosaic-log.txt) for debugging
// _debug_log_to_file(format!("buffer {:?}", buffer));
match buffer {
- [10, 0, 0, 0, 0, 0, 0, 0, 0, 0] => { // ctrl-j
- send_screen_instructions.send(ScreenInstruction::ResizeDown).unwrap();
- },
- [11, 0, 0, 0, 0, 0, 0, 0, 0, 0] => { // ctrl-k
- send_screen_instructions.send(ScreenInstruction::ResizeUp).unwrap();
- },
- [16, 0, 0, 0, 0, 0, 0, 0, 0, 0] => { // ctrl-p
- send_screen_instructions.send(ScreenInstruction::MoveFocus).unwrap();
- },
- [8, 0, 0, 0, 0, 0, 0, 0, 0, 0] => { // ctrl-h
- send_screen_instructions.send(ScreenInstruction::ResizeLeft).unwrap();
- },
- [12, 0, 0, 0, 0, 0, 0, 0, 0, 0] => { // ctrl-l
- send_screen_instructions.send(ScreenInstruction::ResizeRight).unwrap();
- },
- [26, 0, 0, 0, 0, 0, 0, 0, 0, 0] => { // ctrl-z
- send_pty_instructions.send(PtyInstruction::SpawnTerminal(None)).unwrap();
- },
- [14, 0, 0, 0, 0, 0, 0, 0, 0, 0] => { // ctrl-n
- send_pty_instructions.send(PtyInstruction::SpawnTerminalVertically(None)).unwrap();
- },
- [2, 0, 0, 0, 0, 0, 0, 0, 0, 0] => { // ctrl-b
- send_pty_instructions.send(PtyInstruction::SpawnTerminalHorizontally(None)).unwrap();
- },
- [17, 0, 0, 0, 0, 0, 0, 0, 0, 0] => { // ctrl-q
+ [10, 0, 0, 0, 0, 0, 0, 0, 0, 0] => {
+ // ctrl-j
+ send_screen_instructions
+ .send(ScreenInstruction::ResizeDown)
+ .unwrap();
+ }
+ [11, 0, 0, 0, 0, 0, 0, 0, 0, 0] => {
+ // ctrl-k
+ send_screen_instructions
+ .send(ScreenInstruction::ResizeUp)
+ .unwrap();
+ }
+ [16, 0, 0, 0, 0, 0, 0, 0, 0, 0] => {
+ // ctrl-p
+ send_screen_instructions
+ .send(ScreenInstruction::MoveFocus)
+ .unwrap();
+ }
+ [8, 0, 0, 0, 0, 0, 0, 0, 0, 0] => {
+ // ctrl-h
+ send_screen_instructions
+ .send(ScreenInstruction::ResizeLeft)
+ .unwrap();
+ }
+ [12, 0, 0, 0, 0, 0, 0, 0, 0, 0] => {
+ // ctrl-l
+ send_screen_instructions
+ .send(ScreenInstruction::ResizeRight)
+ .unwrap();
+ }
+ [26, 0, 0, 0, 0, 0, 0, 0, 0, 0] => {
+ // ctrl-z
+ send_pty_instructions
+ .send(PtyInstruction::SpawnTerminal(None))
+ .unwrap();
+ }
+ [14, 0, 0, 0, 0, 0, 0, 0, 0, 0] => {
+ // ctrl-n
+ send_pty_instructions
+ .send(PtyInstruction::SpawnTerminalVertically(None))
+ .unwrap();
+ }
+ [2, 0, 0, 0, 0, 0, 0, 0, 0, 0] => {
+ // ctrl-b
+ send_pty_instructions
+ .send(PtyInstruction::SpawnTerminalHorizontally(None))
+ .unwrap();
+ }
+ [17, 0, 0, 0, 0, 0, 0, 0, 0, 0] => {
+ // ctrl-q
let _ = send_screen_instructions.send(ScreenInstruction::Quit);
let _ = send_pty_instructions.send(PtyInstruction::Quit);
let _ = send_app_instructions.send(AppInstruction::Exit);
break;
- },
- [27, 91, 53, 94, 0, 0, 0, 0, 0, 0] => { // ctrl-PgUp
- send_screen_instructions.send(ScreenInstruction::ScrollUp).unwrap();
- },
- [27, 91, 54, 94, 0, 0, 0, 0, 0, 0] => { // ctrl-PgDown
- send_screen_instructions.send(ScreenInstruction::ScrollDown).unwrap();
- },
- [24, 0, 0, 0, 0, 0, 0, 0, 0, 0] => { // ctrl-x
- send_screen_instructions.send(ScreenInstruction::CloseFocusedPane).unwrap();
+ }
+ [27, 91, 53, 94, 0, 0, 0, 0, 0, 0] => {
+ // ctrl-PgUp
+ send_screen_instructions
+ .send(ScreenInstruction::ScrollUp)
+ .unwrap();
+ }
+ [27, 91, 54, 94, 0, 0, 0, 0, 0, 0] => {
+ // ctrl-PgDown
+ send_screen_instructions
+ .send(ScreenInstruction::ScrollDown)
+ .unwrap();
+ }
+ [24, 0, 0, 0, 0, 0, 0, 0, 0, 0] => {
+ // ctrl-x
+ send_screen_instructions
+ .send(ScreenInstruction::CloseFocusedPane)
+ .unwrap();
// ::std::thread::sleep(::std::time::Duration::from_millis(10));
- },
- [5, 0, 0, 0, 0, 0, 0, 0, 0, 0] => { // ctrl-e
- send_screen_instructions.send(ScreenInstruction::ToggleActiveTerminalFullscreen).unwrap();
- },
+ }
+ [5, 0, 0, 0, 0, 0, 0, 0, 0, 0] => {
+ // ctrl-e
+ send_screen_instructions
+ .send(ScreenInstruction::ToggleActiveTerminalFullscreen)
+ .unwrap();
+ }
_ => {
- send_screen_instructions.send(ScreenInstruction::ClearScroll).unwrap();
- send_screen_instructions.send(ScreenInstruction::WriteCharacter(buffer)).unwrap();
+ send_screen_instructions
+ .send(ScreenInstruction::ClearScroll)
+ .unwrap();
+ send_screen_instructions
+ .send(ScreenInstruction::WriteCharacter(buffer))
+ .unwrap();
}
}
- };
+ }
}
});
loop {
- let app_instruction = receive_app_instructions.recv().expect("failed to receive app instruction on channel");
+ let app_instruction = receive_app_instructions
+ .recv()
+ .expect("failed to receive app instruction on channel");
match app_instruction {
AppInstruction::Exit => {
let _ = send_screen_instructions.send(ScreenInstruction::Quit);
let _ = send_pty_instructions.send(PtyInstruction::Quit);
break;
- },
+ }
}
}
@@ -339,9 +422,15 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: Opt) {
// cleanup();
let reset_style = "\u{1b}[m";
let goto_start_of_last_line = format!("\u{1b}[{};{}H", full_screen_ws.ws_row, 1);
- let goodbye_message = format!("{}\n{}Bye from Mosaic!", goto_start_of_last_line, reset_style);
+ let goodbye_message = format!(
+ "{}\n{}Bye from Mosaic!",
+ goto_start_of_last_line, reset_style
+ );
os_input.unset_raw_mode(0);
- os_input.get_stdout_writer().write(goodbye_message.as_bytes()).unwrap();
+ os_input
+ .get_stdout_writer()
+ .write(goodbye_message.as_bytes())
+ .unwrap();
os_input.get_stdout_writer().flush().unwrap();
}
diff --git a/src/os_input_output.rs b/src/os_input_output.rs
index 14690cf5..251b8c5e 100644
--- a/src/os_input_output.rs
+++ b/src/os_input_output.rs
@@ -1,20 +1,13 @@
-use nix::unistd::{read, write, ForkResult, Pid};
use nix::fcntl::{fcntl, FcntlArg, OFlag};
-use nix::sys::termios::{
- Termios,
- tcgetattr,
- cfmakeraw,
- tcsetattr,
- SetArg,
- tcdrain,
-};
-use nix::sys::wait::waitpid;
-use nix::sys::signal::{kill, Signal};
use nix::pty::{forkpty, Winsize};
-use std::os::unix::io::RawFd;
-use std::process::{Command, Child};
+use nix::sys::signal::{kill, Signal};
+use nix::sys::termios::{cfmakeraw, tcdrain, tcgetattr, tcsetattr, SetArg, Termios};
+use nix::sys::wait::waitpid;
+use nix::unistd::{read, write, ForkResult, Pid};
use std::io::{Read, Write};
+use std::os::unix::io::RawFd;
use std::path::PathBuf;
+use std::process::{Child, Command};
use std::sync::{Arc, Mutex};
use std::env;
@@ -23,15 +16,15 @@ fn into_raw_mode(pid: RawFd) {
let mut tio = tcgetattr(pid).expect("could not get terminal attribute");
cfmakeraw(&mut tio);
match tcsetattr(pid, SetArg::TCSANOW, &mut tio) {
- Ok(_) => {},
- Err(e) => panic!("error {:?}", e)
+ Ok(_) => {}
+ Err(e) => panic!("error {:?}", e),
};
}
fn unset_raw_mode(pid: RawFd, mut orig_termios: Termios) {
match tcsetattr(pid, SetArg::TCSANOW, &mut orig_termios) {
- Ok(_) => {},
- Err(e) => panic!("error {:?}", e)
+ Ok(_) => {}
+ Err(e) => panic!("error {:?}", e),
};
}
@@ -65,10 +58,14 @@ pub fn set_terminal_size_using_fd(fd: RawFd, columns: u16, rows: u16) {
unsafe { ioctl(fd, TIOCSWINSZ.into(), &winsize) };
}
-fn _debug_log_to_file (message: String) {
+fn _debug_log_to_file(message: String) {
use std::fs::OpenOptions;
use std::io::prelude::*;
- let mut file = OpenOptions::new().append(true).create(true).open("/tmp/mosaic-log.txt").unwrap();
+ let mut file = OpenOptions::new()
+ .append(true)
+ .create(true)
+ .open("/tmp/mosaic-log.txt")
+ .unwrap();
file.write_all(message.as_bytes()).unwrap();
file.write_all("\n".as_bytes()).unwrap();
}
@@ -96,11 +93,11 @@ fn handle_command_exit(mut child: Child) {
}
_ => {}
}
- };
+ }
}
}
-fn spawn_terminal (file_to_open: Option<PathBuf>, orig_termios: Termios) -> (RawFd, RawFd) {
+fn spawn_terminal(file_to_open: Option<PathBuf>, orig_termios: Termios) -> (RawFd, RawFd) {
let (pid_primary, pid_secondary): (RawFd, RawFd) = {
match forkpty(None, Some(&orig_termios)) {
Ok(fork_pty_res) => {
@@ -108,26 +105,31 @@ fn spawn_terminal (file_to_open: Option<PathBuf>, orig_termios: Termios) -> (Raw
let pid_secondary = match fork_pty_res.fork_result {
ForkResult::Parent { child } => {
// fcntl(pid_primary, FcntlArg::F_SETFL(OFlag::empty())).expect("could not fcntl");
- fcntl(pid_primary, FcntlArg::F_SETFL(OFlag::O_NONBLOCK)).expect("could not fcntl");
+ fcntl(pid_primary, FcntlArg::F_SETFL(OFlag::O_NONBLOCK))
+ .expect("could not fcntl");
child
- },
- ForkResult::Child => {
- match file_to_open {
- Some(file_to_open) => {
- if env::var("EDITOR").is_err() && env::var("VISUAL").is_err() {
- panic!("Can't edit files if an editor is not defined. To fix: define the EDITOR or VISUAL environment variables with the path to your editor (eg. /usr/bin/vim)");
- }
- let editor = env::var("EDITOR").unwrap_or_else(|_| env::var("VISUAL").unwrap());
-
- let child = Command::new(editor).args(&[file_to_open]).spawn().expect("failed to spawn");
- handle_command_exit(child);
- ::std::process::exit(0);
- },
- None => {
- let child = Command::new(env::var("SHELL").unwrap()).spawn().expect("failed to spawn");
- handle_command_exit(child);
- ::std::process::exit(0);
+ }
+ ForkResult::Child => match file_to_open {
+ Some(file_to_open) => {
+ if env::var("EDITOR").is_err() && env::var("VISUAL").is_err() {
+ panic!("Can't edit files if an editor is not defined. To fix: define the EDITOR or VISUAL environment variables with the path to your editor (eg. /usr/bin/vim)");
}
+ let editor =
+ env::var("EDITOR").unwrap_or_else(|_| env::var("VISUAL").unwrap());
+
+ let child = Command::new(editor)
+ .args(&[file_to_open])
+ .spawn()
+ .expect("failed to spawn");
+ handle_command_exit(child);
+ ::std::process::exit(0);
+ }
+ None => {
+ let child = Command::new(env::var("SHELL").unwrap())
+ .spawn()
+ .expect("failed to spawn");
+ handle_command_exit(child);
+ ::std::process::exit(0);
}
},
};
@@ -209,17 +211,14 @@ impl OsApi for OsInputOutput {
}
}
-impl Clone for Box<dyn OsApi>
-{
+impl Clone for Box<dyn OsApi> {
fn clone(&self) -> Box<dyn OsApi> {
self.box_clone()
}
}
-pub fn get_os_input () -> OsInputOutput {
+pub fn get_os_input() -> OsInputOutput {
let current_termios = tcgetattr(0).unwrap();
let orig_termios = Arc::new(Mutex::new(current_termios));
- OsInputOutput {
- orig_termios
- }
+ OsInputOutput { orig_termios }
}
diff --git a/src/pty_bus.rs b/src/pty_bus.rs
index 148eb33e..9f75e4b8 100644
--- a/src/pty_bus.rs
+++ b/src/pty_bus.rs
@@ -1,13 +1,13 @@
-use ::std::os::unix::io::RawFd;
use ::async_std::stream::*;
use ::async_std::task;
use ::async_std::task::*;
-use ::std::pin::*;
-use ::std::sync::mpsc::{Sender, Receiver};
-use ::std::time::{Instant, Duration};
use ::std::collections::HashMap;
-use std::path::PathBuf;
+use ::std::os::unix::io::RawFd;
+use ::std::pin::*;
+use ::std::sync::mpsc::{Receiver, Sender};
+use ::std::time::{Duration, Instant};
use ::vte;
+use std::path::PathBuf;
use crate::os_input_output::OsApi;
use crate::ScreenInstruction;
@@ -26,10 +26,14 @@ impl ReadFromPid {
}
}
-fn _debug_log_to_file (message: String) {
+fn _debug_log_to_file(message: String) {
use std::fs::OpenOptions;
use std::io::prelude::*;
- let mut file = OpenOptions::new().append(true).create(true).open("/tmp/mosaic-log.txt").unwrap();
+ let mut file = OpenOptions::new()
+ .append(true)
+ .create(true)
+ .open("/tmp/mosaic-log.txt")
+ .unwrap();
file.write_all(message.as_bytes()).unwrap();
file.write_all("\n".as_bytes()).unwrap();
}
@@ -69,17 +73,17 @@ impl Stream for ReadFromPid {
let res = Some(read_buffer[..=*res].to_vec());
return Poll::Ready(res);
}
- },
+ }
Err(e) => {
match e {
nix::Error::Sys(errno) => {
if *errno == nix::errno::Errno::EAGAIN {
- return Poll::Ready(Some(vec![])) // TODO: better with timeout waker somehow
+ return Poll::Ready(Some(vec![])); // TODO: better with timeout waker somehow
} else {
Poll::Ready(None)
}
- },
- _ => Poll::Ready(None)
+ }
+ _ => Poll::Ready(None),
}
}
}
@@ -87,15 +91,16 @@ impl Stream for ReadFromPid {
}
#[derive(Debug)]
-pub enum VteEvent { // TODO: try not to allocate Vecs
+pub enum VteEvent {
+ // TODO: try not to allocate Vecs
Print(char),
- Execute(u8), // byte
+ Execute(u8), // byte
Hook(Vec<i64>, Vec<u8>, bool, char), // params, intermediates, ignore, char
- Put(u8), // byte
+ Put(u8), // byte
Unhook,
OscDispatch(Vec<Vec<u8>>, bool), // params, bell_terminated
CsiDispatch(Vec<i64>, Vec<u8>, bool, char), // params, intermediates, ignore, char
- EscDispatch(Vec<u8>, bool, u8), // intermediates, ignore, byte
+ EscDispatch(Vec<u8>, bool, u8), // intermediates, ignore, byte
}
struct VteEventSender {
@@ -104,52 +109,64 @@ struct VteEventSender {
}
impl VteEventSender {
- pub fn new (id: RawFd, sender: Sender<ScreenInstruction>) -> Self {
+ pub fn new(id: RawFd, sender: Sender<ScreenInstruction>) -> Self {
VteEventSender { id, sender }
}
}
impl vte::Perform for VteEventSender {
fn print(&mut self, c: char) {
- self.sender.send(
- ScreenInstruction::Pty(self.id, VteEvent::Print(c))
- ).unwrap();
+ self.sender
+ .send(ScreenInstruction::Pty(self.id, VteEvent::Print(c)))
+ .unwrap();
}
fn execute(&mut self, byte: u8) {
- self.sender.send(ScreenInstruction::Pty(self.id, VteEvent::Execute(byte))).unwrap();
+ self.sender
+ .send(ScreenInstruction::Pty(self.id, VteEvent::Execute(byte)))
+ .unwrap();
}
fn hook(&mut self, params: &[i64], intermediates: &[u8], ignore: bool, c: char) {
let params = params.iter().copied().collect();
let intermediates = intermediates.iter().copied().collect();
- let instruction = ScreenInstruction::Pty(self.id, VteEvent::Hook(params, intermediates, ignore, c));
+ let instruction =
+ ScreenInstruction::Pty(self.id, VteEvent::Hook(params, intermediates, ignore, c));
self.sender.send(instruction).unwrap();
}
fn put(&mut self, byte: u8) {
- self.sender.send(ScreenInstruction::Pty(self.id, VteEvent::Put(byte))).unwrap();
+ self.sender
+ .send(ScreenInstruction::Pty(self.id, VteEvent::Put(byte)))
+ .unwrap();
}
fn unhook(&mut self) {
- self.sender.send(ScreenInstruction::Pty(self.id, VteEvent::Unhook)).unwrap();
+ self.sender
+ .send(ScreenInstruction::Pty(self.id, VteEvent::Unhook))
+ .unwrap();
}
fn osc_dispatch(&mut self, params: &[&[u8]], bell_terminated: bool) {
let params = params.iter().map(|p| p.to_vec()).collect();
- let instruction = ScreenInstruction::Pty(self.id, VteEvent::OscDispatch(params, bell_terminated));
+ let instruction =
+ ScreenInstruction::Pty(self.id, VteEvent::OscDispatch(params, bell_terminated));
self.sender.send(instruction).unwrap();
}
fn csi_dispatch(&mut self, params: &[i64], intermediates: &[u8], ignore: bool, c: char) {
let params = params.iter().copied().collect();
let intermediates = intermediates.iter().copied().collect();
- let instruction = ScreenInstruction::Pty(self.id, VteEvent::CsiDispatch(params, intermediates, ignore, c));
+ let instruction = ScreenInstruction::Pty(
+ self.id,
+ VteEvent::CsiDispatch(params, intermediates, ignore, c),
+ );
self.sender.send(instruction).unwrap();
}
fn esc_dispatch(&mut self, intermediates: &[u8], ignore: bool, byte: u8) {
let intermediates = intermediates.iter().copied().collect();
- let instruction = ScreenInstruction::Pty(self.id, VteEvent::EscDispatch(intermediates, ignore, byte));
+ let instruction =
+ ScreenInstruction::Pty(self.id, VteEvent::EscDispatch(intermediates, ignore, byte));
self.sender.send(instruction).unwrap();
}
}
@@ -159,7 +176,7 @@ pub enum PtyInstruction {
SpawnTerminalVertically(Option<PathBuf>),
SpawnTerminalHorizontally(Option<PathBuf>),
ClosePane(RawFd),
- Quit
+ Quit,
}
pub struct PtyBus {
@@ -167,10 +184,15 @@ pub struct PtyBus {
pub receive_pty_instructions: Receiver<PtyInstruction>,
pub id_to_child_pid: HashMap<RawFd, RawFd>,
os_input: Box<dyn OsApi>,
- debug_to_file: bool
+ debug_to_file: bool,
}
-fn stream_terminal_bytes(pid: RawFd, send_screen_instructions: Sender<ScreenInstruction>, os_input: Box<dyn OsApi>, debug: bool) {
+fn stream_terminal_bytes(
+ pid: RawFd,
+ send_screen_instructions: Sender<ScreenInstruction>,
+ os_input: Box<dyn OsApi>,
+ debug: bool,
+) {
task::spawn({
async move {
let mut vte_parser = vte::Parser::new();
@@ -200,64 +222,100 @@ fn stream_terminal_bytes(pid: RawFd, send_screen_instructions: Sender<ScreenInst
Some(receive_time) => {
if receive_time.elapsed() > max_render_pause {
pending_render = false;
- send_screen_instructions.send(ScreenInstruction::Render).unwrap();
+ send_screen_instructions
+ .send(ScreenInstruction::Render)
+ .unwrap();
last_byte_receive_time = Some(Instant::now());
} else {
pending_render = true;
}
- },
+ }
None => {
last_byte_receive_time = Some(Instant::now());
pending_render = true;
-
}
};
} else {
if pending_render {
pending_render = false;
- send_screen_instructions.send(ScreenInstruction::Render).unwrap();
+ send_screen_instructions
+ .send(ScreenInstruction::Render)
+ .unwrap();
}
last_byte_receive_time = None;
task::sleep(::std::time::Duration::from_millis(10)).await;
}
}
- send_screen_instructions.send(ScreenInstruction::Render).unwrap();
+ send_screen_instructions
+ .send(ScreenInstruction::Render)
+ .unwrap();
#[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
// a better solution would be to fix the test fakes, but this will do for now
- send_screen_instructions.send(ScreenInstruction::ClosePane(pid)).unwrap();
+ send_screen_instructions
+ .send(ScreenInstruction::ClosePane(pid))
+ .unwrap();
}
});
}
impl PtyBus {
- pub fn new (receive_pty_instructions: Receiver<PtyInstruction>, send_screen_instructions: Sender<ScreenInstruction>, os_input: Box<dyn OsApi>, debug_to_file: bool) -> Self {
+ pub fn new(
+ receive_pty_instructions: Receiver<PtyInstruction>,
+ send_screen_instructions: Sender<ScreenInstruction>,
+ os_input: Box<dyn OsApi>,
+ debug_to_file: bool,
+ ) -> Self {
PtyBus {
send_screen_instructions,
receive_pty_instructions,
os_input,
id_to_child_pid: HashMap::new(),
- debug_to_file
+ debug_to_file,
}
}
pub fn spawn_terminal(&mut self, file_to_open: Option<PathBuf>) {
- let (pid_primary, pid_secondary): (RawFd, RawFd) = self.os_input.spawn_terminal(file_to_open);
- stream_terminal_bytes(pid_primary, self.send_screen_instructions.clone(), self.os_input.clone(), self.debug_to_file);
+ let (pid_primary, pid_secondary): (RawFd, RawFd) =
+ self.os_input.spawn_terminal(file_to_open);
+ stream_terminal_bytes(
+ pid_primary,
+ self.send_screen_instructions.clone(),
+ self.os_input.clone(),
+ self.debug_to_file,
+ );
self.id_to_child_pid.insert(pid_primary, pid_secondary);
- self.send_screen_instructions.send(ScreenInstruction::NewPane(pid_primary)).unwrap();
+ self.send_screen_instructions
+ .send(ScreenInstruction::NewPane(pid_primary))
+ .unwrap();
}
pub fn spawn_terminal_vertically(&mut self, file_to_open: Option<PathBuf>) {
- let (pid_primary, pid_secondary): (RawFd, RawFd) = self.os_input.spawn_terminal(file_to_open);
- stream_terminal_bytes(pid_primary, self.send_screen_instructions.clone(), self.os_input.clone(), self.debug_to_file);
+ let (pid_primary, pid_secondary): (RawFd, RawFd) =
+ self.os_input.spawn_terminal(file_to_open);
+ stream_terminal_bytes(
+ pid_primary,
+ self.send_screen_instructions.clone(),
+ self.os_input.clone(),
+ self.debug_to_file,
+ );
self.id_to_child_pid.insert(pid_primary, pid_secondary);
- self.send_screen_instructions.send(ScreenInstruction::VerticalSplit(pid_primary)).unwrap();
+ self.send_screen_instructions
+ .send(ScreenInstruction::VerticalSplit(pid_primary))
+ .unwrap();
}
pub fn spawn_terminal_horizontally(&mut self, file_to_open: Option<PathBuf>) {
- let (pid_primary, pid_secondary): (RawFd, RawFd) = self.os_input.spawn_terminal(file_to_open);
- stream_terminal_bytes(pid_primary, self.send_screen_instructions.clone(), self.os_input.clone(), self.debug_to_file);
+ let (pid_primary, pid_secondary): (RawFd, RawFd) =
+ self.os_input.spawn_terminal(file_to_open);
+ stream_terminal_bytes(
+ pid_primary,
+ self.send_screen_instructions.clone(),
+ self.os_input.clone(),
+ self.debug_to_file,
+ );
self.id_to_child_pid.insert(pid_primary, pid_secondary);
- self.send_screen_instructions.send(ScreenInstruction::HorizontalSplit(pid_primary)).unwrap();
+ self.send_screen_instructions
+ .send(ScreenInstruction::HorizontalSplit(pid_primary))
+ .unwrap();
}
pub fn close_pane(&mut self, id: RawFd) {
let child_pid = self.id_to_child_pid.get(&id).unwrap();
diff --git a/src/screen.rs b/src/screen.rs
index a5bb2a73..a433f02b 100644
--- a/src/screen.rs
+++ b/src/screen.rs
@@ -1,13 +1,13 @@
-use std::io::Write;
-use std::collections::{HashSet, BTreeMap};
use nix::pty::Winsize;
+use std::collections::{BTreeMap, HashSet};
+use std::io::Write;
use std::os::unix::io::RawFd;
-use std::sync::mpsc::{Sender, Receiver};
+use std::sync::mpsc::{Receiver, Sender};
+use crate::boundaries::Boundaries;
use crate::os_input_output::OsApi;
+use crate::pty_bus::{PtyInstruction, VteEvent};
use crate::terminal_pane::TerminalPane;
-use crate::pty_bus::{VteEvent, PtyInstruction};
-use crate::boundaries::Boundaries;
use crate::AppInstruction;
/*
@@ -18,10 +18,14 @@ use crate::AppInstruction;
*
*/
-fn _debug_log_to_file (message: String) {
+fn _debug_log_to_file(message: String) {
use std::fs::OpenOptions;
use std::io::prelude::*;
- let mut file = OpenOptions::new().append(true).create(true).open("/tmp/mosaic-log.txt").unwrap();
+ let mut file = OpenOptions::new()
+ .append(true)
+ .create(true)
+ .open("/tmp/mosaic-log.txt")
+ .unwrap();
file.write_all(message.as_bytes()).unwrap();
file.write_all("\n".as_bytes()).unwrap();
}
@@ -30,7 +34,7 @@ const CURSOR_HEIGHT_WIDGH_RATIO: usize = 4; // this is not accurate and kind of
type BorderAndPaneIds = (usize, Vec<RawFd>);
-fn split_vertically_with_gap (rect: &Winsize) -> (Winsize, Winsize) {
+fn split_vertically_with_gap(rect: &Winsize) -> (Winsize, Winsize) {
let width_of_each_half = (rect.ws_col - 1) / 2;
let mut first_rect = rect.clone();
let mut second_rect = rect.clone();
@@ -43,7 +47,7 @@ fn split_vertically_with_gap (rect: &Winsize) -> (Winsize, Winsize) {
(first_rect, second_rect)
}
-fn split_horizontally_with_gap (rect: &Winsize) -> (Winsize, Winsize) {
+fn split_horizontally_with_gap(rect: &Winsize) -> (Winsize, Winsize) {
let height_of_each_half = (rect.ws_row - 1) / 2;
let mut first_rect = rect.clone();
let mut second_rect = rect.clone();
@@ -91,7 +95,7 @@ pub struct Screen {
}
impl Screen {
- pub fn new (
+ pub fn new(
receive_screen_instructions: Receiver<ScreenInstruction>,
send_pty_instructions: Sender<PtyInstruction>,
send_app_instructions: Sender<AppInstruction>,
@@ -117,21 +121,29 @@ impl Screen {
let x = 0;
let y = 0;
let new_terminal = TerminalPane::new(pid, self.full_screen_ws.clone(), x, y);
- self.os_api.set_terminal_size_using_fd(new_terminal.pid, new_terminal.get_columns() as u16, new_terminal.get_rows() as u16);
+ self.os_api.set_terminal_size_using_fd(
+ new_terminal.pid,
+ new_terminal.get_columns() as u16,
+ new_terminal.get_rows() as u16,
+ );
self.terminals.insert(pid, new_terminal);
self.active_terminal = Some(pid);
} else {
// TODO: check minimum size of active terminal
- let (_longest_edge, terminal_id_to_split) = self.terminals.iter().fold((0, 0), |(current_longest_edge, current_terminal_id_to_split), id_and_terminal_to_check| {
- let (id_of_terminal_to_check, terminal_to_check) = id_and_terminal_to_check;
- let terminal_size = (terminal_to_check.get_rows() * CURSOR_HEIGHT_WIDGH_RATIO) * terminal_to_check.get_columns();
- if terminal_size > current_longest_edge {
- (terminal_size, *id_of_terminal_to_check)
- } else {
- (current_longest_edge, current_terminal_id_to_split)
- }
- });
+ let (_longest_edge, terminal_id_to_split) = self.terminals.iter().fold(
+ (0, 0),
+ |(current_longest_edge, current_terminal_id_to_split), id_and_terminal_to_check| {
+ let (id_of_terminal_to_check, terminal_to_check) = id_and_terminal_to_check;
+ let terminal_size = (terminal_to_check.get_rows() * CURSOR_HEIGHT_WIDGH_RATIO)
+ * terminal_to_check.get_columns();
+ if terminal_size > current_longest_edge {
+ (terminal_size, *id_of_terminal_to_check)
+ } else {
+ (current_longest_edge, current_terminal_id_to_split)
+ }
+ },
+ );
let terminal_to_split = self.terminals.get_mut(&terminal_id_to_split).unwrap();
let terminal_ws = Winsize {
ws_row: terminal_to_split.get_rows() as u16,
@@ -139,23 +151,51 @@ impl Screen {
ws_xpixel: terminal_to_split.get_x() as u16,
ws_ypixel: terminal_to_split.get_y() as u16,
};
- if terminal_to_split.get_rows() * CURSOR_HEIGHT_WIDGH_RATIO > terminal_to_split.get_columns() {
+ if terminal_to_split.get_rows() * CURSOR_HEIGHT_WIDGH_RATIO
+ > terminal_to_split.get_columns()
+ {
let (top_winsize, bottom_winsize) = split_horizontally_with_gap(&terminal_ws);
let bottom_half_y = terminal_ws.ws_ypixel + top_winsize.ws_row + 1;
- let new_terminal = TerminalPane::new(pid, bottom_winsize, terminal_ws.ws_xpixel as usize, bottom_half_y as usize);
- self.os_api.set_terminal_size_using_fd(new_terminal.pid, bottom_winsize.ws_col, bottom_winsize.ws_row);
+ let new_terminal = TerminalPane::new(
+ pid,
+ bottom_winsize,
+ terminal_ws.ws_xpixel as usize,
+ bottom_half_y as usize,
+ );
+ self.os_api.set_terminal_size_using_fd(
+ new_terminal.pid,
+ bottom_winsize.ws_col,
+ bottom_winsize.ws_row,
+ );
terminal_to_split.change_size(&top_winsize);
self.terminals.insert(pid, new_terminal);
- self.os_api.set_terminal_size_using_fd(terminal_id_to_split, top_winsize.ws_col, top_winsize.ws_row);
+ self.os_api.set_terminal_size_using_fd(
+ terminal_id_to_split,
+ top_winsize.ws_col,
+ top_winsize.ws_row,
+ );
self.active_terminal = Some(pid);
} else {
let (left_winszie, right_winsize) = split_vertically_with_gap(&terminal_ws);
let right_side_x = (terminal_ws.ws_xpixel + left_winszie.ws_col + 1) as usize;
- let new_terminal = TerminalPane::new(pid, right_winsize, right_side_x, terminal_ws.ws_ypixel as usize);
- self.os_api.set_terminal_size_using_fd(new_terminal.pid, right_winsize.ws_col, right_winsize.ws_row);
+ let new_terminal = TerminalPane::new(
+ pid,
+ right_winsize,
+ right_side_x,
+ terminal_ws.ws_ypixel as usize,
+ );
+ self.os_api.set_terminal_size_using_fd(
+ new_terminal.pid,
+ right_winsize.ws_col,
+ right_winsize.ws_row,
+ );
terminal_to_split.change_size(&left_winszie);
self.terminals.insert(pid, new_terminal);
- self.os_api.set_terminal_size_using_fd(terminal_id_to_split, left_winszie.ws_col, left_winszie.ws_row);
+ self.os_api.set_terminal_size_using_fd(
+ terminal_id_to_split,
+ left_winszie.ws_col,
+ left_winszie.ws_row,
+ );
}
self.active_terminal = Some(pid);
self.render();
@@ -167,7 +207,11 @@ impl Screen {
let x = 0;
let y = 0;
let new_terminal = TerminalPane::new(pid, self.full_screen_ws.clone(), x, y);
- self.os_api.set_terminal_size_using_fd(new_terminal.pid, new_terminal.get_columns() as u16, new_terminal.get_rows() as u16);
+ self.os_api.set_terminal_size_using_fd(
+ new_terminal.pid,
+ new_terminal.get_columns() as u16,
+ new_terminal.get_rows() as u16,
+ );
self.terminals.insert(pid, new_terminal);
self.active_terminal = Some(pid);
} else {
@@ -182,13 +226,18 @@ impl Screen {
ws_ypixel: 0,
},
active_terminal.get_x(),
- active_terminal.get_y()
+ active_terminal.get_y(),
)
};
let (top_winsize, bottom_winsize) = split_horizontally_with_gap(&active_terminal_ws);
let bottom_half_y = active_terminal_y + top_winsize.ws_row as usize + 1;
- let new_terminal = TerminalPane::new(pid, bottom_winsize, active_terminal_x, bottom_half_y);
- self.os_api.set_terminal_size_using_fd(new_terminal.pid, bottom_winsize.ws_col, bottom_winsize.ws_row);
+ let new_terminal =
+ TerminalPane::new(pid, bottom_winsize, active_terminal_x, bottom_half_y);
+ self.os_api.set_terminal_size_using_fd(
+ new_terminal.pid,
+ bottom_winsize.ws_col,
+ bottom_winsize.ws_row,
+ );
{
let active_terminal_id = &self.get_active_terminal_id().unwrap();
@@ -198,7 +247,11 @@ impl Screen {
self.terminals.insert(pid, new_terminal);
let active_terminal_pid = self.get_active_terminal_id().unwrap();
- self.os_api.set_terminal_size_using_fd(active_terminal_pid, top_winsize.ws_col, top_winsize.ws_row);
+ self.os_api.set_terminal_size_using_fd(
+ active_terminal_pid,
+ top_winsize.ws_col,
+ top_winsize.ws_row,
+ );
self.active_terminal = Some(pid);
self.render();
}
@@ -209,7 +262,11 @@ impl Screen {
let x = 0;
let y = 0;
let new_terminal = TerminalPane::new(pid, self.full_screen_ws.clone(), x, y);
- self.os_api.set_terminal_size_using_fd(new_terminal.pid, new_terminal.get_columns() as u16, new_terminal.get_rows() as u16);
+ self.os_api.set_terminal_size_using_fd(
+ new_terminal.pid,
+ new_terminal.get_columns() as u16,
+ new_terminal.get_rows() as u16,
+ );
self.terminals.insert(pid, new_terminal);
self.active_terminal = Some(pid);
} else {
@@ -224,13 +281,18 @@ impl Screen {
ws_ypixel: 0,
},
active_terminal.get_x(),
- active_terminal.get_y()
+ active_terminal.get_y(),
)
};
let (left_winszie, right_winsize) = split_vertically_with_gap(&active_terminal_ws);
let right_side_x = active_terminal_x + left_winszie.ws_col as usize + 1;
- let new_terminal = TerminalPane::new(pid, right_winsize, right_side_x, active_terminal_y);
- self.os_api.set_terminal_size_using_fd(new_terminal.pid, right_winsize.ws_col, right_winsize.ws_row);
+ let new_terminal =
+ TerminalPane::new(pid, right_winsize, right_side_x, active_terminal_y);
+ self.os_api.set_terminal_size_using_fd(
+ new_terminal.pid,
+ right_winsize.ws_col,
+ right_winsize.ws_row,
+ );
{
let active_terminal_id = &self.get_active_terminal_id().unwrap();
@@ -240,21 +302,25 @@ impl Screen {
self.terminals.insert(pid, new_terminal);
let active_terminal_pid = self.get_active_terminal_id().unwrap();
- self.os_api.set_terminal_size_using_fd(active_terminal_pid, left_winszie.ws_col, left_winszie.ws_row);
+ self.os_api.set_terminal_size_using_fd(
+ active_terminal_pid,
+ left_winszie.ws_col,
+ left_winszie.ws_row,
+ );
self.active_terminal = Some(pid);
self.render();
}
}
- fn get_active_terminal (&self) -> Option<&TerminalPane> {
+ fn get_active_terminal(&self) -> Option<&TerminalPane> {
match self.active_terminal {
Some(active_terminal) => self.terminals.get(&active_terminal),
- None => None
+ None => None,
}
}
- fn get_active_terminal_id (&self) -> Option<RawFd> {
+ fn get_active_terminal_id(&self) -> Option<RawFd> {
match self.active_terminal {
Some(active_terminal) => Some(self.terminals.get(&active_terminal).unwrap().pid),
- None => None
+ None => None,
}
}
pub fn handle_pty_event(&mut self, pid: RawFd, event: VteEvent) {
@@ -274,21 +340,33 @@ impl Screen {
trimmed_bytes.push(*byte);
}
}
- self.os_api.write_to_tty_stdin(*active_terminal_id, &mut trimmed_bytes).expect("failed to write to terminal");
- self.os_api.tcdrain(*active_terminal_id).expect("failed to drain terminal");
+ self.os_api
+ .write_to_tty_stdin(*active_terminal_id, &mut trimmed_bytes)
+ .expect("failed to write to terminal");
+ self.os_api
+ .tcdrain(*active_terminal_id)
+ .expect("failed to drain terminal");
}
}
- fn get_active_terminal_cursor_position(&self) -> Option<(usize, usize)> { // (x, y)
+ fn get_active_terminal_cursor_position(&self) -> Option<(usize, usize)> {
+ // (x, y)
let active_terminal = &self.get_active_terminal().unwrap();
- active_terminal.cursor_coordinates().and_then(|(x_in_terminal, y_in_terminal)| {
- let x = active_terminal.get_x() + x_in_terminal;
- let y = active_terminal.get_y() + y_in_terminal;
- Some((x, y))
- })
+ active_terminal
+ .cursor_coordinates()
+ .and_then(|(x_in_terminal, y_in_terminal)| {
+ let x = active_terminal.get_x() + x_in_terminal;
+ let y = active_terminal.get_y() + y_in_terminal;
+ Some((x, y))
+ })
}
pub fn toggle_active_terminal_fullscreen(&mut self) {
if let Some(active_terminal_id) = self.get_active_terminal_id() {
- if self.get_active_terminal().unwrap().position_and_size_override.is_some() {
+ if self
+ .get_active_terminal()
+ .unwrap()
+ .position_and_size_override
+ .is_some()
+ {
for terminal_id in self.panes_to_hide.iter() {
self.terminals.get_mut(terminal_id).unwrap().should_render = true;
}
@@ -296,7 +374,10 @@ impl Screen {
let active_terminal = self.terminals.get_mut(&active_terminal_id).unwrap();
active_terminal.reset_size_and_position_override();
} else {
- let all_ids_except_current = self.terminals.keys().filter(|id| **id != active_terminal_id);
+ let all_ids_except_current = self
+ .terminals
+ .keys()
+ .filter(|id| **id != active_terminal_id);
self.panes_to_hide = all_ids_except_current.copied().collect();
let active_terminal = self.terminals.get_mut(&active_terminal_id).unwrap();
active_terminal.override_size_and_position(0, 0, &self.full_screen_ws);
@@ -310,38 +391,53 @@ impl Screen {
self.render();
}
}
- pub fn render (&mut self) {
+ pub fn render(&mut self) {
if self.active_terminal.is_none() {
// we might not have an active terminal if we closed the last pane
// in that case, we should not render as the app is exiting
return;
}
let mut stdout = self.os_api.get_stdout_writer();
- let mut boundaries = Boundaries::new(self.full_screen_ws.ws_col, self.full_screen_ws.ws_row);
+ let mut boundaries =
+ Boundaries::new(self.full_screen_ws.ws_col, self.full_screen_ws.ws_row);
for (pid, terminal) in self.terminals.iter_mut() {
if !self.panes_to_hide.contains(pid) {
boundaries.add_rect(&terminal);
if let Some(vte_output) = terminal.buffer_as_vte_output() {
- stdout.write_all(&vte_output.as_bytes()).expect("cannot write to stdout");
+ stdout
+ .write_all(&vte_output.as_bytes())
+ .expect("cannot write to stdout");
}
}
}
// TODO: only render (and calculate) boundaries if there was a resize
let vte_output = boundaries.vte_output();
- stdout.write_all(&vte_output.as_bytes()).expect("cannot write to stdout");
+ stdout
+ .write_all(&vte_output.as_bytes())
+ .expect("cannot write to stdout");
match self.get_active_terminal_cursor_position() {
Some((cursor_position_x, cursor_position_y)) => {
let show_cursor = "\u{1b}[?25h";
- let goto_cursor_position = format!("\u{1b}[{};{}H\u{1b}[m", cursor_position_y + 1, cursor_position_x + 1); // goto row/col
- stdout.write_all(&show_cursor.as_bytes()).expect("cannot write to stdout");
- stdout.write_all(&goto_cursor_position.as_bytes()).expect("cannot write to stdout");
+ let goto_cursor_position = format!(
+ "\u{1b}[{};{}H\u{1b}[m",
+ cursor_position_y + 1,
+ cursor_position_x + 1
+ ); // goto row/col
+ stdout
+ .write_all(&show_cursor.as_bytes())
+ .expect("cannot write to stdout");
+ stdout
+ .write_all(&goto_cursor_position.as_bytes())
+ .expect("cannot write to stdout");
stdout.flush().expect("could not flush");
- },
+ }
None => {
let hide_cursor = "\u{1b}[?25l";
- stdout.write_all(&hide_cursor.as_bytes()).expect("cannot write to stdout");
+ stdout
+ .write_all(&hide_cursor.as_bytes())
+ .expect("cannot write to stdout");
stdout.flush().expect("could not flush");
}
}
@@ -416,14 +512,21 @@ impl Screen {
self.terminals
.keys()
.map(|t_id| self.terminals.get(&t_id).unwrap())
- .filter(|terminal| terminal.pid != pane.pid && terminal.get_y() + terminal.get_rows() == pane.get_y() + pane.get_rows())
+ .filter(|terminal| {
+ terminal.pid != pane.pid
+ && terminal.get_y() + terminal.get_rows() == pane.get_y() + pane.get_rows()
+ })
.collect()
}
fn panes_right_aligned_with_pane(&self, pane: &TerminalPane) -> Vec<&TerminalPane> {
self.terminals
.keys()
.map(|t_id| self.terminals.get(&t_id).unwrap())
- .filter(|terminal| terminal.pid != pane.pid && terminal.get_x() + terminal.get_columns() == pane.get_x() + pane.get_columns())
+ .filter(|terminal| {
+ terminal.pid != pane.pid
+ && terminal.get_x() + terminal.get_columns()
+ == pane.get_x() + pane.get_columns()
+ })
.collect()
}
fn panes_left_aligned_with_pane(&self, pane: &TerminalPane) -> Vec<&TerminalPane> {
@@ -433,16 +536,18 @@ impl Screen {
.filter(|terminal| terminal.pid != pane.pid && terminal.get_x() == pane.get_x())
.collect()
}
- fn right_aligned_contiguous_panes_above(&self, id: &RawFd, terminal_borders_to_the_right: &HashSet<usize>) -> BorderAndPaneIds {
+ fn right_aligned_contiguous_panes_above(
+ &self,
+ id: &RawFd,
+ terminal_borders_to_the_right: &HashSet<usize>,
+ ) -> BorderAndPaneIds {
let mut terminals = vec![];
let terminal_to_check = self.terminals.get(id).expect("terminal id does not exist");
let mut right_aligned_terminals = self.panes_right_aligned_with_pane(&terminal_to_check);
// terminals that are next to each other up to current
- right_aligned_terminals.sort_by(|a, b| { b.get_y().cmp(&a.get_y())});
+ right_aligned_terminals.sort_by(|a, b| b.get_y().cmp(&a.get_y()));
for terminal in right_aligned_terminals {
- let terminal_to_check = terminals
- .last()
- .unwrap_or(&terminal_to_check);
+ let terminal_to_check = terminals.last().unwrap_or(&terminal_to_check);
if terminal.get_y() + terminal.get_rows() + 1 == terminal_to_check.get_y() {
terminals.push(terminal);
}
@@ -451,29 +556,37 @@ impl Screen {
let mut top_resize_border = 0;
for terminal in &terminals {
let bottom_terminal_boundary = terminal.get_y() + terminal.get_rows();
- if terminal_borders_to_the_right.get(&(bottom_terminal_boundary + 1)).is_some() && top_resize_border < bottom_terminal_boundary {
+ if terminal_borders_to_the_right
+ .get(&(bottom_terminal_boundary + 1))
+ .is_some()
+ && top_resize_border < bottom_terminal_boundary
+ {
top_resize_border = bottom_terminal_boundary + 1;
}
}
- terminals.retain(|terminal| {
- terminal.get_y() >= top_resize_border
- });
+ terminals.retain(|terminal| terminal.get_y() >= top_resize_border);
// if there are no adjacent panes to resize, we use the border of the main pane we're
// resizing
- let top_resize_border = if terminals.is_empty() { terminal_to_check.get_y() } else { top_resize_border };
+ let top_resize_border = if terminals.is_empty() {
+ terminal_to_check.get_y()
+ } else {
+ top_resize_border
+ };
let terminal_ids: Vec<RawFd> = terminals.iter().map(|t| t.pid).collect();
(top_resize_border, terminal_ids)
}
- fn right_aligned_contiguous_panes_below(&self, id: &RawFd, terminal_borders_to_the_right: &HashSet<usize>) -> BorderAndPaneIds {
+ fn right_aligned_contiguous_panes_below(
+ &self,
+ id: &RawFd,
+ terminal_borders_to_the_right: &HashSet<usize>,
+ ) -> BorderAndPaneIds {
let mut terminals = vec![];
let terminal_to_check = self.terminals.get(id).expect("terminal id does not exist");
let mut right_aligned_terminals = self.panes_right_aligned_with_pane(&terminal_to_check);
// terminals that are next to each other up to current
- right_aligned_terminals.sort_by(|a, b| { a.get_y().cmp(&b.get_y())});
+ right_aligned_terminals.sort_by(|a, b| a.get_y().cmp(&b.get_y()));
for terminal in right_aligned_terminals {
- let terminal_to_check = terminals
- .last()
- .unwrap_or(&terminal_to_check);
+ let terminal_to_check = terminals.last().unwrap_or(&terminal_to_check);
if terminal.get_y() == terminal_to_check.get_y() + terminal_to_check.get_rows() + 1 {
terminals.push(terminal);
}
@@ -482,29 +595,37 @@ impl Screen {
let mut bottom_resize_border = self.full_screen_ws.ws_row as usize;
for terminal in &terminals {
let top_terminal_boundary = terminal.get_y();
- if terminal_borders_to_the_right.get(&(top_terminal_boundary)).is_some() && top_terminal_boundary < bottom_resize_border {
+ if terminal_borders_to_the_right
+ .get(&(top_terminal_boundary))
+ .is_some()
+ && top_terminal_boundary < bottom_resize_border
+ {
bottom_resize_border = top_terminal_boundary;
}
}
- terminals.retain(|terminal| {
- terminal.get_y() + terminal.get_rows() <= bottom_resize_border
- });
+ terminals.retain(|terminal| terminal.get_y() + terminal.get_rows() <= bottom_resize_border);
// if there are no adjacent panes to resize, we use the border of the main pane we're
// resizing
- let bottom_resize_border = if terminals.is_empty() { terminal_to_check.get_y() + terminal_to_check.get_rows() } else { bottom_resize_border };
+ let bottom_resize_border = if terminals.is_empty() {
+ terminal_to_check.get_y() + terminal_to_check.get_rows()
+ } else {
+ bottom_resize_border
+ };
let terminal_ids: Vec<RawFd> = terminals.iter().map(|t| t.pid).collect();
(bottom_resize_border, terminal_ids)
}
- fn left_aligned_contiguous_panes_above(&self, id: &RawFd, terminal_borders_to_the_left: &HashSet<usize>) -> BorderAndPaneIds {
+ fn left_aligned_contiguous_panes_above(
+ &self,
+ id: &RawFd,
+ terminal_borders_to_the_left: &HashSet<usize>,
+ ) -> BorderAndPaneIds {
let mut terminals = vec![];
let terminal_to_check = self.terminals.get(id).expect("terminal id does not exist");
let mut left_aligned_terminals = self.panes_left_aligned_with_pane(&terminal_to_check);
// terminals that are next to each other up to current
- left_aligned_terminals.sort_by(|a, b| { b.get_y().cmp(&a.get_y())});
+ left_aligned_terminals.sort_by(|a, b| b.get_y().cmp(&a.get_y()));
for terminal in left_aligned_terminals {
- let terminal_to_check = terminals
- .last()
- .unwrap_or(&terminal_to_check);
+ let terminal_to_check = terminals.last().unwrap_or(&terminal_to_check);
if terminal.get_y() + terminal.get_rows() + 1 == terminal_to_check.get_y() {
terminals.push(terminal);
}
@@ -513,29 +634,37 @@ impl Screen {
let mut top_resize_border = 0;
for terminal in &terminals {
let bottom_terminal_boundary = terminal.get_y() + terminal.get_rows();
- if terminal_borders_to_the_left.get(&(bottom_terminal_boundary + 1)).is_some() && top_resize_border < bottom_terminal_boundary {
+ if terminal_borders_to_the_left
+ .get(&(bottom_terminal_boundary + 1))
+ .is_some()
+ && top_resize_border < bottom_terminal_boundary
+ {
top_resize_border = bottom_terminal_boundary + 1;
}
}
- terminals.retain(|terminal| {
- terminal.get_y() >= top_resize_border
- });
+ terminals.retain(|terminal| terminal.get_y() >= top_resize_border);
// if there are no adjacent panes to resize, we use the border of the main pane we're
// resizing
- let top_resize_border = if terminals.is_empty() { terminal_to_check.get_y() } else { top_resize_border };
+ let top_resize_border = if terminals.is_empty() {
+ terminal_to_check.get_y()
+ } else {
+ top_resize_border
+ };
let terminal_ids: Vec<RawFd> = terminals.iter().map(|t| t.pid).collect();
(top_resize_border, terminal_ids)
}
- fn left_aligned_contiguous_panes_below(&self, id: &RawFd, terminal_borders_to_the_left: &HashSet<usize>) -> BorderAndPaneIds {
+ fn left_aligned_contiguous_panes_below(
+ &self,
+ id: &RawFd,
+ terminal_borders_to_the_left: &HashSet<usize>,
+ ) -> BorderAndPaneIds {
let mut terminals = vec![];
let terminal_to_check = self.terminals.get(id).expect("terminal id does not exist");
let mut left_aligned_terminals = self.panes_left_aligned_with_pane(&terminal_to_check);
// terminals that are next to each other up to current
- left_aligned_terminals.sort_by(|a, b| { a.get_y().cmp(&b.get_y())});
+ left_aligned_terminals.sort_by(|a, b| a.get_y().cmp(&b.get_y()));
for terminal in left_aligned_terminals {
- let terminal_to_check = terminals
- .last()
- .unwrap_or(&terminal_to_check);
+ let terminal_to_check = terminals.last().unwrap_or(&terminal_to_check);
if terminal.get_y() == terminal_to_check.get_y() + terminal_to_check.get_rows() + 1 {
terminals.push(terminal);
}
@@ -544,7 +673,11 @@ impl Screen {
let mut bottom_resize_border = self.full_screen_ws.ws_row as usize;
for terminal in &terminals {
let top_terminal_boundary = terminal.get_y();
- if terminal_borders_to_the_left.get(&(top_terminal_boundary)).is_some() && top_terminal_boundary < bottom_resize_border {
+ if terminal_borders_to_the_left
+ .get(&(top_terminal_boundary))
+ .is_some()
+ && top_terminal_boundary < bottom_resize_border
+ {
bottom_resize_border = top_terminal_boundary;
}
}
@@ -554,20 +687,26 @@ impl Screen {
});
// if there are no adjacent panes to resize, we use the border of the main pane we're
// resizing
- let bottom_resize_border = if terminals.is_empty() { terminal_to_check.get_y() + terminal_to_check.get_rows() } else { bottom_resize_border };
+ let bottom_resize_border = if terminals.is_empty() {
+ terminal_to_check.get_y() + terminal_to_check.get_rows()
+ } else {
+ bottom_resize_border
+ };
let terminal_ids: Vec<RawFd> = terminals.iter().map(|t| t.pid).collect();
(bottom_resize_border, terminal_ids)
}
- fn top_aligned_contiguous_panes_to_the_left(&self, id: &RawFd, terminal_borders_above: &HashSet<usize>) -> BorderAndPaneIds {
+ fn top_aligned_contiguous_panes_to_the_left(
+ &self,
+ id: &RawFd,
+ terminal_borders_above: &HashSet<usize>,
+ ) -> BorderAndPaneIds {
let mut terminals = vec![];
let terminal_to_check = self.terminals.get(id).expect("terminal id does not exist");
let mut top_aligned_terminals = self.panes_top_aligned_with_pane(&terminal_to_check);
// terminals that are next to each other up to current
- top_aligned_terminals.sort_by(|a, b| { b.get_x().cmp(&a.get_x())});
+ top_aligned_terminals.sort_by(|a, b| b.get_x().cmp(&a.get_x()));
for terminal in top_aligned_terminals {
- let terminal_to_check = terminals
- .last()
- .unwrap_or(&terminal_to_check);
+ let terminal_to_check = terminals.last().unwrap_or(&terminal_to_check);
if terminal.get_x() + terminal.get_columns() + 1 == terminal_to_check.get_x() {
terminals.push(terminal);
}
@@ -576,29 +715,37 @@ impl Screen {
let mut left_resize_border = 0;
for terminal in &terminals {
let right_terminal_boundary = terminal.get_x() + terminal.get_columns();
- if terminal_borders_above.get(&(right_terminal_boundary + 1)).is_some() && left_resize_border < right_terminal_boundary {
+ if terminal_borders_above
+ .get(&(right_terminal_boundary + 1))
+ .is_some()
+ && left_resize_border < right_terminal_boundary
+ {
left_resize_border = right_terminal_boundary + 1;
}
}
- terminals.retain(|terminal| {
- terminal.get_x() >= left_resize_border
- });
+ terminals.retain(|terminal| terminal.get_x() >= left_resize_border);
// if there are no adjacent panes to resize, we use the border of the main pane we're
// resizing
- let left_resize_border = if terminals.is_empty() { terminal_to_check.get_x() } else { left_resize_border };
+ let left_resize_border = if terminals.is_empty() {
+ terminal_to_check.get_x()
+ } else {
+ left_resize_border
+ };
let terminal_ids: Vec<RawFd> = terminals.iter().map(|t| t.pid).collect();
(left_resize_border, terminal_ids)
}
- fn top_aligned_contiguous_panes_to_the_right(&self, id: &RawFd, terminal_borders_above: &HashSet<usize>) -> BorderAndPaneIds {
+ fn top_aligned_contiguous_panes_to_the_right(
+ &self,
+ id: &RawFd,
+ terminal_borders_above: &HashSet<usize>,
+ ) -> BorderAndPaneIds {
let mut terminals = vec![];
let terminal_to_check = self.terminals.get(id).unwrap();
let mut top_aligned_terminals = self.panes_top_aligned_with_pane(&terminal_to_check);
// terminals that are next to each other up to current
- top_aligned_terminals.sort_by(|a, b| { a.get_x().cmp(&b.get_x())});
+ top_aligned_terminals.sort_by(|a, b| a.get_x().cmp(&b.get_x()));
for terminal in top_aligned_terminals {
- let terminal_to_check = terminals
- .last()
- .unwrap_or(&terminal_to_check);
+ let terminal_to_check = terminals.last().unwrap_or(&terminal_to_check);
if terminal.get_x() == terminal_to_check.get_x() + terminal_to_check.get_columns() + 1 {
terminals.push(terminal);
}
@@ -607,29 +754,38 @@ impl Screen {
let mut right_resize_border = self.full_screen_ws.ws_col as usize;
for terminal in &terminals {
let left_terminal_boundary = terminal.get_x();
- if terminal_borders_above.get(&left_terminal_boundary).is_some() && right_resize_border > left_terminal_boundary {
+ if terminal_borders_above
+ .get(&left_terminal_boundary)
+ .is_some()
+ && right_resize_border > left_terminal_boundary
+ {
right_resize_border = left_terminal_boundary;
}
}
- terminals.retain(|terminal| {
- terminal.get_x() + terminal.get_columns() <= right_resize_border
- });
+ terminals
+ .retain(|terminal| terminal.get_x() + terminal.get_columns() <= right_resize_border);
// if there are no adjacent panes to resize, we use the border of the main pane we're
// resizing
- let right_resize_border = if terminals.is_empty() { terminal_to_check.get_x() + terminal_to_check.get_columns() } else { right_resize_border };
+ let right_resize_border = if terminals.is_empty() {
+ terminal_to_check.get_x() + terminal_to_check.get_columns()
+ } else {
+ right_resize_border
+ };
let terminal_ids: Vec<RawFd> = terminals.iter().map(|t| t.pid).collect();
(right_resize_border, terminal_ids)
}
- fn bottom_aligned_contiguous_panes_to_the_left(&self, id: &RawFd, terminal_borders_below: &HashSet<usize>) -> BorderAndPaneIds {
+ fn bottom_aligned_contiguous_panes_to_the_left(
+ &self,
+ id: &RawFd,
+ terminal_borders_below: &HashSet<usize>,
+ ) -> BorderAndPaneIds {
let mut terminals = vec![];
let terminal_to_check = self.terminals.get(id).unwrap();
let mut bottom_aligned_terminals = self.panes_bottom_aligned_with_pane(&terminal_to_check);
- bottom_aligned_terminals.sort_by(|a, b| { b.get_x().cmp(&a.get_x())});
+ bottom_aligned_terminals.sort_by(|a, b| b.get_x().cmp(&a.get_x()));
// terminals that are next to each other up to current
for terminal in bottom_aligned_terminals {
- let terminal_to_check = terminals
- .last()
- .unwrap_or(&terminal_to_check);
+ let terminal_to_check = terminals.last().unwrap_or(&terminal_to_check);
if terminal.get_x() + terminal.get_columns() + 1 == terminal_to_check.get_x() {
terminals.push(terminal);
}
@@ -638,29 +794,37 @@ impl Screen {
let mut left_resize_border = 0;
for terminal in &terminals {
let right_terminal_boundary = terminal.get_x() + terminal.get_columns();
- if terminal_borders_below.get(&(right_terminal_boundary + 1)).is_some() && left_resize_border < right_terminal_boundary {
+ if terminal_borders_below
+ .get(&(right_terminal_boundary + 1))
+ .is_some()
+ && left_resize_border < right_terminal_boundary
+ {
left_resize_border = right_terminal_boundary + 1;
}
}
- terminals.retain(|terminal| {
- terminal.get_x() >= left_resize_border
- });
+ terminals.retain(|terminal| terminal.get_x() >= left_resize_border);
// if there are no adjacent panes to resize, we use the border of the main pane we're
// resizing
- let left_resize_border = if terminals.is_empty() { terminal_to_check.get_x() } else { left_resize_border };
+ let left_resize_border = if terminals.is_empty() {
+ terminal_to_check.get_x()
+ } else {
+ left_resize_border
+ };
let terminal_ids: Vec<RawFd> = terminals.iter().map(|t| t.pid).collect();
(left_resize_border, terminal_ids)
}
- fn bottom_aligned_contiguous_panes_to_the_right(&self, id: &RawFd, terminal_borders_below: &HashSet<usize>) -> BorderAndPaneIds {
+ fn bottom_aligned_contiguous_panes_to_the_right(
+ &self,
+ id: &RawFd,
+ terminal_borders_below: &HashSet<usize>,
+ ) -> BorderAndPaneIds {
let mut terminals = vec![];
let terminal_to_check = self.terminals.get(id).unwrap();
let mut bottom_aligned_terminals = self.panes_bottom_aligned_with_pane(&terminal_to_check);
- bottom_aligned_terminals.sort_by(|a, b| { a.get_x().cmp(&b.get_x())});
+ bottom_aligned_terminals.sort_by(|a, b| a.get_x().cmp(&b.get_x()));
// terminals that are next to each other up to current
for terminal in bottom_aligned_terminals {
- let terminal_to_check = terminals
- .last()
- .unwrap_or(&terminal_to_check);
+ let terminal_to_check = terminals.last().unwrap_or(&terminal_to_check);
if terminal.get_x() == terminal_to_check.get_x() + terminal_to_check.get_columns() + 1 {
terminals.push(terminal);
}
@@ -669,14 +833,21 @@ impl Screen {
let mut right_resize_border = self.full_screen_ws.ws_col as usize;
for terminal in &terminals {
let left_terminal_boundary = terminal.get_x();
- if terminal_borders_below.get(&left_terminal_boundary).is_some() && right_resize_border > left_terminal_boundary {
+ if terminal_borders_below
+ .get(&left_terminal_boundary)
+ .is_some()
+ && right_resize_border > left_terminal_boundary
+ {
right_resize_border = left_terminal_boundary;
}
}
- terminals.retain(|terminal| {
- terminal.get_x() + terminal.get_columns() <= right_resize_border
- });
- let right_resize_border = if terminals.is_empty() { terminal_to_check.get_x() + terminal_to_check.get_columns() } else { right_resize_border };
+ terminals
+ .retain(|terminal| terminal.get_x() + terminal.get_columns() <= right_resize_border);
+ let right_resize_border = if terminals.is_empty() {
+ terminal_to_check.get_x() + terminal_to_check.get_columns()
+ } else {
+ right_resize_border
+ };
let terminal_ids: Vec<RawFd> = terminals.iter().map(|t| t.pid).collect();
(right_resize_border, terminal_ids)
}
@@ -731,7 +902,7 @@ impl Screen {
self.os_api.set_terminal_size_using_fd(
terminal.pid,
terminal.get_columns() as u16,
- terminal.get_rows() as u16
+ terminal.get_rows() as u16,
);
}
fn reduce_pane_width_right(&mut self, id: &RawFd, count: usize) {
@@ -752,48 +923,99 @@ impl Screen {
terminal.get_rows() as u16,
);
}
- fn pane_is_between_vertical_borders(&self, id: &RawFd, left_border_x: usize, right_border_x: usize) -> bool {
- let terminal = self.terminals.get(id).expect("could not find terminal to check between borders");
- terminal.get_x() >= left_border_x && terminal.get_x() + terminal.get_columns() <= right_border_x
+ fn pane_is_between_vertical_borders(
+ &self,
+ id: &RawFd,
+ left_border_x: usize,
+ right_border_x: usize,
+ ) -> bool {
+ let terminal = self
+ .terminals
+ .get(id)
+ .expect("could not find terminal to check between borders");
+ terminal.get_x() >= left_border_x
+ && terminal.get_x() + terminal.get_columns() <= right_border_x
}
- fn pane_is_between_horizontal_borders(&self, id: &RawFd, top_border_y: usize, bottom_border_y: usize) -> bool {
- let terminal = self.terminals.get(id).expect("could not find terminal to check between borders");
- terminal.get_y() >= top_border_y && terminal.get_y() + terminal.get_rows() <= bottom_border_y
+ fn pane_is_between_horizontal_borders(
+ &self,
+ id: &RawFd,
+ top_border_y: usize,
+ bottom_border_y: usize,
+ ) -> bool {
+ let terminal = self
+ .terminals
+ .get(id)
+ .expect("could not find terminal to check between borders");
+ terminal.get_y() >= top_border_y
+ && terminal.get_y() + terminal.get_rows() <= bottom_border_y
}
fn reduce_pane_and_surroundings_up(&mut self, id: &RawFd, count: usize) {
- let mut terminals_below = self.terminal_ids_directly_below(&id).expect("can't reduce pane size up if there are no terminals below");
- let terminal_borders_below: HashSet<usize> = terminals_below.iter().map(|t| self.terminals.get(t).unwrap().get_x()).collect();
- let (left_resize_border, terminals_to_the_left) = self.bottom_aligned_contiguous_panes_to_the_left(&id, &terminal_borders_below);
- let (right_resize_border, terminals_to_the_right) = self.bottom_aligned_contiguous_panes_to_the_right(&id, &terminal_borders_below);
- terminals_below.retain(|t| self.pane_is_between_vertical_borders(t, left_resize_border, right_resize_border));
+ let mut terminals_below = self
+ .terminal_ids_directly_below(&id)
+ .expect("can't reduce pane size up if there are no terminals below");
+ let terminal_borders_below: HashSet<usize> = terminals_below
+ .iter()
+ .map(|t| self.terminals.get(t).unwrap().get_x())
+ .collect();
+ let (left_resize_border, terminals_to_the_left) =
+ self.bottom_aligned_contiguous_panes_to_the_left(&id, &terminal_borders_below);
+ let (right_resize_border, terminals_to_the_right) =
+ self.bottom_aligned_contiguous_panes_to_the_right(&id, &terminal_borders_below);
+ terminals_below.retain(|t| {
+ self.pane_is_between_vertical_borders(t, left_resize_border, right_resize_border)
+ });
self.reduce_pane_height_up(&id, count);
for terminal_id in terminals_below {
self.increase_pane_height_up(&terminal_id, count);
}
- for terminal_id in terminals_to_the_left.iter().chain(terminals_to_the_right.iter()) {
+ for terminal_id in terminals_to_the_left
+ .iter()
+ .chain(terminals_to_the_right.iter())
+ {
self.reduce_pane_height_up(&terminal_id, count);
}
}
fn reduce_pane_and_surroundings_down(&mut self, id: &RawFd, count: usize) {
- let mut terminals_above = self.terminal_ids_directly_above(&id).expect("can't reduce pane size down if there are no terminals above");
- let terminal_borders_above: HashSet<usize> = terminals_above.iter().map(|t| self.terminals.get(t).unwrap().get_x()).collect();
- let (left_resize_border, terminals_to_the_left) = self.top_aligned_contiguous_panes_to_the_left(&id, &terminal_borders_above);
- let (right_resize_border, terminals_to_the_right) = self.top_aligned_contiguous_panes_to_the_right(&id, &terminal_borders_above);
- terminals_above.retain(|t| self.pane_is_between_vertical_borders(t, left_resize_border, right_resize_border));
+ let mut terminals_above = self
+ .terminal_ids_directly_above(&id)
+ .expect("can't reduce pane size down if there are no terminals above");
+ let terminal_borders_above: HashSet<usize> = terminals_above
+ .iter()
+ .map(|t| self.terminals.get(t).unwrap().get_x())
+ .collect();
+ let (left_resize_border, terminals_to_the_left) =
+ self.top_aligned_contiguous_panes_to_the_left(&id, &terminal_borders_above);
+ let (right_resize_border, terminals_to_the_right) =
+ self.top_aligned_contiguous_panes_to_the_right(&id, &terminal_borders_above);
+ terminals_above.retain(|t| {
+ self.pane_is_between_vertical_borders(t, left_resize_border, right_resize_border)
+ });
self.reduce_pane_height_down(&id, count);
for terminal_id in terminals_above {
self.increase_pane_height_down(&terminal_id, count);
}
- for terminal_id in terminals_to_the_left.iter().chain(terminals_to_the_right.iter()) {
+ for terminal_id in terminals_to_the_left
+ .iter()
+ .chain(terminals_to_the_right.iter())
+ {
self.reduce_pane_height_down(&terminal_id, count);
}
}
fn reduce_pane_and_surroundings_right(&mut self, id: &RawFd, count: usize) {
- let mut terminals_to_the_left = self.terminal_ids_directly_left_of(&id).expect("can't reduce pane size right if there are no terminals to the left");
- let terminal_borders_to_the_left: HashSet<usize> = terminals_to_the_left.iter().map(|t| self.terminals.get(t).unwrap().get_y()).collect();
- let (top_resize_border, terminals_above) = self.left_aligned_contiguous_panes_above(&id, &terminal_borders_to_the_left);
- let (bottom_resize_border, terminals_below) = self.left_aligned_contiguous_panes_below(&id, &terminal_borders_to_the_left);
- terminals_to_the_left.retain(|t| self.pane_is_between_horizontal_borders(t, top_resize_border, bottom_resize_border));
+ let mut terminals_to_the_left = self
+ .terminal_ids_directly_left_of(&id)
+ .expect("can't reduce pane size right if there are no terminals to the left");
+ let terminal_borders_to_the_left: HashSet<usize> = terminals_to_the_left
+ .iter()
+ .map(|t| self.terminals.get(t).unwrap().get_y())
+ .collect();
+ let (top_resize_border, terminals_above) =
+ self.left_aligned_contiguous_panes_above(&id, &terminal_borders_to_the_left);
+ let (bottom_resize_border, terminals_below) =
+ self.left_aligned_contiguous_panes_below(&id, &terminal_borders_to_the_left);
+ terminals_to_the_left.retain(|t| {
+ self.pane_is_between_horizontal_borders(t, top_resize_border, bottom_resize_border)
+ });
self.reduce_pane_width_right(&id, count);
for terminal_id in terminals_to_the_left {
self.increase_pane_width_right(&terminal_id, count);
@@ -803,11 +1025,20 @@ impl Screen {
}
}
fn reduce_pane_and_surroundings_left(&mut self, id: &RawFd, count: usize) {
- let mut terminals_to_the_right = self.terminal_ids_directly_right_of(&id).expect("can't reduce pane size left if there are no terminals to the right");
- let terminal_borders_to_the_right: HashSet<usize> = terminals_to_the_right.iter().map(|t| self.terminals.get(t).unwrap().get_y()).collect();
- let (top_resize_border, terminals_above) = self.right_aligned_contiguous_panes_above(&id, &terminal_borders_to_the_right);
- let (bottom_resize_border, terminals_below) = self.right_aligned_contiguous_panes_below(&id, &terminal_borders_to_the_right);
- terminals_to_the_right.retain(|t| self.pane_is_between_horizontal_borders(t, top_resize_border, bottom_resize_border));
+ let mut terminals_to_the_right = self
+ .terminal_ids_directly_right_of(&id)
+ .expect("can't reduce pane size left if there are no terminals to the right");
+ let terminal_borders_to_the_right: HashSet<usize> = terminals_to_the_right
+ .iter()
+ .map(|t| self.terminals.get(t).unwrap().get_y())
+ .collect();
+ let (top_resize_border, terminals_above) =
+ self.right_aligned_contiguous_panes_above(&id, &terminal_borders_to_the_right);
+ let (bottom_resize_border, terminals_below) =
+ self.right_aligned_contiguous_panes_below(&id, &terminal_borders_to_the_right);
+ terminals_to_the_right.retain(|t| {
+ self.pane_is_between_horizontal_borders(t, top_resize_border, bottom_resize_border)
+ });
self.reduce_pane_width_left(&id, count);
for terminal_id in terminals_to_the_right {
self.increase_pane_width_left(&terminal_id, count);
@@ -817,39 +1048,72 @@ impl Screen {
}
}
fn increase_pane_and_surroundings_up(&mut self, id: &RawFd, count: usize) {
- let mut terminals_above = self.terminal_ids_directly_above(&id).expect("can't increase pane size up if there are no terminals above");
- let terminal_borders_above: HashSet<usize> = terminals_above.iter().map(|t| self.terminals.get(t).unwrap().get_x()).collect();
- let (left_resize_border, terminals_to_the_left) = self.top_aligned_contiguous_panes_to_the_left(&id, &terminal_borders_above);
- let (right_resize_border, terminals_to_the_right) = self.top_aligned_contiguous_panes_to_the_right(&id, &terminal_borders_above);
- terminals_above.retain(|t| self.pane_is_between_vertical_borders(t, left_resize_border, right_resize_border));
+ let mut terminals_above = self
+ .terminal_ids_directly_above(&id)
+ .expect("can't increase pane size up if there are no terminals above");
+ let terminal_borders_above: HashSet<usize> = terminals_above
+ .iter()
+ .map(|t| self.terminals.get(t).unwrap().get_x())
+ .collect();
+ let (left_resize_border, terminals_to_the_left) =
+ self.top_aligned_contiguous_panes_to_the_left(&id, &terminal_borders_above);
+ let (right_resize_border, terminals_to_the_right) =
+ self.top_aligned_contiguous_panes_to_the_right(&id, &terminal_borders_above);
+ terminals_above.retain(|t| {
+ self.pane_is_between_vertical_borders(t, left_resize_border, right_resize_border)
+ });
self.increase_pane_height_up(&id, count);
for terminal_id in terminals_above {
self.reduce_pane_height_up(&terminal_id, count);
}
- for terminal_id in terminals_to_the_left.iter().chain(terminals_to_the_right.iter()) {
+ for terminal_id in terminals_to_the_left
+ .iter()
+ .chain(terminals_to_the_right.iter())
+ {
self.increase_pane_height_up(&terminal_id, count);
}
}
fn increase_pane_and_surroundings_down(&mut self, id: &RawFd, count: usize) {
- let mut terminals_below = self.terminal_ids_directly_below(&id).expect("can't increase pane size down if there are no terminals below");
- let terminal_borders_below: HashSet<usize> = terminals_below.iter().map(|t| self.terminals.get(t).unwrap().get_x()).collect();
- let (left_resize_border, terminals_to_the_left) = self.bottom_aligned_contiguous_panes_to_the_left(&id, &terminal_borders_below);
- let (right_resize_border, terminals_to_the_right) = self.bottom_aligned_contiguous_panes_to_the_right(&id, &terminal_borders_below);
- terminals_below.retain(|t| self.pane_is_between_vertical_borders(t, left_resize_border, right_resize_border));
+ let mut terminals_below = self
+ .terminal_ids_directly_below(&id)
+ .expect("can't increase pane size down if there are no terminals below");
+ let terminal_borders_below: HashSet<usize> = terminals_below
+ .iter()
+ .map(|t| self.terminals.get(t).unwrap().get_x())
+ .collect();
+ let (left_resize_border, terminals_to_the_left) =
+ self.bottom_aligned_contiguous_panes_to_the_left(&id, &terminal_borders_below);
+ let (right_resize_border, terminals_to_the_right) =
+ self.bottom_aligned_contiguous_panes_to_the_right(&id, &terminal_borders_below);
+ terminals_below.retain(|t| {
+ self.pane_is_between_vertical_borders(t, left_resize_border, right_resize_border)
+ });
self.increase_pane_height_down(&id, count);
for terminal_id in terminals_below {
self.reduce_pane_height_down(&terminal_id, count);
}
- for terminal_id in terminals_to_the_left.iter().chain(terminals_to_the_right.iter()) {
+ for terminal_id in terminals_to_the_left
+ .iter()
+ .chain(terminals_to_the_right.iter())
+ {
self.increase_pane_height_down(&terminal_id, count);
}
}
fn increase_pane_and_surroundings_right(&mut self, id: &RawFd, count: usize) {
- let mut terminals_to_the_right = self.terminal_ids_directly_right_of(&id).expect("can't increase pane size right if there are no terminals to the right");
- let terminal_borders_to_the_right: HashSet<usize> = terminals_to_the_right.iter().map(|t| self.terminals.get(t).unwrap().get_y()).collect();
- let (top_resize_border, terminals_above) = self.right_aligned_contiguous_panes_above(&id, &terminal_borders_to_the_right);
- let (bottom_resize_border, terminals_below) = self.right_aligned_contiguous_panes_below(&id, &terminal_borders_to_the_right);
- terminals_to_the_right.retain(|t| self.pane_is_between_horizontal_borders(t, top_resize_border, bottom_resize_border));
+ let mut terminals_to_the_right = self
+ .terminal_ids_directly_right_of(&id)
+ .expect("can't increase pane size right if there are no terminals to the right");
+ let terminal_borders_to_the_right: HashSet<usize> = terminals_to_the_right
+ .iter()
+ .map(|t| self.terminals.get(t).unwrap().get_y())
+ .collect();
+ let (top_resize_border, terminals_above) =
+ self.right_aligned_contiguous_panes_above(&id, &terminal_borders_to_the_right);
+ let (bottom_resize_border, terminals_below) =
+ self.right_aligned_contiguous_panes_below(&id, &terminal_borders_to_the_right);
+ terminals_to_the_right.retain(|t| {
+ self.pane_is_between_horizontal_borders(t, top_resize_border, bottom_resize_border)
+ });
self.increase_pane_width_right(&id, count);
for terminal_id in terminals_to_the_right {
self.reduce_pane_width_right(&terminal_id, count);
@@ -859,11 +1123,20 @@ impl Screen {
}
}
fn increase_pane_and_surroundings_left(&mut self, id: &RawFd, count: usize) {
- let mut terminals_to_the_left = self.terminal_ids_directly_left_of(&id).expect("can't increase pane size right if there are no terminals to the right");
- let terminal_borders_to_the_left: HashSet<usize> = terminals_to_the_left.iter().map(|t| self.terminals.get(t).unwrap().get_y()).collect();
- let (top_resize_border, terminals_above) = self.left_aligned_contiguous_panes_above(&id, &terminal_borders_to_the_left);
- let (bottom_resize_border, terminals_below) = self.left_aligned_contiguous_panes_below(&id, &terminal_borders_to_the_left);
- terminals_to_the_left.retain(|t| self.pane_is_between_horizontal_borders(t, top_resize_border, bottom_resize_border));
+ let mut terminals_to_the_left = self
+ .terminal_ids_directly_left_of(&id)
+ .expect("can't increase pane size right if there are no terminals to the right");
+ let terminal_borders_to_the_left: HashSet<usize> = terminals_to_the_left
+ .iter()
+ .map(|t| self.terminals.get(t).unwrap().get_y())
+ .collect();
+ let (top_resize_border, terminals_above) =
+ self.left_aligned_contiguous_panes_above(&id, &terminal_borders_to_the_left);
+ let (bottom_resize_border, terminals_below) =
+ self.left_aligned_contiguous_panes_below(&id, &terminal_borders_to_the_left);
+ terminals_to_the_left.retain(|t| {
+ self.pane_is_between_horizontal_borders(t, top_resize_border, bottom_resize_border)
+ });
self.increase_pane_width_left(&id, count);
for terminal_id in terminals_to_the_left {
self.reduce_pane_width_left(&terminal_id, count);
@@ -888,7 +1161,7 @@ impl Screen {
let pane = self.terminals.get(pane_id).expect("pane does not exist");
pane.get_x() > 0
}
- pub fn resize_right (&mut self) {
+ pub fn resize_right(&mut self) {
// TODO: find out by how much we actually reduced and only reduce by that much
let count = 10;
if let Some(active_terminal_id) = self.get_active_terminal_id() {
@@ -901,7 +1174,7 @@ impl Screen {
}
}
}
- pub fn resize_left (&mut self) {
+ pub fn resize_left(&mut self) {
// TODO: find out by how much we actually reduced and only reduce by that much
let count = 10;
if let Some(active_terminal_id) = self.get_active_terminal_id() {
@@ -914,7 +1187,7 @@ impl Screen {
}
}
}
- pub fn resize_down (&mut self) {
+ pub fn resize_down(&mut self) {
// TODO: find out by how much we actually reduced and only reduce by that much
let count = 2;
if let Some(active_terminal_id) = self.get_active_terminal_id() {
@@ -927,7 +1200,7 @@ impl Screen {
}
}
}
- pub fn resize_up (&mut self) {
+ pub fn resize_up(&mut self) {
// TODO: find out by how much we actually reduced and only reduce by that much
let count = 2;
if let Some(active_terminal_id) = self.get_active_terminal_id() {
@@ -947,7 +1220,10 @@ impl Screen {
let active_terminal_id = self.get_active_terminal_id().unwrap();
let terminal_ids: Vec<RawFd> = self.terminals.keys().copied().collect(); // TODO: better, no allocations
let first_terminal = terminal_ids.get(0).unwrap();
- let active_terminal_id_position = terminal_ids.iter().position(|id| id == &active_terminal_id).unwrap();
+ let active_terminal_id_position = terminal_ids
+ .iter()
+ .position(|id| id == &active_terminal_id)
+ .unwrap();
if let Some(next_terminal) = terminal_ids.get(active_terminal_id_position + 1) {
self.active_terminal = Some(*next_terminal);
} else {
@@ -978,8 +1254,16 @@ impl Screen {
if let Some(mut terminals_to_the_left) = self.terminal_ids_directly_left_of(&id) {
let terminal_borders_to_the_left = self.horizontal_borders(&terminals_to_the_left);
- if terminal_borders_to_the_left.contains(&upper_close_border) && terminal_borders_to_the_left.contains(&lower_close_border) {
- terminals_to_the_left.retain(|t| self.pane_is_between_horizontal_borders(t, upper_close_border, lower_close_border));
+ if terminal_borders_to_the_left.contains(&upper_close_border)
+ && terminal_borders_to_the_left.contains(&lower_close_border)
+ {
+ terminals_to_the_left.retain(|t| {
+ self.pane_is_between_horizontal_borders(
+ t,
+ upper_close_border,
+ lower_close_border,
+ )
+ });
return Some(terminals_to_the_left);
}
}
@@ -992,9 +1276,18 @@ impl Screen {
let lower_close_border = terminal.get_y() + terminal.get_rows() + 1;
if let Some(mut terminals_to_the_right) = self.terminal_ids_directly_right_of(&id) {
- let terminal_borders_to_the_right = self.horizontal_borders(&terminals_to_the_right);
- if terminal_borders_to_the_right.contains(&upper_close_border) && terminal_borders_to_the_right.contains(&lower_close_border) {
- terminals_to_the_right.retain(|t| self.pane_is_between_horizontal_borders(t, upper_close_border, lower_close_border));
+ let terminal_borders_to_the_right =
+ self.horizontal_borders(&terminals_to_the_right);
+ if terminal_borders_to_the_right.contains(&upper_close_border)
+ && terminal_borders_to_the_right.contains(&lower_close_border)
+ {
+ terminals_to_the_right.retain(|t| {
+ self.pane_is_between_horizontal_borders(
+ t,
+ upper_close_border,
+ lower_close_border,
+ )
+ });
return Some(terminals_to_the_right);
}
}
@@ -1008,8 +1301,16 @@ impl Screen {
if let Some(mut terminals_above) = self.terminal_ids_directly_above(&id) {
let terminal_borders_above = self.vertical_borders(&terminals_above);
- if terminal_borders_above.contains(&left_close_border) && terminal_borders_above.contains(&right_close_border) {
- terminals_above.retain(|t| self.pane_is_between_vertical_borders(t, left_close_border, right_close_border));
+ if terminal_borders_above.contains(&left_close_border)
+ && terminal_borders_above.contains(&right_close_border)
+ {
+ terminals_above.retain(|t| {
+ self.pane_is_between_vertical_borders(
+ t,
+ left_close_border,
+ right_close_border,
+ )
+ });
return Some(terminals_above);
}
}
@@ -1023,20 +1324,30 @@ impl Screen {
if let Some(mut terminals_below) = self.terminal_ids_directly_below(&id) {
let terminal_borders_below = self.vertical_borders(&terminals_below);
- if terminal_borders_below.contains(&left_close_border) && terminal_borders_below.contains(&right_close_border) {
- terminals_below.retain(|t| self.pane_is_between_vertical_borders(t, left_close_border, right_close_border));
+ if terminal_borders_below.contains(&left_close_border)
+ && terminal_borders_below.contains(&right_close_border)
+ {
+ terminals_below.retain(|t| {
+ self.pane_is_between_vertical_borders(
+ t,
+ left_close_border,
+ right_close_border,
+ )
+ });
return Some(terminals_below);
}
}
}
None
}
- fn close_down_to_max_terminals (&mut self) {
+ fn close_down_to_max_terminals(&mut self) {
if let Some(max_panes) = self.max_panes {
if self.terminals.len() >= max_panes {
for _ in max_panes..=self.terminals.len() {
let first_pid = *self.terminals.iter().next().unwrap().0;
- self.send_pty_instructions.send(PtyInstruction::ClosePane(first_pid)).unwrap();
+ self.send_pty_instructions
+ .send(PtyInstruction::ClosePane(first_pid))
+ .unwrap();
self.close_pane_without_rerender(first_pid); // TODO: do not render yet
}
}
@@ -1054,28 +1365,33 @@ impl Screen {
let terminal_to_close_height = terminal_to_close.get_rows();
if let Some(terminals) = self.terminals_to_the_left_between_aligning_borders(id) {
for terminal_id in terminals.iter() {
- &self.increase_pane_width_right(&terminal_id, terminal_to_close_width + 1); // 1 for the border
+ &self.increase_pane_width_right(&terminal_id, terminal_to_close_width + 1);
+ // 1 for the border
}
if self.active_terminal == Some(id) {
self.active_terminal = Some(*terminals.last().unwrap());
}
- } else if let Some(terminals) = self.terminals_to_the_right_between_aligning_borders(id) {
+ } else if let Some(terminals) = self.terminals_to_the_right_between_aligning_borders(id)
+ {
for terminal_id in terminals.iter() {
- &self.increase_pane_width_left(&terminal_id, terminal_to_close_width + 1); // 1 for the border
+ &self.increase_pane_width_left(&terminal_id, terminal_to_close_width + 1);
+ // 1 for the border
}
if self.active_terminal == Some(id) {
self.active_terminal = Some(*terminals.last().unwrap());
}
} else if let Some(terminals) = self.terminals_above_between_aligning_borders(id) {
for terminal_id in terminals.iter() {
- &self.increase_pane_height_down(&terminal_id, terminal_to_close_height + 1); // 1 for the border
+ &self.increase_pane_height_down(&terminal_id, terminal_to_close_height + 1);
+ // 1 for the border
}
if self.active_terminal == Some(id) {
self.active_terminal = Some(*terminals.last().unwrap());
}
} else if let Some(terminals) = self.terminals_below_between_aligning_borders(id) {
for terminal_id in terminals.iter() {
- &self.increase_pane_height_up(&terminal_id, terminal_to_close_height + 1); // 1 for the border
+ &self.increase_pane_height_up(&terminal_id, terminal_to_close_height + 1);
+ // 1 for the border
}
if self.active_terminal == Some(id) {
self.active_terminal = Some(*terminals.last().unwrap());
@@ -1091,7 +1407,9 @@ impl Screen {
}
pub fn close_focused_pane(&mut self) {
if let Some(active_terminal_id) = self.get_active_terminal_id() {
- self.send_pty_instructions.send(PtyInstruction::ClosePane(active_terminal_id)).unwrap();
+ self.send_pty_instructions
+ .send(PtyInstruction::ClosePane(active_terminal_id))
+ .unwrap();
self.close_pane(active_terminal_id);
}
}
diff --git a/src/terminal_pane/mod.rs b/src/terminal_pane/mod.rs
index d242947d..c6c10be2 100644
--- a/src/terminal_pane/mod.rs
+++ b/src/terminal_pane/mod.rs
@@ -1,7 +1,7 @@
-mod terminal_pane;
-mod terminal_character;
mod scroll;
+mod terminal_character;
+mod terminal_pane;
-pub use terminal_pane::*;
-pub use terminal_character::*;
pub use scroll::*;
+pub use terminal_character::*;
+pub use terminal_pane::*;
diff --git a/src/terminal_pane/scroll.rs b/src/terminal_pane/scroll.rs
index 8034431d..3ced3828 100644
--- a/src/terminal_pane/scroll.rs
+++ b/src/terminal_pane/scroll.rs
@@ -1,5 +1,5 @@
-use ::std::fmt::{self, Debug, Formatter};
use ::std::collections::VecDeque;
+use ::std::fmt::{self, Debug, Formatter};
use crate::terminal_pane::terminal_character::{TerminalCharacter, EMPTY_TERMINAL_CHARACTER};
@@ -23,13 +23,17 @@ use crate::terminal_pane::terminal_character::{TerminalCharacter, EMPTY_TERMINAL
#[derive(Clone)]
pub struct CanonicalLine {
- pub wrapped_fragments: Vec<WrappedFragment>
+ pub wrapped_fragments: Vec<WrappedFragment>,
}
-fn debug_log_to_file (message: String) {
+fn debug_log_to_file(message: String) {
use std::fs::OpenOptions;
use std::io::prelude::*;
- let mut file = OpenOptions::new().append(true).create(true).open("/tmp/mosaic-log.txt").unwrap();
+ let mut file = OpenOptions::new()
+ .append(true)
+ .create(true)
+ .open("/tmp/mosaic-log.txt")
+ .unwrap();
file.write_all(message.as_bytes()).unwrap();
file.write_all("\n".as_bytes()).unwrap();
}
@@ -46,12 +50,16 @@ impl CanonicalLine {
self.wrapped_fragments.push(new_fragment);
}
pub fn change_width(&mut self, new_width: usize) {
- let mut characters: Vec<TerminalCharacter> = self.wrapped_fragments
+ let mut characters: Vec<TerminalCharacter> = self
+ .wrapped_fragments
.iter()
- .fold(Vec::with_capacity(self.wrapped_fragments.len()), |mut characters, wrapped_fragment| {
- characters.push(wrapped_fragment.characters.iter().copied());
- characters
- })
+ .fold(
+ Vec::with_capacity(self.wrapped_fragments.len()),
+ |mut characters, wrapped_fragment| {
+ characters.push(wrapped_fragment.characters.iter().copied());
+ characters
+ },
+ )
.into_iter()
.flatten()
.collect();
@@ -59,7 +67,9 @@ impl CanonicalLine {
while characters.len() > 0 {
if characters.len() > new_width {
- wrapped_fragments.push(WrappedFragment::from_vec(characters.drain(..new_width).collect()));
+ wrapped_fragments.push(WrappedFragment::from_vec(
+ characters.drain(..new_width).collect(),
+ ));
} else {
wrapped_fragments.push(WrappedFragment::from_vec(characters.drain(..).collect()));
}
@@ -70,7 +80,10 @@ impl CanonicalLine {
self.wrapped_fragments = wrapped_fragments;
}
pub fn clear_after(&mut self, fragment_index: usize, column_index: usize) {
- let fragment_to_clear = self.wrapped_fragments.get_mut(fragment_index).expect("fragment out of bounds");
+ let fragment_to_clear = self
+ .wrapped_fragments
+ .get_mut(fragment_index)
+ .expect("fragment out of bounds");
fragment_to_clear.clear_after_and_including(column_index);
self.wrapped_fragments.truncate(fragment_index + 1);
}
@@ -87,16 +100,18 @@ impl Debug for CanonicalLine {
#[derive(Clone)]
pub struct WrappedFragment {
- pub characters: Vec<TerminalCharacter>
+ pub characters: Vec<TerminalCharacter>,
}
impl WrappedFragment {
pub fn new() -> Self {
- WrappedFragment {
- characters: vec![]
- }
+ WrappedFragment { characters: vec![] }
}
- pub fn add_character(&mut self, terminal_character: TerminalCharacter, position_in_line: usize) {
+ pub fn add_character(
+ &mut self,
+ terminal_character: TerminalCharacter,
+ position_in_line: usize,
+ ) {
if position_in_line == self.characters.len() {
self.characters.push(terminal_character);
} else {
@@ -106,9 +121,7 @@ impl WrappedFragment {
}
}
pub fn from_vec(characters: Vec<TerminalCharacter>) -> Self {
- WrappedFragment {
- characters
- }
+ WrappedFragment { characters }
}
pub fn clear_after_and_including(&mut self, character_index: usize) {
self.characters.truncate(character_index);
@@ -127,17 +140,17 @@ impl Debug for WrappedFragment {
#[derive(Debug)]
pub struct CursorPosition {
line_index: (usize, usize), // (canonical line index, fragment index in line)
- column_index: usize // 0 is the first character from the pane edge
+ column_index: usize, // 0 is the first character from the pane edge
}
impl CursorPosition {
pub fn new() -> Self {
CursorPosition {
line_index: (0, 0),
- column_index: 0
+ column_index: 0,
}
}
- pub fn move_forward (&mut self, count: usize) {
+ pub fn move_forward(&mut self, count: usize) {
// TODO: panic if out of bounds?
self.column_index += count;
}
@@ -150,7 +163,7 @@ impl CursorPosition {
pub fn move_to_next_canonical_line(&mut self) {
self.line_index.0 += 1;
}
- pub fn move_to_beginning_of_linewrap (&mut self) {
+ pub fn move_to_beginning_of_linewrap(&mut self) {
self.column_index = 0;
}
pub fn move_to_beginning_of_canonical_line(&mut self) {
@@ -188,7 +201,7 @@ pub struct Scroll {
}
impl Scroll {
- pub fn new (total_columns: usize, lines_in_view: usize) -> Self {
+ pub fn new(total_columns: usize, lines_in_view: usize) -> Self {
let mut canonical_lines = vec![];
canonical_lines.push(CanonicalLine::new());
let cursor_position = CursorPosition::new();
@@ -210,7 +223,8 @@ impl Scroll {
match canonical_lines.next() {
Some(current_canonical_line) => {
for wrapped_fragment in current_canonical_line.wrapped_fragments.iter().rev() {
- let mut line: Vec<TerminalCharacter> = wrapped_fragment.characters.iter().copied().collect();
+ let mut line: Vec<TerminalCharacter> =
+ wrapped_fragment.characters.iter().copied().collect();
if lines_to_skip > 0 {
lines_to_skip -= 1;
} else {
@@ -224,7 +238,7 @@ impl Scroll {
break 'gather_lines;
}
}
- },
+ }
None => break, // no more lines
}
}
@@ -242,10 +256,17 @@ impl Scroll {
Vec::from(lines)
}
pub fn add_character(&mut self, terminal_character: TerminalCharacter) {
- let (canonical_line_position, wrapped_fragment_index_in_line) = self.cursor_position.line_index;
+ let (canonical_line_position, wrapped_fragment_index_in_line) =
+ self.cursor_position.line_index;
let cursor_position_in_line = self.cursor_position.column_index;
- let current_line = self.canonical_lines.get_mut(canonical_line_position).expect("cursor out of bounds");
- let current_wrapped_fragment = current_line.wrapped_fragments.get_mut(wrapped_fragment_index_in_line).expect("cursor out of bounds");
+ let current_line = self
+ .canonical_lines
+ .get_mut(canonical_line_position)
+ .expect("cursor out of bounds");
+ let current_wrapped_fragment = current_line
+ .wrapped_fragments
+ .get_mut(wrapped_fragment_index_in_line)
+ .expect("cursor out of bounds");
if cursor_position_in_line <= self.total_columns {
current_wrapped_fragment.add_character(terminal_character, cursor_position_in_line);
@@ -257,27 +278,30 @@ impl Scroll {
self.cursor_position.move_forward(1);
}
}
- pub fn show_cursor (&mut self) {
+ pub fn show_cursor(&mut self) {
self.show_cursor = true;
}
- pub fn hide_cursor (&mut self) {
+ pub fn hide_cursor(&mut self) {
self.show_cursor = false;
}
pub fn add_canonical_line(&mut self) {
let current_canonical_line_index = self.cursor_position.line_index.0;
if let Some((scroll_region_top, scroll_region_bottom)) = self.scroll_region {
// the scroll region indices start at 1, so we need to adjust them
- if self.show_cursor { // scroll region should be ignored if the cursor is hidden
+ if self.show_cursor {
+ // scroll region should be ignored if the cursor is hidden
let scroll_region_top_index = scroll_region_top - 1;
let scroll_region_bottom_index = scroll_region_bottom - 1;
- if current_canonical_line_index == scroll_region_bottom_index { // end of scroll region
+ if current_canonical_line_index == scroll_region_bottom_index {
+ // end of scroll region
// when we have a scroll region set and we're at its bottom
// we need to delete its first line, thus shifting all lines in it upwards
// then we add an empty line at its end which will be filled by the application
// controlling the scroll region (presumably filled by whatever comes next in the
// scroll buffer, but that's not something we control)
self.canonical_lines.remove(scroll_region_top_index);
- self.canonical_lines.insert(scroll_region_bottom_index, CanonicalLine::new());
+ self.canonical_lines
+ .insert(scroll_region_bottom_index, CanonicalLine::new());
return;
}
}
@@ -294,11 +318,13 @@ impl Scroll {
panic!("cursor out of bounds, cannot add_canonical_line");
}
}
- pub fn cursor_coordinates_on_screen(&self) -> Option<(usize, usize)> { // (x, y)
+ pub fn cursor_coordinates_on_screen(&self) -> Option<(usize, usize)> {
+ // (x, y)
if !self.show_cursor {
- return None
+ return None;
}
- let (canonical_line_cursor_position, line_wrap_cursor_position) = self.cursor_position.line_index;
+ let (canonical_line_cursor_position, line_wrap_cursor_position) =
+ self.cursor_position.line_index;
let x = self.cursor_position.column_index;
let mut y = 0;
let mut indices_and_canonical_lines = self.canonical_lines.iter().enumerate().rev();
@@ -311,12 +337,16 @@ impl Scroll {
} else {
y += current_line.wrapped_fragments.len();
}
-
- },
+ }
None => break,
}
}
- let total_lines = self.canonical_lines.iter().fold(0, |total_lines, current_line| total_lines + current_line.wrapped_fragments.len()); // TODO: is this performant enough? should it be cached or kept track of?
+ let total_lines = self
+ .canonical_lines
+ .iter()
+ .fold(0, |total_lines, current_line| {
+ total_lines + current_line.wrapped_fragments.len()
+ }); // TODO: is this performant enough? should it be cached or kept track of?
let y = if total_lines < self.lines_in_view {
total_lines - y
} else if y > self.lines_in_view {
@@ -327,10 +357,17 @@ impl Scroll {
Some((x, y))
}
pub fn move_cursor_forward(&mut self, count: usize) {
- let (current_canonical_line_index, current_line_wrap_position) = self.cursor_position.line_index;
+ let (current_canonical_line_index, current_line_wrap_position) =
+ self.cursor_position.line_index;
let current_cursor_column_position = self.cursor_position.column_index;
- let current_canonical_line = self.canonical_lines.get_mut(current_canonical_line_index).expect("cursor out of bounds");
- let current_fragment = current_canonical_line.wrapped_fragments.get_mut(current_line_wrap_position).expect("cursor out of bounds");
+ let current_canonical_line = self
+ .canonical_lines
+ .get_mut(current_canonical_line_index)
+ .expect("cursor out of bounds");
+ let current_fragment = current_canonical_line
+ .wrapped_fragments
+ .get_mut(current_line_wrap_position)
+ .expect("cursor out of bounds");
let move_count = if current_cursor_column_position + count > self.total_columns {
// move to last column in the current line wrap
self.total_columns - current_cursor_column_position
@@ -367,7 +404,10 @@ impl Scroll {
for canonical_line in self.canonical_lines.iter_mut() {
canonical_line.change_width(columns);
}
- let cursor_line = self.canonical_lines.get(self.cursor_position.line_index.0).expect("cursor out of bounds");
+ let cursor_line = self
+ .canonical_lines
+ .get(self.cursor_position.line_index.0)
+ .expect("cursor out of bounds");
if cursor_line.wrapped_fragments.len() <= self.cursor_position.line_index.1 {
self.cursor_position.line_index.1 = cursor_line.wrapped_fragments.len() - 1;
}
@@ -376,17 +416,28 @@ impl Scroll {
self.total_columns = columns;
}
pub fn clear_canonical_line_right_of_cursor(&mut self) {
- let (current_canonical_line_index, current_line_wrap_position) = self.cursor_position.line_index;
+ let (current_canonical_line_index, current_line_wrap_position) =
+ self.cursor_position.line_index;
let current_cursor_column_position = self.cursor_position.column_index;
- let current_canonical_line = self.canonical_lines.get_mut(current_canonical_line_index).expect("cursor out of bounds");
- current_canonical_line.clear_after(current_line_wrap_position, current_cursor_column_position);
+ let current_canonical_line = self
+ .canonical_lines
+ .get_mut(current_canonical_line_index)
+ .expect("cursor out of bounds");
+ current_canonical_line
+ .clear_after(current_line_wrap_position, current_cursor_column_position);
}
pub fn clear_all_after_cursor(&mut self) {
- let (current_canonical_line_index, current_line_wrap_position) = self.cursor_position.line_index;
+ let (current_canonical_line_index, current_line_wrap_position) =
+ self.cursor_position.line_index;
let current_cursor_column_position = self.cursor_position.column_index;
- let current_canonical_line = self.canonical_lines.get_mut(current_canonical_line_index).expect("cursor out of bounds");
- current_canonical_line.clear_after(current_line_wrap_position, current_cursor_column_position);
- self.canonical_lines.truncate(current_canonical_line_index + 1);
+ let current_canonical_line = self
+ .canonical_lines
+ .get_mut(current_canonical_line_index)
+ .expect("cursor out of bounds");
+ current_canonical_line
+ .clear_after(current_line_wrap_position, current_cursor_column_position);
+ self.canonical_lines
+ .truncate(current_canonical_line_index + 1);
}
pub fn clear_all(&mut self) {
self.canonical_lines.clear();
@@ -402,9 +453,16 @@ impl Scroll {
}
self.cursor_position.move_to_canonical_line(line);
}
- let (current_canonical_line_index, current_line_wrap_position) = self.cursor_position.line_index;
- let current_canonical_line = self.canonical_lines.get_mut(current_canonical_line_index).expect("cursor out of bounds");
- let current_fragment = current_canonical_line.wrapped_fragments.get_mut(current_line_wrap_position).expect("cursor out of bounds");
+ let (current_canonical_line_index, current_line_wrap_position) =
+ self.cursor_position.line_index;
+ let current_canonical_line = self
+ .canonical_lines
+ .get_mut(current_canonical_line_index)
+ .expect("cursor out of bounds");
+ let current_fragment = current_canonical_line
+ .wrapped_fragments
+ .get_mut(current_line_wrap_position)
+ .expect("cursor out of bounds");
for _ in current_fragment.characters.len()..col {
current_fragment.characters.push(EMPTY_TERMINAL_CHARACTER);
}
@@ -423,15 +481,17 @@ impl Scroll {
let scroll_region_top_index = scroll_region_top - 1;
let scroll_region_bottom_index = scroll_region_bottom - 1;
let current_canonical_line_index = self.cursor_position.line_index.0;
- if current_canonical_line_index >= scroll_region_top_index &&
- current_canonical_line_index <= scroll_region_bottom_index {
+ if current_canonical_line_index >= scroll_region_top_index
+ && current_canonical_line_index <= scroll_region_bottom_index
+ {
// when deleting lines inside the scroll region, we must make sure it stays the
// same size (and that other lines below it aren't shifted inside it)
// so we delete the current line(s) and add an empty line at the end of the scroll
// region
for _ in 0..count {
self.canonical_lines.remove(current_canonical_line_index);
- self.canonical_lines.insert(scroll_region_bottom_index, CanonicalLine::new());
+ self.canonical_lines
+ .insert(scroll_region_bottom_index, CanonicalLine::new());
}
}
}
@@ -442,28 +502,29 @@ impl Scroll {
let scroll_region_top_index = scroll_region_top - 1;
let scroll_region_bottom_index = scroll_region_bottom - 1;
let current_canonical_line_index = self.cursor_position.line_index.0;
- if current_canonical_line_index >= scroll_region_top_index &&
- current_canonical_line_index <= scroll_region_bottom_index {
+ if current_canonical_line_index >= scroll_region_top_index
+ && current_canonical_line_index <= scroll_region_bottom_index
+ {
// when adding empty lines inside the scroll region, we must make sure it stays the
// same size and that lines don't "leak" outside of it
// so we add an empty line where the cursor currently is, and delete the last line
// of the scroll region
for _ in 0..count {
self.canonical_lines.remove(scroll_region_bottom_index);
- self.canonical_lines.insert(current_canonical_line_index, CanonicalLine::new());
+ self.canonical_lines
+ .insert(current_canonical_line_index, CanonicalLine::new());
}
}
}
}
- pub fn move_viewport_up (&mut self, count: usize) {
+ pub fn move_viewport_up(&mut self, count: usize) {
if let Some(current_offset) = self.viewport_bottom_offset.as_mut() {
*current_offset += count;
} else {
self.viewport_bottom_offset = Some(count);
}
-
}
- pub fn move_viewport_down (&mut self, count: usize) {
+ pub fn move_viewport_down(&mut self, count: usize) {
if let Some(current_offset) = self.viewport_bottom_offset.as_mut() {
if *current_offset > count {
*current_offset -= count;
@@ -472,7 +533,7 @@ impl Scroll {
}
}
}
- pub fn reset_viewport (&mut self) {
+ pub fn reset_viewport(&mut self) {
self.viewport_bottom_offset = None;
}
}
diff --git a/src/terminal_pane/terminal_character.rs b/src/terminal_pane/terminal_character.rs
index 53418306..2c5fe3ac 100644
--- a/src/terminal_pane/terminal_character.rs
+++ b/src/terminal_pane/terminal_character.rs
@@ -1,4 +1,4 @@
-use ::std::fmt::{self, Display, Debug, Formatter};
+use ::std::fmt::{self, Debug, Display, Formatter};
pub const EMPTY_TERMINAL_CHARACTER: TerminalCharacter = TerminalCharacter {
character: ' ',
@@ -14,14 +14,14 @@ pub const EMPTY_TERMINAL_CHARACTER: TerminalCharacter = TerminalCharacter {
bold: Some(AnsiCode::Reset),
dim: Some(AnsiCode::Reset),
italic: Some(AnsiCode::Reset),
- }
+ },
};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum AnsiCode {
Reset,
NamedColor(NamedColor),
- Code((Option<u16>, Option<u16>))
+ Code((Option<u16>, Option<u16>)),
}
#[derive(Clone, Copy, Eq, PartialEq, Debug)]
@@ -151,32 +151,36 @@ impl CharacterStyles {
self.dim = None;
self.italic = None;
}
- pub fn update_and_return_diff(&mut self, new_styles: &CharacterStyles) -> Option<CharacterStyles> {
+ pub fn update_and_return_diff(
+ &mut self,
+ new_styles: &CharacterStyles,
+ ) -> Option<CharacterStyles> {
let mut diff: Option<CharacterStyles> = None;
- if new_styles.foreground == Some(AnsiCode::Reset) &&
- new_styles.background == Some(AnsiCode::Reset) &&
- new_styles.strike == Some(AnsiCode::Reset) &&
- new_styles.hidden == Some(AnsiCode::Reset) &&
- new_styles.reverse == Some(AnsiCode::Reset) &&
- new_styles.fast_blink == Some(AnsiCode::Reset) &&
- new_styles.slow_blink == Some(AnsiCode::Reset) &&
- new_styles.underline == Some(AnsiCode::Reset) &&
- new_styles.bold == Some(AnsiCode::Reset) &&
- new_styles.dim == Some(AnsiCode::Reset) &&
- new_styles.italic == Some(AnsiCode::Reset) {
- self.foreground = Some(AnsiCode::Reset);
- self.background = Some(AnsiCode::Reset);
- self.strike = Some(AnsiCode::Reset);
- self.hidden = Some(AnsiCode::Reset);
- self.reverse = Some(AnsiCode::Reset);
- self.fast_blink = Some(AnsiCode::Reset);
- self.slow_blink = Some(AnsiCode::Reset);
- self.underline = Some(AnsiCode::Reset);
- self.bold = Some(AnsiCode::Reset);
- self.dim = Some(AnsiCode::Reset);
- self.italic = Some(AnsiCode::Reset);
- return Some(*new_styles)
+ if new_styles.foreground == Some(AnsiCode::Reset)
+ && new_styles.background == Some(AnsiCode::Reset)
+ && new_styles.strike == Some(AnsiCode::Reset)
+ && new_styles.hidden == Some(AnsiCode::Reset)
+ && new_styles.reverse == Some(AnsiCode::Reset)
+ && new_styles.fast_blink == Some(AnsiCode::Reset)
+ && new_styles.slow_blink == Some(AnsiCode::Reset)
+ && new_styles.underline == Some(AnsiCode::Reset)
+ && new_styles.bold == Some(AnsiCode::Reset)
+ && new_styles.dim == Some(AnsiCode::Reset)
+ && new_styles.italic == Some(AnsiCode::Reset)
+ {
+ self.foreground = Some(AnsiCode::Reset);
+ self.background = Some(AnsiCode::Reset);
+ self.strike = Some(AnsiCode::Reset);
+ self.hidden = Some(AnsiCode::Reset);
+ self.reverse = Some(AnsiCode::Reset);
+ self.fast_blink = Some(AnsiCode::Reset);
+ self.slow_blink = Some(AnsiCode::Reset);
+ self.underline = Some(AnsiCode::Reset);
+ self.bold = Some(AnsiCode::Reset);
+ self.dim = Some(AnsiCode::Reset);
+ self.italic = Some(AnsiCode::Reset);
+ return Some(*new_styles);
};
if self.foreground != new_styles.foreground {
@@ -218,10 +222,10 @@ impl CharacterStyles {
if self.reverse != new_styles.reverse {
if let Some(new_diff) = diff.as_mut() {
diff = Some(new_diff.reverse(new_styles.reverse));
- self.reverse= new_styles.reverse;
+ self.reverse = new_styles.reverse;
} else {
diff = Some(CharacterStyles::new().reverse(new_styles.reverse));
- self.reverse= new_styles.reverse;
+ self.reverse = new_styles.reverse;
}
}
if self.slow_blink != new_styles.slow_blink {
@@ -245,28 +249,28 @@ impl CharacterStyles {
if self.underline != new_styles.underline {
if let Some(new_diff) = diff.as_mut() {
diff = Some(new_diff.underline(new_styles.underline));
- self.underline= new_styles.underline;
+ self.underline = new_styles.underline;
} else {
diff = Some(CharacterStyles::new().underline(new_styles.underline));
- self.underline= new_styles.underline;
+ self.underline = new_styles.underline;
}
}
if self.bold != new_styles.bold {
if let Some(new_diff) = diff.as_mut() {
diff = Some(new_diff.bold(new_styles.bold));
- self.bold= new_styles.bold;
+ self.bold = new_styles.bold;
} else {
diff = Some(CharacterStyles::new().bold(new_styles.bold));
- self.bold= new_styles.bold;
+ self.bold = new_styles.bold;
}
}
if self.dim != new_styles.dim {
if let Some(new_diff) = diff.as_mut() {
diff = Some(new_diff.dim(new_styles.dim));
- self.dim= new_styles.dim;
+ self.dim = new_styles.dim;
} else {
diff = Some(CharacterStyles::new().dim(new_styles.dim));
- self.dim= new_styles.dim;
+ self.dim = new_styles.dim;
}
}
if self.italic != new_styles.italic {
@@ -297,18 +301,18 @@ impl CharacterStyles {
impl Display for CharacterStyles {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
- if self.foreground == Some(AnsiCode::Reset) &&
- self.background == Some(AnsiCode::Reset) &&
- self.strike == Some(AnsiCode::Reset) &&
- self.hidden == Some(AnsiCode::Reset) &&
- self.reverse == Some(AnsiCode::Reset) &&
- self.fast_blink == Some(AnsiCode::Reset) &&
- self.slow_blink == Some(AnsiCode::Reset) &&
- self.underline == Some(AnsiCode::Reset) &&
- self.bold == Some(AnsiCode::Reset) &&
- self.dim == Some(AnsiCode::Reset) &&
- self.italic == Some(AnsiCode::Reset) {
-
+ if self.foreground == Some(AnsiCode::Reset)
+ && self.background == Some(AnsiCode::Reset)
+ && self.strike == Some(AnsiCode::Reset)
+ && self.hidden == Some(AnsiCode::Reset)
+ && self.reverse == Some(AnsiCode::Reset)
+ && self.fast_blink == Some(AnsiCode::Reset)
+ && self.slow_blink == Some(AnsiCode::Reset)
+ && self.underline == Some(AnsiCode::Reset)
+ && self.bold == Some(AnsiCode::Reset)
+ && self.dim == Some(AnsiCode::Reset)
+ && self.italic == Some(AnsiCode::Reset)
+ {
write!(f, "\u{1b}[m")?; // reset all
return Ok(());
}
@@ -318,18 +322,18 @@ impl Display for CharacterStyles {
match (param1, param2) {
(Some(param1), Some(param2)) => {
write!(f, "\u{1b}[38;{};{}m", param1, param2)?;
- },
+ }
(Some(param1), None) => {
write!(f, "\u{1b}[38;{}m", param1)?;
- },
+ }
(_, _) => {
// TODO: can this happen?
}
}
- },
+ }
AnsiCode::Reset => {
write!(f, "\u{1b}[39m")?;
- },
+ }
AnsiCode::NamedColor(named_color) => {
write!(f, "\u{1b}[{}m", named_color.to_foreground_ansi_code())?;
}
@@ -341,15 +345,15 @@ impl Display for CharacterStyles {
match (param1, param2) {
(Some(param1), Some(param2)) => {
write!(f, "\u{1b}[48;{};{}m", param1, param2)?;
- },
+ }
(Some(param1), None) => {
write!(f, "\u{1b}[48;{}m", param1)?;
- },
+ }
(_, _) => {
// TODO: can this happen?
}
}
- },
+ }
AnsiCode::Reset => {
write!(f, "\u{1b}[49m")?;
}
@@ -360,122 +364,110 @@ impl Display for CharacterStyles {
}
if let Some(ansi_code) = self.strike {
match ansi_code {
- AnsiCode::Code((param1, param2)) => {
- match (param1, param2) {
- (Some(param1), Some(param2)) => {
- write!(f, "\u{1b}[9;{};{}m", param1, param2)?;
- },
- (Some(param1), None) => {
- write!(f, "\u{1b}[9;{}m", param1)?;
- },
- (_, _) => {
- write!(f, "\u{1b}[9m")?;
- }
+ AnsiCode::Code((param1, param2)) => match (param1, param2) {
+ (Some(param1), Some(param2)) => {
+ write!(f, "\u{1b}[9;{};{}m", param1, param2)?;
+ }
+ (Some(param1), None) => {
+ write!(f, "\u{1b}[9;{}m", param1)?;
+ }
+ (_, _) => {
+ write!(f, "\u{1b}[9m")?;
}
},
AnsiCode::Reset => {
write!(f, "\u{1b}[29m")?;
- },
+ }
_ => {}
}
}
if let Some(ansi_code) = self.hidden {
match ansi_code {
- AnsiCode::Code((param1, param2)) => {
- match (param1, param2) {
- (Some(param1), Some(param2)) => {
- write!(f, "\u{1b}[8;{};{}m", param1, param2)?;
- },
- (Some(param1), None) => {
- write!(f, "\u{1b}[8;{}m", param1)?;
- },
- (_, _) => {
- write!(f, "\u{1b}[8m")?;
- }
+ AnsiCode::Code((param1, param2)) => match (param1, param2) {
+ (Some(param1), Some(param2)) => {
+ write!(f, "\u{1b}[8;{};{}m", param1, param2)?;
+ }
+ (Some(param1), None) => {
+ write!(f, "\u{1b}[8;{}m", param1)?;
+ }
+ (_, _) => {
+ write!(f, "\u{1b}[8m")?;
}
},
AnsiCode::Reset => {
write!(f, "\u{1b}[28m")?;
- },
+ }
_ => {}
}
}
if let Some(ansi_code) = self.reverse {
match ansi_code {
- AnsiCode::Code((param1, param2)) => {
- match (param1, param2) {
- (Some(param1), Some(param2)) => {
- write!(f, "\u{1b}[7;{};{}m", param1, param2)?;
- },
- (Some(param1), None) => {
- write!(f, "\u{1b}[7;{}m", param1)?;
- },
- (_, _) => {
- write!(f, "\u{1b}[7m")?;
- }
+ AnsiCode::Code((param1, param2)) => match (param1, param2) {
+ (Some(param1), Some(param2)) => {
+ write!(f, "\u{1b}[7;{};{}m", param1, param2)?;
+ }
+ (Some(param1), None) => {
+ write!(f, "\u{1b}[7;{}m", param1)?;
+ }
+ (_, _) => {
+ write!(f, "\u{1b}[7m")?;
}
},
AnsiCode::Reset => {
write!(f, "\u{1b}[27m")?;
- },
+ }
_ => {}
}
}
if let Some(ansi_code) = self.fast_blink {
match ansi_code {
- AnsiCode::Code((param1, param2)) => {
- match (param1, param2) {
- (Some(param1), Some(param2)) => {
- write!(f, "\u{1b}[6;{};{}m", param1, param2)?;
- },
- (Some(param1), None) => {
- write!(f, "\u{1b}[6;{}m", param1)?;
- },
- (_, _) => {
- write!(f, "\u{1b}[6m")?;
- }
+ AnsiCode::Code((param1, param2)) => match (param1, param2) {
+ (Some(param1), Some(param2)) => {
+ write!(f, "\u{1b}[6;{};{}m", param1, param2)?;
+ }
+ (Some(param1), None) => {
+ write!(f, "\u{1b}[6;{}m", param1)?;
+ }
+ (_, _) => {
+ write!(f, "\u{1b}[6m")?;
}
},
AnsiCode::Reset => {
write!(f, "\u{1b}[25m")?;
- },
+ }
_ => {}
}
}
if let Some(ansi_code) = self.slow_blink {
match ansi_code {
- AnsiCode::Code((param1, param2)) => {
- match (param1, param2) {
- (Some(param1), Some(param2)) => {
- write!(f, "\u{1b}[5;{};{}m", param1, param2)?;
- },
- (Some(param1), None) => {
- write!(f, "\u{1b}[5;{}m", param1)?;
- },
- (_, _) => {
- write!(f, "\u{1b}[5m")?;
- }
+ AnsiCode::Code((param1, param2)) => match (param1, param2) {
+ (Some(param1), Some(param2)) => {
+ write!(f, "\u{1b}[5;{};{}m", param1, param2)?;
+ }
+ (Some(param1), None) => {
+ write!(f, "\u{1b}[5;{}m", param1)?;
+ }
+ (_, _) => {
+ write!(f, "\u{1b}[5m")?;
}
},
AnsiCode::Reset => {
write!(f, "\u{1b}[25m")?;
- },
+ }
_ => {}
}
}
if let Some(ansi_code) = self.bold {
match ansi_code {
- AnsiCode::Code((param1, param2)) => {
- match (param1, param2) {
- (Some(param1), Some(param2)) => {
- write!(f, "\u{1b}[1;{};{}m", param1, param2)?;
- },
- (Some(param1), None) => {
- write!(f, "\u{1b}[1;{}m", param1)?;
- },
- (_, _) => {
- write!(f, "\u{1b}[1m")?;
- }
+ AnsiCode::Code((param1, param2)) => match (param1, param2) {
+ (Some(param1), Some(param2)) => {
+ write!(f, "\u{1b}[1;{};{}m", param1, param2)?;
+ }
+ (Some(param1), None) => {
+ write!(f, "\u{1b}[1;{}m", param1)?;
+ }
+ (_, _) => {
+ write!(f, "\u{1b}[1m")?;
}
},
AnsiCode::Reset => {
@@ -483,7 +475,7 @@ impl Display for CharacterStyles {
// character_ansi_codes.push_str(&format!("\u{1b}[22m"));
// TODO: this cancels bold + underline, if this behaviour is indeed correct, we
// need to properly handle it in the struct methods etc like dim
- },
+ }
_ => {}
}
}
@@ -492,38 +484,34 @@ impl Display for CharacterStyles {
// otherwise
if let Some(ansi_code) = self.underline {
match ansi_code {
- AnsiCode::Code((param1, param2)) => {
- match (param1, param2) {
- (Some(param1), Some(param2)) => {
- write!(f, "\u{1b}[4;{};{}m", param1, param2)?;
- },
- (Some(param1), None) => {
- write!(f, "\u{1b}[4;{}m", param1)?;
- },
- (_, _) => {
- write!(f, "\u{1b}[4m")?;
- }
+ AnsiCode::Code((param1, param2)) => match (param1, param2) {
+ (Some(param1), Some(param2)) => {
+ write!(f, "\u{1b}[4;{};{}m", param1, param2)?;
+ }
+ (Some(param1), None) => {
+ write!(f, "\u{1b}[4;{}m", param1)?;
+ }
+ (_, _) => {
+ write!(f, "\u{1b}[4m")?;
}
},
AnsiCode::Reset => {
write!(f, "\u{1b}[24m")?;
- },
+ }
_ => {}
}
}
if let Some(ansi_code) = self.dim {
match ansi_code {
- AnsiCode::Code((param1, param2)) => {
- match (param1, param2) {
- (Some(param1), Some(param2)) => {
- write!(f, "\u{1b}[2;{};{}m", param1, param2)?;
- },
- (Some(param1), None) => {
- write!(f, "\u{1b}[2;{}m", param1)?;
- },
- (_, _) => {
- write!(f, "\u{1b}[2m")?;
- }
+ AnsiCode::Code((param1, param2)) => match (param1, param2) {
+ (Some(param1), Some(param2)) => {
+ write!(f, "\u{1b}[2;{};{}m", param1, param2)?;
+ }
+ (Some(param1), None) => {
+ write!(f, "\u{1b}[2;{}m", param1)?;
+ }
+ (_, _) => {
+ write!(f, "\u{1b}[2m")?;
}
},
AnsiCode::Reset => {
@@ -532,32 +520,30 @@ impl Display for CharacterStyles {
match bold {
AnsiCode::Reset => {
write!(f, "\u{1b}[22m")?;
- },
+ }
_ => {}
}
}
- },
+ }
_ => {}
}
}
if let Some(ansi_code) = self.italic {
match ansi_code {
- AnsiCode::Code((param1, param2)) => {
- match (param1, param2) {
- (Some(param1), Some(param2)) => {
- write!(f, "\u{1b}[3;{};{}m", param1, param2)?;
- },
- (Some(param1), None) => {
- write!(f, "\u{1b}[3;{}m", param1)?;
- },
- (_, _) => {
- write!(f, "\u{1b}[3m")?;
- }
+ AnsiCode::Code((param1, param2)) => match (param1, param2) {
+ (Some(param1), Some(param2)) => {
+ write!(f, "\u{1b}[3;{};{}m", param1, param2)?;
+ }
+ (Some(param1), None) => {
+ write!(f, "\u{1b}[3;{}m", param1)?;
+ }
+ (_, _) => {
+ write!(f, "\u{1b}[3m")?;
}
},
AnsiCode::Reset => {
write!(f, "\u{1b}[23m")?;
- },
+ }
_ => {}
}
};
diff --git a/src/terminal_pane/terminal_pane.rs b/src/terminal_pane/terminal_pane.rs
index 853ff54f..3e0cdd6b 100644
--- a/src/terminal_pane/terminal_pane.rs
+++ b/src/terminal_pane/terminal_pane.rs
@@ -1,16 +1,13 @@
-use ::std::os::unix::io::RawFd;
use ::nix::pty::Winsize;
+use ::std::os::unix::io::RawFd;
use ::vte::Perform;
-use crate::VteEvent;
use crate::boundaries::Rect;
-use crate::terminal_pane::Scroll;
use crate::terminal_pane::terminal_character::{
- TerminalCharacter,
- CharacterStyles,
- AnsiCode,
- NamedColor
+ AnsiCode, CharacterStyles, NamedColor, TerminalCharacter,
};
+use crate::terminal_pane::Scroll;
+use crate::VteEvent;
#[derive(Clone, Copy, Debug)]
pub struct PositionAndSize {
@@ -45,7 +42,7 @@ impl Rect for &mut TerminalPane {
}
impl TerminalPane {
- pub fn new (pid: RawFd, ws: Winsize, x: usize, y: usize) -> TerminalPane {
+ pub fn new(pid: RawFd, ws: Winsize, x: usize, y: usize) -> TerminalPane {
let scroll = Scroll::new(ws.ws_col as usize, ws.ws_row as usize);
let pending_styles = CharacterStyles::new();
let position_and_size = PositionAndSize {
@@ -68,26 +65,26 @@ impl TerminalPane {
VteEvent::Print(c) => {
self.print(c);
self.should_render = true;
- },
+ }
VteEvent::Execute(byte) => {
self.execute(byte);
- },
+ }
VteEvent::Hook(params, intermediates, ignore, c) => {
self.hook(&params, &intermediates, ignore, c);
- },
+ }
VteEvent::Put(byte) => {
self.put(byte);
- },
+ }
VteEvent::Unhook => {
self.unhook();
- },
+ }
VteEvent::OscDispatch(params, bell_terminated) => {
let params: Vec<&[u8]> = params.iter().map(|p| &p[..]).collect();
self.osc_dispatch(&params[..], bell_terminated);
- },
+ }
VteEvent::CsiDispatch(params, intermediates, ignore, c) => {
self.csi_dispatch(&params, &intermediates, ignore, c);
- },
+ }
VteEvent::EscDispatch(intermediates, ignore, byte) => {
self.esc_dispatch(&intermediates, ignore, byte);
}
@@ -145,50 +142,35 @@ impl TerminalPane {
}
pub fn get_x(&self) -> usize {
match self.position_and_size_override {
- Some(position_and_size_override) => {
- position_and_size_override.x
- },
- None => {
- self.position_and_size.x as usize
- }
+ Some(position_and_size_override) => position_and_size_override.x,
+ None => self.position_and_size.x as usize,
}
}
pub fn get_y(&self) -> usize {
match self.position_and_size_override {
- Some(position_and_size_override) => {
- position_and_size_override.y
- },
- None => {
- self.position_and_size.y as usize
- }
+ Some(position_and_size_override) => position_and_size_override.y,
+ None => self.position_and_size.y as usize,
}
}
pub fn get_columns(&self) -> usize {
match &self.position_and_size_override.as_ref() {
- Some(position_and_size_override) => {
- position_and_size_override.columns
- },
- None => {
- self.position_and_size.columns as usize
- }
+ Some(position_and_size_override) => position_and_size_override.columns,
+ None => self.position_and_size.columns as usize,
}
}
pub fn get_rows(&self) -> usize {
match &self.position_and_size_override.as_ref() {
- Some(position_and_size_override) => {
- position_and_size_override.rows
- },
- None => {
- self.position_and_size.rows as usize
- }
+ Some(position_and_size_override) => position_and_size_override.rows,
+ None => self.position_and_size.rows as usize,
}
}
- fn reflow_lines (&mut self) {
+ fn reflow_lines(&mut self) {
let rows = self.get_rows();
let columns = self.get_columns();
self.scroll.change_size(columns, rows);
}
- pub fn buffer_as_vte_output(&mut self) -> Option<String> { // TODO: rename to render
+ pub fn buffer_as_vte_output(&mut self) -> Option<String> {
+ // TODO: rename to render
// if self.should_render {
if true {
// while checking should_render rather than rendering each pane every time
@@ -208,7 +190,9 @@ impl TerminalPane {
// in some cases (eg. while resizing) some characters will spill over
// before they are corrected by the shell (for the prompt) or by reflowing
// lines
- if let Some(new_styles) = character_styles.update_and_return_diff(&t_character.styles) {
+ if let Some(new_styles) =
+ character_styles.update_and_return_diff(&t_character.styles)
+ {
// the terminal keeps the previous styles as long as we're in the same
// line, so we only want to update the new styles here (this also
// includes resetting previous styles as needed)
@@ -225,10 +209,11 @@ impl TerminalPane {
None
}
}
- pub fn read_buffer_as_lines (&self) -> Vec<Vec<TerminalCharacter>> {
+ pub fn read_buffer_as_lines(&self) -> Vec<Vec<TerminalCharacter>> {
self.scroll.as_character_lines()
}
- pub fn cursor_coordinates (&self) -> Option<(usize, usize)> { // (x, y)
+ pub fn cursor_coordinates(&self) -> Option<(usize, usize)> {
+ // (x, y)
self.scroll.cursor_coordinates_on_screen()
}
pub fn scroll_up(&mut self, count: usize) {
@@ -259,12 +244,12 @@ impl TerminalPane {
self.reflow_lines();
self.should_render = true;
}
- fn add_newline (&mut self) {
+ fn add_newline(&mut self) {
self.scroll.add_canonical_line();
// self.reset_all_ansi_codes(); // TODO: find out if we should be resetting here or not
self.should_render = true;
}
- fn move_to_beginning_of_line (&mut self) {
+ fn move_to_beginning_of_line(&mut self) {
self.scroll.move_cursor_to_beginning_of_linewrap();
}
fn move_cursor_backwards(&mut self, count: usize) {
@@ -275,11 +260,15 @@ impl TerminalPane {
}
}
-fn debug_log_to_file (message: String, pid: RawFd) {
+fn debug_log_to_file(message: String, pid: RawFd) {
if pid == 3 {
use std::fs::OpenOptions;
use std::io::prelude::*;
- let mut file = OpenOptions::new().append(true).create(true).open("/tmp/mosaic-log.txt").unwrap();
+ let mut file = OpenOptions::new()
+ .append(true)
+ .create(true)
+ .open("/tmp/mosaic-log.txt")
+ .unwrap();
file.write_all(message.as_bytes()).unwrap();
file.write_all("\n".as_bytes()).unwrap();
}
@@ -297,11 +286,14 @@ impl vte::Perform for TerminalPane {
}
fn execute(&mut self, byte: u8) {
- if byte == 13 { // 0d, carriage return
+ if byte == 13 {
+ // 0d, carriage return
self.move_to_beginning_of_line();
- } else if byte == 08 { // backspace
+ } else if byte == 08 {
+ // backspace
self.move_cursor_backwards(1);
- } else if byte == 10 { // 0a, newline
+ } else if byte == 10 {
+ // 0a, newline
self.add_newline();
}
}
@@ -360,219 +352,334 @@ impl vte::Perform for TerminalPane {
} else if params[0] == 38 {
match (params.get(1), params.get(2)) {
(Some(param1), Some(param2)) => {
- self.pending_styles = self.pending_styles.foreground(Some(AnsiCode::Code((Some(*param1 as u16), Some(*param2 as u16)))));
- },
+ self.pending_styles = self.pending_styles.foreground(Some(AnsiCode::Code(
+ (Some(*param1 as u16), Some(*param2 as u16)),
+ )));
+ }
(Some(param1), None) => {
- self.pending_styles = self.pending_styles.foreground(Some(AnsiCode::Code((Some(*param1 as u16), None))));
+ self.pending_styles = self
+ .pending_styles
+ .foreground(Some(AnsiCode::Code((Some(*param1 as u16), None))));
}
(_, _) => {
- self.pending_styles = self.pending_styles.foreground(Some(AnsiCode::Code((None, None))));
+ self.pending_styles = self
+ .pending_styles
+ .foreground(Some(AnsiCode::Code((None, None))));
}
};
} else if params[0] == 48 {
match (params.get(1), params.get(2)) {
(Some(param1), Some(param2)) => {
- self.pending_styles = self.pending_styles.background(Some(AnsiCode::Code((Some(*param1 as u16), Some(*param2 as u16)))));
- },
+ self.pending_styles = self.pending_styles.background(Some(AnsiCode::Code(
+ (Some(*param1 as u16), Some(*param2 as u16)),
+ )));
+ }
(Some(param1), None) => {
- self.pending_styles = self.pending_styles.background(Some(AnsiCode::Code((Some(*param1 as u16), None))));
+ self.pending_styles = self
+ .pending_styles
+ .background(Some(AnsiCode::Code((Some(*param1 as u16), None))));
}
(_, _) => {
- self.pending_styles = self.pending_styles.background(Some(AnsiCode::Code((None, None))));
+ self.pending_styles = self
+ .pending_styles
+ .background(Some(AnsiCode::Code((None, None))));
}
};
} else if params[0] == 1 {
// bold
match (params.get(1), params.get(2)) {
(Some(param1), Some(param2)) => {
- self.pending_styles = self.pending_styles.bold(Some(AnsiCode::Code((Some(*param1 as u16), Some(*param2 as u16)))));
- },
+ self.pending_styles = self.pending_styles.bold(Some(AnsiCode::Code((
+ Some(*param1 as u16),
+ Some(*param2 as u16),
+ ))));
+ }
(Some(param1), None) => {
- self.pending_styles = self.pending_styles.bold(Some(AnsiCode::Code((Some(*param1 as u16), None))));
+ self.pending_styles = self
+ .pending_styles
+ .bold(Some(AnsiCode::Code((Some(*param1 as u16), None))));
}
(_, _) => {
- self.pending_styles = self.pending_styles.bold(Some(AnsiCode::Code((None, None))));
+ self.pending_styles =
+ self.pending_styles.bold(Some(AnsiCode::Code((None, None))));
}
};
} else if params[0] == 2 {
// dim
match (params.get(1), params.get(2)) {
(Some(param1), Some(param2)) => {
- self.pending_styles = self.pending_styles.dim(Some(AnsiCode::Code((Some(*param1 as u16), Some(*param2 as u16)))));
- },
+ self.pending_styles = self.pending_styles.dim(Some(AnsiCode::Code((
+ Some(*param1 as u16),
+ Some(*param2 as u16),
+ ))));
+ }
(Some(param1), None) => {
- self.pending_styles = self.pending_styles.dim(Some(AnsiCode::Code((Some(*param1 as u16), None))));
+ self.pending_styles = self
+ .pending_styles
+ .dim(Some(AnsiCode::Code((Some(*param1 as u16), None))));
}
(_, _) => {
- self.pending_styles = self.pending_styles.dim(Some(AnsiCode::Code((None, None))));
+ self.pending_styles =
+ self.pending_styles.dim(Some(AnsiCode::Code((None, None))));
}
};
} else if params[0] == 3 {
// italic
match (params.get(1), params.get(2)) {
(Some(param1), Some(param2)) => {
- self.pending_styles = self.pending_styles.italic(Some(AnsiCode::Code((Some(*param1 as u16), Some(*param2 as u16)))));
- },
+ self.pending_styles = self.pending_styles.italic(Some(AnsiCode::Code((
+ Some(*param1 as u16),
+ Some(*param2 as u16),
+ ))));
+ }
(Some(param1), None) => {
- self.pending_styles = self.pending_styles.italic(Some(AnsiCode::Code((Some(*param1 as u16), None))));
+ self.pending_styles = self
+ .pending_styles
+ .italic(Some(AnsiCode::Code((Some(*param1 as u16), None))));
}
(_, _) => {
- self.pending_styles = self.pending_styles.italic(Some(AnsiCode::Code((None, None))));
+ self.pending_styles = self
+ .pending_styles
+ .italic(Some(AnsiCode::Code((None, None))));
}
};
} else if params[0] == 4 {
// underline
match (params.get(1), params.get(2)) {
(Some(param1), Some(param2)) => {
- self.pending_styles = self.pending_styles.underline(Some(AnsiCode::Code((Some(*param1 as u16), Some(*param2 as u16)))));
- },
+ self.pending_styles = self.pending_styles.underline(Some(AnsiCode::Code(
+ (Some(*param1 as u16), Some(*param2 as u16)),
+ )));
+ }
(Some(param1), None) => {
- self.pending_styles = self.pending_styles.underline(Some(AnsiCode::Code((Some(*param1 as u16), None))));
+ self.pending_styles = self
+ .pending_styles
+ .underline(Some(AnsiCode::Code((Some(*param1 as u16), None))));
}
(_, _) => {
- self.pending_styles = self.pending_styles.underline(Some(AnsiCode::Code((None, None))));
+ self.pending_styles = self
+ .pending_styles
+ .underline(Some(AnsiCode::Code((None, None))));
}
};
} else if params[0] == 5 {
// blink slow
match (params.get(1), params.get(2)) {
(Some(param1), Some(param2)) => {
- self.pending_styles = self.pending_styles.blink_slow(Some(AnsiCode::Code((Some(*param1 as u16), Some(*param2 as u16)))));
- },
+ self.pending_styles = self.pending_styles.blink_slow(Some(AnsiCode::Code(
+ (Some(*param1 as u16), Some(*param2 as u16)),
+ )));
+ }
(Some(param1), None) => {
- self.pending_styles = self.pending_styles.blink_slow(Some(AnsiCode::Code((Some(*param1 as u16), None))));
+ self.pending_styles = self
+ .pending_styles
+ .blink_slow(Some(AnsiCode::Code((Some(*param1 as u16), None))));
}
(_, _) => {
- self.pending_styles = self.pending_styles.blink_slow(Some(AnsiCode::Code((None, None))));
+ self.pending_styles = self
+ .pending_styles
+ .blink_slow(Some(AnsiCode::Code((None, None))));
}
};
} else if params[0] == 6 {
// blink fast
match (params.get(1), params.get(2)) {
(Some(param1), Some(param2)) => {
- self.pending_styles = self.pending_styles.blink_fast(Some(AnsiCode::Code((Some(*param1 as u16), Some(*param2 as u16)))));
- },
+ self.pending_styles = self.pending_styles.blink_fast(Some(AnsiCode::Code(
+ (Some(*param1 as u16), Some(*param2 as u16)),
+ )));
+ }
(Some(param1), None) => {
- self.pending_styles = self.pending_styles.blink_fast(Some(AnsiCode::Code((Some(*param1 as u16), None))));
+ self.pending_styles = self
+ .pending_styles
+ .blink_fast(Some(AnsiCode::Code((Some(*param1 as u16), None))));
}
(_, _) => {
- self.pending_styles = self.pending_styles.blink_fast(Some(AnsiCode::Code((None, None))));
+ self.pending_styles = self
+ .pending_styles
+ .blink_fast(Some(AnsiCode::Code((None, None))));
}
};
} else if params[0] == 7 {
// reverse
match (params.get(1), params.get(2)) {
(Some(param1), Some(param2)) => {
- self.pending_styles = self.pending_styles.reverse(Some(AnsiCode::Code((Some(*param1 as u16), Some(*param2 as u16)))));
- },
+ self.pending_styles = self.pending_styles.reverse(Some(AnsiCode::Code((
+ Some(*param1 as u16),
+ Some(*param2 as u16),
+ ))));
+ }
(Some(param1), None) => {
- self.pending_styles = self.pending_styles.reverse(Some(AnsiCode::Code((Some(*param1 as u16), None))));
+ self.pending_styles = self
+ .pending_styles
+ .reverse(Some(AnsiCode::Code((Some(*param1 as u16), None))));
}
(_, _) => {
- self.pending_styles = self.pending_styles.reverse(Some(AnsiCode::Code((None, None))));
+ self.pending_styles = self
+ .pending_styles
+ .reverse(Some(AnsiCode::Code((None, None))));
}
};
} else if params[0] == 8 {
// hidden
match (params.get(1), params.get(2)) {
(Some(param1), Some(param2)) => {
- self.pending_styles = self.pending_styles.hidden(Some(AnsiCode::Code((Some(*param1 as u16), Some(*param2 as u16)))));
- },
+ self.pending_styles = self.pending_styles.hidden(Some(AnsiCode::Code((
+ Some(*param1 as u16),
+ Some(*param2 as u16),
+ ))));
+ }
(Some(param1), None) => {
- self.pending_styles = self.pending_styles.hidden(Some(AnsiCode::Code((Some(*param1 as u16), None))));
+ self.pending_styles = self
+ .pending_styles
+ .hidden(Some(AnsiCode::Code((Some(*param1 as u16), None))));
}
(_, _) => {
- self.pending_styles = self.pending_styles.hidden(Some(AnsiCode::Code((None, None))));
+ self.pending_styles = self
+ .pending_styles
+ .hidden(Some(AnsiCode::Code((None, None))));
}
};
} else if params[0] == 9 {
// strike
match (params.get(1), params.get(2)) {
(Some(param1), Some(param2)) => {
- self.pending_styles = self.pending_styles.strike(Some(AnsiCode::Code((Some(*param1 as u16), Some(*param2 as u16)))));
- },
+ self.pending_styles = self.pending_styles.strike(Some(AnsiCode::Code((
+ Some(*param1 as u16),
+ Some(*param2 as u16),
+ ))));
+ }
(Some(param1), None) => {
- self.pending_styles = self.pending_styles.strike(Some(AnsiCode::Code((Some(*param1 as u16), None))));
+ self.pending_styles = self
+ .pending_styles
+ .strike(Some(AnsiCode::Code((Some(*param1 as u16), None))));
}
(_, _) => {
- self.pending_styles = self.pending_styles.strike(Some(AnsiCode::Code((None, None))));
+ self.pending_styles = self
+ .pending_styles
+ .strike(Some(AnsiCode::Code((None, None))));
}
};
} else if params[0] == 30 {
- self.pending_styles = self.pending_styles.foreground(Some(AnsiCode::NamedColor(NamedColor::Black)));
+ self.pending_styles = self
+ .pending_styles
+ .foreground(Some(AnsiCode::NamedColor(NamedColor::Black)));
} else if params[0] == 31 {
- self.pending_styles = self.pending_styles.foreground(Some(AnsiCode::NamedColor(NamedColor::Red)));
+ self.pending_styles = self
+ .pending_styles
+ .foreground(Some(AnsiCode::NamedColor(NamedColor::Red)));
} else if params[0] == 32 {
- self.pending_styles = self.pending_styles.foreground(Some(AnsiCode::NamedColor(NamedColor::Green)));
+ self.pending_styles = self
+ .pending_styles
+ .foreground(Some(AnsiCode::NamedColor(NamedColor::Green)));
} else if params[0] == 33 {
- self.pending_styles = self.pending_styles.foreground(Some(AnsiCode::NamedColor(NamedColor::Yellow)));
+ self.pending_styles = self
+ .pending_styles
+ .foreground(Some(AnsiCode::NamedColor(NamedColor::Yellow)));
} else if params[0] == 34 {
- self.pending_styles = self.pending_styles.foreground(Some(AnsiCode::NamedColor(NamedColor::Blue)));
+ self.pending_styles = self
+ .pending_styles
+ .foreground(Some(AnsiCode::NamedColor(NamedColor::Blue)));
} else if params[0] == 35 {
- self.pending_styles = self.pending_styles.foreground(Some(AnsiCode::NamedColor(NamedColor::Magenta)));
+ self.pending_styles = self
+ .pending_styles
+ .foreground(Some(AnsiCode::NamedColor(NamedColor::Magenta)));
} else if params[0] == 36 {
- self.pending_styles = self.pending_styles.foreground(Some(AnsiCode::NamedColor(NamedColor::Cyan)));
+ self.pending_styles = self
+ .pending_styles
+ .foreground(Some(AnsiCode::NamedColor(NamedColor::Cyan)));
} else if params[0] == 37 {
- self.pending_styles = self.pending_styles.foreground(Some(AnsiCode::NamedColor(NamedColor::White)));
+ self.pending_styles = self
+ .pending_styles
+ .foreground(Some(AnsiCode::NamedColor(NamedColor::White)));
} else if params[0] == 40 {
- self.pending_styles = self.pending_styles.background(Some(AnsiCode::NamedColor(NamedColor::Black)));
+ self.pending_styles = self
+ .pending_styles
+ .background(Some(AnsiCode::NamedColor(NamedColor::Black)));
} else if params[0] == 41 {
- self.pending_styles = self.pending_styles.background(Some(AnsiCode::NamedColor(NamedColor::Red)));
+ self.pending_styles = self
+ .pending_styles
+ .background(Some(AnsiCode::NamedColor(NamedColor::Red)));
} else if params[0] == 42 {
- self.pending_styles = self.pending_styles.background(Some(AnsiCode::NamedColor(NamedColor::Green)));
+ self.pending_styles = self
+ .pending_styles
+ .background(Some(AnsiCode::NamedColor(NamedColor::Green)));
} else if params[0] == 43 {
- self.pending_styles = self.pending_styles.background(Some(AnsiCode::NamedColor(NamedColor::Yellow)));
+ self.pending_styles = self
+ .pending_styles
+ .background(Some(AnsiCode::NamedColor(NamedColor::Yellow)));
} else if params[0] == 44 {
- self.pending_styles = self.pending_styles.background(Some(AnsiCode::NamedColor(NamedColor::Blue)));
+ self.pending_styles = self
+ .pending_styles
+ .background(Some(AnsiCode::NamedColor(NamedColor::Blue)));
} else if params[0] == 45 {
- self.pending_styles = self.pending_styles.background(Some(AnsiCode::NamedColor(NamedColor::Magenta)));
+ self.pending_styles = self
+ .pending_styles
+ .background(Some(AnsiCode::NamedColor(NamedColor::Magenta)));
} else if params[0] == 46 {
- self.pending_styles = self.pending_styles.background(Some(AnsiCode::NamedColor(NamedColor::Cyan)));
+ self.pending_styles = self
+ .pending_styles
+ .background(Some(AnsiCode::NamedColor(NamedColor::Cyan)));
} else if params[0] == 47 {
- self.pending_styles = self.pending_styles.background(Some(AnsiCode::NamedColor(NamedColor::White)));
+ self.pending_styles = self
+ .pending_styles
+ .background(Some(AnsiCode::NamedColor(NamedColor::White)));
} else {
debug_log_to_file(format!("unhandled csi m code {:?}", params), self.pid);
}
- } else if c == 'C' { // move cursor forward
- let move_by = if params[0] == 0 { 1 } else { params[0] as usize };
+ } else if c == 'C' {
+ // move cursor forward
+ let move_by = if params[0] == 0 {
+ 1
+ } else {
+ params[0] as usize
+ };
self.scroll.move_cursor_forward(move_by);
- } else if c == 'K' { // clear line (0 => right, 1 => left, 2 => all)
+ } else if c == 'K' {
+ // clear line (0 => right, 1 => left, 2 => all)
if params[0] == 0 {
self.scroll.clear_canonical_line_right_of_cursor();
}
- // TODO: implement 1 and 2
- } else if c == 'J' { // clear all (0 => below, 1 => above, 2 => all, 3 => saved)
+ // TODO: implement 1 and 2
+ } else if c == 'J' {
+ // clear all (0 => below, 1 => above, 2 => all, 3 => saved)
if params[0] == 0 {
self.scroll.clear_all_after_cursor();
} else if params[0] == 2 {
self.scroll.clear_all();
}
- // TODO: implement 1
- } else if c == 'H' { // goto row/col
+ // TODO: implement 1
+ } else if c == 'H' {
+ // goto row/col
let (row, col) = if params.len() == 1 {
(params[0] as usize, 0) // TODO: is this always correct ?
} else {
(params[0] as usize - 1, params[1] as usize - 1) // we subtract 1 here because this csi is 1 indexed and we index from 0
};
self.scroll.move_cursor_to(row, col);
- } else if c == 'A' { // move cursor up until edge of screen
+ } else if c == 'A' {
+ // move cursor up until edge of screen
let move_up_count = if params[0] == 0 { 1 } else { params[0] };
self.scroll.move_cursor_up(move_up_count as usize);
} else if c == 'D' {
- let move_back_count = if params[0] == 0 { 1 } else { params[0] as usize };
+ let move_back_count = if params[0] == 0 {
+ 1
+ } else {
+ params[0] as usize
+ };
self.scroll.move_cursor_back(move_back_count);
} else if c == 'l' {
let first_intermediate_is_questionmark = match _intermediates.get(0) {
Some(b'?') => true,
None => false,
- _ => false
+ _ => false,
};
if first_intermediate_is_questionmark {
match params.get(0) {
Some(25) => {
self.scroll.hide_cursor();
self.should_render = true;
- },
+ }
_ => {}
};
}
@@ -580,14 +687,14 @@ impl vte::Perform for TerminalPane {
let first_intermediate_is_questionmark = match _intermediates.get(0) {
Some(b'?') => true,
None => false,
- _ => false
+ _ => false,
};
if first_intermediate_is_questionmark {
match params.get(0) {
Some(25) => {
self.scroll.show_cursor();
self.should_render = true;
- },
+ }
_ => {}
};
}
@@ -595,7 +702,8 @@ impl vte::Perform for TerminalPane {
if params.len() > 1 {
let top_line_index = params[0] as usize;
let bottom_line_index = params[1] as usize;
- self.scroll.set_scroll_region(top_line_index, bottom_line_index);
+ self.scroll
+ .set_scroll_region(top_line_index, bottom_line_index);
self.scroll.show_cursor();
} else {
self.scroll.clear_scroll_region();
@@ -608,12 +716,22 @@ impl vte::Perform for TerminalPane {
// TBD - identify terminal
} else if c == 'M' {
// delete lines if currently inside scroll region
- let line_count_to_delete = if params[0] == 0 { 1 } else { params[0] as usize };
- self.scroll.delete_lines_in_scroll_region(line_count_to_delete);
+ let line_count_to_delete = if params[0] == 0 {
+ 1
+ } else {
+ params[0] as usize
+ };
+ self.scroll
+ .delete_lines_in_scroll_region(line_count_to_delete);
} else if c == 'L' {
// insert blank lines if inside scroll region
- let line_count_to_add = if params[0] == 0 { 1 } else { params[0] as usize };
- self.scroll.add_empty_lines_in_scroll_region(line_count_to_add);
+ let line_count_to_add = if params[0] == 0 {
+ 1
+ } else {
+ params[0] as usize
+ };
+ self.scroll
+ .add_empty_lines_in_scroll_region(line_count_to_add);
} else if c == 'q' || c == 'd' || c == 'X' || c == 'G' {
// ignore for now to run on mac
} else {
diff --git a/src/tests/fakes.rs b/src/tests/fakes.rs
index a9f34778..109424cf 100644
--- a/src/tests/fakes.rs
+++ b/src/tests/fakes.rs
@@ -1,13 +1,13 @@
-use ::std::time::Duration;
use ::nix::pty::Winsize;
-use ::std::os::unix::io::RawFd;
-use ::std::io::{Read, Write};
use ::std::collections::HashMap;
-use ::std::sync::{Arc, Mutex};
+use ::std::io::{Read, Write};
+use ::std::os::unix::io::RawFd;
use ::std::path::PathBuf;
+use ::std::sync::{Arc, Mutex};
+use ::std::time::Duration;
use crate::os_input_output::OsApi;
-use crate::tests::possible_tty_inputs::{Bytes, get_possible_tty_inputs};
+use crate::tests::possible_tty_inputs::{get_possible_tty_inputs, Bytes};
#[derive(Clone)]
pub enum IoEvent {
@@ -87,7 +87,7 @@ pub struct FakeInputOutput {
impl FakeInputOutput {
pub fn new(winsize: Winsize) -> Self {
let mut win_sizes = HashMap::new();
- win_sizes.insert(0 , winsize); // 0 is the current terminal
+ win_sizes.insert(0, winsize); // 0 is the current terminal
FakeInputOutput {
read_buffers: Arc::new(Mutex::new(HashMap::new())),
stdin_writes: Arc::new(Mutex::new(HashMap::new())),
@@ -117,15 +117,30 @@ impl OsApi for FakeInputOutput {
*winsize
}
fn set_terminal_size_using_fd(&mut self, pid: RawFd, cols: u16, rows: u16) {
- let terminal_input = self.possible_tty_inputs.get(&cols).expect(&format!("could not find input for size {:?}", cols));
- self.read_buffers.lock().unwrap().insert(pid, terminal_input.clone());
- self.io_events.lock().unwrap().push(IoEvent::SetTerminalSizeUsingFd(pid, cols, rows));
+ let terminal_input = self
+ .possible_tty_inputs
+ .get(&cols)
+ .expect(&format!("could not find input for size {:?}", cols));
+ self.read_buffers
+ .lock()
+ .unwrap()
+ .insert(pid, terminal_input.clone());
+ self.io_events
+ .lock()
+ .unwrap()
+ .push(IoEvent::SetTerminalSizeUsingFd(pid, cols, rows));
}
fn into_raw_mode(&mut self, pid: RawFd) {
- self.io_events.lock().unwrap().push(IoEvent::IntoRawMode(pid));
+ self.io_events
+ .lock()
+ .unwrap()
+ .push(IoEvent::IntoRawMode(pid));
}
fn unset_raw_mode(&mut self, pid: RawFd) {
- self.io_events.lock().unwrap().push(IoEvent::UnsetRawMode(pid));
+ self.io_events
+ .lock()
+ .unwrap()
+ .push(IoEvent::UnsetRawMode(pid));
}
fn spawn_terminal(&mut self, _file_to_open: Option<PathBuf>) -> (RawFd, RawFd) {
let next_terminal_id = { self.read_buffers.lock().unwrap().keys().len() as RawFd + 1 };
@@ -158,7 +173,7 @@ impl OsApi for FakeInputOutput {
bytes.set_read_position(bytes_read);
}
return Ok(bytes_read);
- },
+ }
None => {
attempts_left -= 1;
}
diff --git a/src/tests/integration/basic.rs b/src/tests/integration/basic.rs
index a7e84ad0..6640b6e6 100644
--- a/src/tests/integration/basic.rs
+++ b/src/tests/integration/basic.rs
@@ -1,29 +1,20 @@
-use ::nix::pty::Winsize;
use ::insta::assert_snapshot;
+use ::nix::pty::Winsize;
-use crate::{start, Opt};
-use crate::tests::fakes::{FakeInputOutput};
-use crate::tests::utils::get_output_frame_snapshots;
+use crate::tests::fakes::FakeInputOutput;
use crate::tests::utils::commands::{
- SPLIT_HORIZONTALLY,
- SPLIT_VERTICALLY,
- RESIZE_UP,
- MOVE_FOCUS,
- RESIZE_LEFT,
- RESIZE_RIGHT,
- SPAWN_TERMINAL,
- QUIT,
- SCROLL_UP,
- SCROLL_DOWN,
- TOGGLE_ACTIVE_TERMINAL_FULLSCREEN,
+ MOVE_FOCUS, QUIT, RESIZE_LEFT, RESIZE_RIGHT, RESIZE_UP, SCROLL_DOWN, SCROLL_UP, SPAWN_TERMINAL,
+ SPLIT_HORIZONTALLY, SPLIT_VERTICALLY, TOGGLE_ACTIVE_TERMINAL_FULLSCREEN,
};
+use crate::tests::utils::get_output_frame_snapshots;
+use crate::{start, Opt};
-fn get_fake_os_input (fake_win_size: &Winsize) -> FakeInputOutput {
+fn get_fake_os_input(fake_win_size: &Winsize) -> FakeInputOutput {
FakeInputOutput::new(fake_win_size.clone())
}
#[test]
-pub fn starts_with_one_terminal () {
+pub fn starts_with_one_terminal() {
let fake_win_size = Winsize {
ws_col: 121,
ws_row: 20,
@@ -33,7 +24,11 @@ pub fn starts_with_one_terminal () {
let mut fake_input_output = get_fake_os_input(&fake_win_size);
fake_input_output.add_terminal_input(&[QUIT]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -49,12 +44,13 @@ pub fn split_terminals_vertically() {
ws_ypixel: 0,
};
let mut fake_input_output = get_fake_os_input(&fake_win_size);
- fake_input_output.add_terminal_input(&[
- SPLIT_VERTICALLY,
- QUIT,
- ]);
+ fake_input_output.add_terminal_input(&[SPLIT_VERTICALLY, QUIT]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -70,12 +66,13 @@ pub fn split_terminals_horizontally() {
ws_ypixel: 0,
};
let mut fake_input_output = get_fake_os_input(&fake_win_size);
- fake_input_output.add_terminal_input(&[
- SPLIT_HORIZONTALLY,
- QUIT,
- ]);
+ fake_input_output.add_terminal_input(&[SPLIT_HORIZONTALLY, QUIT]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -83,7 +80,7 @@ pub fn split_terminals_horizontally() {
}
#[test]
-pub fn split_largest_terminal () {
+pub fn split_largest_terminal() {
// this finds the largest pane and splits along its longest edge (vertically or horizontally)
let fake_win_size = Winsize {
ws_col: 121,
@@ -92,14 +89,13 @@ pub fn split_largest_terminal () {
ws_ypixel: 0,
};
let mut fake_input_output = get_fake_os_input(&fake_win_size);
- fake_input_output.add_terminal_input(&[
- SPAWN_TERMINAL,
- SPAWN_TERMINAL,
- SPAWN_TERMINAL,
- QUIT,
- ]);
+ fake_input_output.add_terminal_input(&[SPAWN_TERMINAL, SPAWN_TERMINAL, SPAWN_TERMINAL, QUIT]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -144,7 +140,11 @@ pub fn resize_right_and_up_on_the_same_axis() {
QUIT,
]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -170,7 +170,11 @@ pub fn scrolling_inside_a_pane() {
QUIT,
]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -178,7 +182,7 @@ pub fn scrolling_inside_a_pane() {
}
#[test]
-pub fn max_panes () {
+pub fn max_panes() {
// with the --max-panes option, we only allow a certain amount of panes on screen
// simultaneously, new panes beyond this limit will close older panes on screen
let fake_win_size = Winsize {
@@ -193,12 +197,16 @@ pub fn max_panes () {
SPAWN_TERMINAL,
SPAWN_TERMINAL,
SPAWN_TERMINAL,
- QUIT
+ QUIT,
]);
let mut opts = Opt::default();
opts.max_panes = Some(4);
start(Box::new(fake_input_output.clone()), opts);
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -206,7 +214,7 @@ pub fn max_panes () {
}
#[test]
-pub fn toggle_focused_pane_fullscreen () {
+pub fn toggle_focused_pane_fullscreen() {
let fake_win_size = Winsize {
ws_col: 121,
ws_row: 20,
@@ -229,12 +237,16 @@ pub fn toggle_focused_pane_fullscreen () {
MOVE_FOCUS,
TOGGLE_ACTIVE_TERMINAL_FULLSCREEN,
TOGGLE_ACTIVE_TERMINAL_FULLSCREEN,
- QUIT
+ QUIT,
]);
let mut opts = Opt::default();
opts.max_panes = Some(4);
start(Box::new(fake_input_output.clone()), opts);
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
diff --git a/src/tests/integration/close_pane.rs b/src/tests/integration/close_pane.rs
index ddb41d1e..ba44ec08 100644
--- a/src/tests/integration/close_pane.rs
+++ b/src/tests/integration/close_pane.rs
@@ -1,22 +1,16 @@
-use ::nix::pty::Winsize;
use ::insta::assert_snapshot;
+use ::nix::pty::Winsize;
-use crate::{start, Opt};
-use crate::tests::fakes::{FakeInputOutput};
+use crate::tests::fakes::FakeInputOutput;
use crate::tests::utils::get_output_frame_snapshots;
+use crate::{start, Opt};
use crate::tests::utils::commands::{
- SPLIT_HORIZONTALLY,
+ CLOSE_FOCUSED_PANE, MOVE_FOCUS, QUIT, RESIZE_DOWN, RESIZE_LEFT, RESIZE_UP, SPLIT_HORIZONTALLY,
SPLIT_VERTICALLY,
- RESIZE_DOWN,
- RESIZE_UP,
- MOVE_FOCUS,
- RESIZE_LEFT,
- QUIT,
- CLOSE_FOCUSED_PANE,
};
-fn get_fake_os_input (fake_win_size: &Winsize) -> FakeInputOutput {
+fn get_fake_os_input(fake_win_size: &Winsize) -> FakeInputOutput {
FakeInputOutput::new(fake_win_size.clone())
}
@@ -37,14 +31,14 @@ pub fn close_pane_with_another_pane_above_it() {
ws_ypixel: 0,
};
let mut fake_input_output = get_fake_os_input(&fake_win_size);
- fake_input_output.add_terminal_input(&[
- SPLIT_HORIZONTALLY,
- CLOSE_FOCUSED_PANE,
- QUIT,
- ]);
+ fake_input_output.add_terminal_input(&[SPLIT_HORIZONTALLY, CLOSE_FOCUSED_PANE, QUIT]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -76,7 +70,11 @@ pub fn close_pane_with_another_pane_below_it() {
]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -98,14 +96,14 @@ pub fn close_pane_with_another_pane_to_the_left() {
ws_ypixel: 0,
};
let mut fake_input_output = get_fake_os_input(&fake_win_size);
- fake_input_output.add_terminal_input(&[
- SPLIT_VERTICALLY,
- CLOSE_FOCUSED_PANE,
- QUIT,
- ]);
+ fake_input_output.add_terminal_input(&[SPLIT_VERTICALLY, CLOSE_FOCUSED_PANE, QUIT]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -127,15 +125,14 @@ pub fn close_pane_with_another_pane_to_the_right() {
ws_ypixel: 0,
};
let mut fake_input_output = get_fake_os_input(&fake_win_size);
- fake_input_output.add_terminal_input(&[
- SPLIT_VERTICALLY,
- MOVE_FOCUS,
- CLOSE_FOCUSED_PANE,
- QUIT,
- ]);
+ fake_input_output.add_terminal_input(&[SPLIT_VERTICALLY, MOVE_FOCUS, CLOSE_FOCUSED_PANE, QUIT]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -170,7 +167,11 @@ pub fn close_pane_with_multiple_panes_above_it() {
]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -203,7 +204,11 @@ pub fn close_pane_with_multiple_panes_below_it() {
]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -238,7 +243,11 @@ pub fn close_pane_with_multiple_panes_to_the_left() {
]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -271,7 +280,11 @@ pub fn close_pane_with_multiple_panes_to_the_right() {
]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -318,7 +331,11 @@ pub fn close_pane_with_multiple_panes_above_it_away_from_screen_edges() {
]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -365,7 +382,11 @@ pub fn close_pane_with_multiple_panes_below_it_away_from_screen_edges() {
]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -414,7 +435,11 @@ pub fn close_pane_with_multiple_panes_to_the_left_away_from_screen_edges() {
]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -463,7 +488,11 @@ pub fn close_pane_with_multiple_panes_to_the_right_away_from_screen_edges() {
]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -489,7 +518,11 @@ pub fn closing_last_pane_exits_app() {
]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
diff --git a/src/tests/integration/compatibility.rs b/src/tests/integration/compatibility.rs
index e6a913e6..a7cd375c 100644
--- a/src/tests/integration/compatibility.rs
+++ b/src/tests/integration/compatibility.rs
@@ -1,11 +1,11 @@
-use ::nix::pty::Winsize;
use ::insta::assert_snapshot;
+use ::nix::pty::Winsize;
use ::std::collections::HashMap;
-use crate::{start, Opt};
+use crate::tests::fakes::FakeInputOutput;
use crate::tests::possible_tty_inputs::Bytes;
-use crate::tests::fakes::{FakeInputOutput};
use crate::tests::utils::get_output_frame_snapshots;
+use crate::{start, Opt};
use crate::tests::utils::commands::QUIT;
@@ -22,7 +22,7 @@ use crate::tests::utils::commands::QUIT;
*
*/
-fn get_fake_os_input (fake_win_size: &Winsize, fixture_name: &str) -> FakeInputOutput {
+fn get_fake_os_input(fake_win_size: &Winsize, fixture_name: &str) -> FakeInputOutput {
let mut tty_inputs = HashMap::new();
let fixture_bytes = Bytes::from_file_in_fixtures(&fixture_name);
tty_inputs.insert(fake_win_size.ws_col, fixture_bytes);
@@ -41,7 +41,11 @@ pub fn run_bandwhich_from_fish_shell() {
let mut fake_input_output = get_fake_os_input(&fake_win_size, fixture_name);
fake_input_output.add_terminal_input(&[QUIT]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -60,7 +64,11 @@ pub fn fish_tab_completion_options() {
let mut fake_input_output = get_fake_os_input(&fake_win_size, fixture_name);
fake_input_output.add_terminal_input(&[QUIT]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -84,7 +92,11 @@ pub fn fish_select_tab_completion_options() {
let mut fake_input_output = get_fake_os_input(&fake_win_size, fixture_name);
fake_input_output.add_terminal_input(&[QUIT]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -92,7 +104,7 @@ pub fn fish_select_tab_completion_options() {
}
#[test]
-pub fn vim_scroll_region_down () {
+pub fn vim_scroll_region_down() {
// here we test a case where vim defines the scroll region as lesser than the screen row count
// and then scrolls down
// the region is defined here by vim as 1-26 (there are 28 rows)
@@ -113,7 +125,11 @@ pub fn vim_scroll_region_down () {
// fake_input_output.add_terminal_input(&[17]); // quit (ctrl-q)
fake_input_output.add_terminal_input(&[QUIT]); // quit (ctrl-q)
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -138,7 +154,11 @@ pub fn vim_ctrl_d() {
let mut fake_input_output = get_fake_os_input(&fake_win_size, fixture_name);
fake_input_output.add_terminal_input(&[QUIT]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -162,7 +182,11 @@ pub fn vim_ctrl_u() {
let mut fake_input_output = get_fake_os_input(&fake_win_size, fixture_name);
fake_input_output.add_terminal_input(&[QUIT]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
diff --git a/src/tests/integration/mod.rs b/src/tests/integration/mod.rs
index 138f36a7..677af578 100644
--- a/src/tests/integration/mod.rs
+++ b/src/tests/integration/mod.rs
@@ -1,7 +1,7 @@
pub mod basic;
+pub mod close_pane;
pub mod compatibility;
-pub mod resize_right;
+pub mod resize_down;
pub mod resize_left;
+pub mod resize_right;
pub mod resize_up;
-pub mod resize_down;
-pub mod close_pane;
diff --git a/src/tests/integration/resize_down.rs b/src/tests/integration/resize_down.rs
index 732c01a7..cd149c59 100644
--- a/src/tests/integration/resize_down.rs
+++ b/src/tests/integration/resize_down.rs
@@ -1,20 +1,15 @@
-use ::nix::pty::Winsize;
use ::insta::assert_snapshot;
+use ::nix::pty::Winsize;
-use crate::{start, Opt};
-use crate::tests::fakes::{FakeInputOutput};
+use crate::tests::fakes::FakeInputOutput;
use crate::tests::utils::get_output_frame_snapshots;
+use crate::{start, Opt};
use crate::tests::utils::commands::{
- SPLIT_HORIZONTALLY,
- SPLIT_VERTICALLY,
- RESIZE_DOWN,
- MOVE_FOCUS,
- RESIZE_LEFT,
- QUIT,
+ MOVE_FOCUS, QUIT, RESIZE_DOWN, RESIZE_LEFT, SPLIT_HORIZONTALLY, SPLIT_VERTICALLY,
};
-fn get_fake_os_input (fake_win_size: &Winsize) -> FakeInputOutput {
+fn get_fake_os_input(fake_win_size: &Winsize) -> FakeInputOutput {
FakeInputOutput::new(fake_win_size.clone())
}
@@ -25,7 +20,7 @@ pub fn resize_down_with_pane_above() {
// │ │ │ │
// ├───────────┤ ==resize=down==> │ │
// │███████████│ ├───────────┤
- // │███████████│ │███████████│
+ // │███████████│ │███████████│
// │███████████│ │███████████│
// └───────────┘ └───────────┘
// █ == focused pane
@@ -36,14 +31,14 @@ pub fn resize_down_with_pane_above() {
ws_ypixel: 0,
};
let mut fake_input_output = get_fake_os_input(&fake_win_size);
- fake_input_output.add_terminal_input(&[
- SPLIT_HORIZONTALLY,
- RESIZE_DOWN,
- QUIT,
- ]);
+ fake_input_output.add_terminal_input(&[SPLIT_HORIZONTALLY, RESIZE_DOWN, QUIT]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -67,14 +62,14 @@ pub fn resize_down_with_pane_below() {
ws_ypixel: 0,
};
let mut fake_input_output = get_fake_os_input(&fake_win_size);
- fake_input_output.add_terminal_input(&[SPLIT_HORIZONTALLY,
- MOVE_FOCUS,
- RESIZE_DOWN,
- QUIT,
- ]);
+ fake_input_output.add_terminal_input(&[SPLIT_HORIZONTALLY, MOVE_FOCUS, RESIZE_DOWN, QUIT]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -111,7 +106,11 @@ pub fn resize_down_with_panes_above_and_below() {
]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -148,7 +147,11 @@ pub fn resize_down_with_multiple_panes_above() {
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -187,7 +190,11 @@ pub fn resize_down_with_panes_above_aligned_left_with_current_pane() {
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -225,7 +232,11 @@ pub fn resize_down_with_panes_below_aligned_left_with_current_pane() {
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -261,7 +272,11 @@ pub fn resize_down_with_panes_above_aligned_right_with_current_pane() {
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -298,7 +313,11 @@ pub fn resize_down_with_panes_below_aligned_right_with_current_pane() {
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -338,7 +357,11 @@ pub fn resize_down_with_panes_above_aligned_left_and_right_with_current_pane() {
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -380,7 +403,11 @@ pub fn resize_down_with_panes_below_aligned_left_and_right_with_current_pane() {
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -437,7 +464,11 @@ pub fn resize_down_with_panes_above_aligned_left_and_right_with_panes_to_the_lef
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -496,7 +527,11 @@ pub fn resize_down_with_panes_below_aligned_left_and_right_with_to_the_left_and_
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
diff --git a/src/tests/integration/resize_left.rs b/src/tests/integration/resize_left.rs
index ad59b85e..87c746ca 100644
--- a/src/tests/integration/resize_left.rs
+++ b/src/tests/integration/resize_left.rs
@@ -1,20 +1,15 @@
-use ::nix::pty::Winsize;
use ::insta::assert_snapshot;
+use ::nix::pty::Winsize;
-use crate::{start, Opt};
-use crate::tests::fakes::{FakeInputOutput};
+use crate::tests::fakes::FakeInputOutput;
use crate::tests::utils::get_output_frame_snapshots;
+use crate::{start, Opt};
use crate::tests::utils::commands::{
- SPLIT_HORIZONTALLY,
- SPLIT_VERTICALLY,
- RESIZE_UP,
- MOVE_FOCUS,
- RESIZE_LEFT,
- QUIT,
+ MOVE_FOCUS, QUIT, RESIZE_LEFT, RESIZE_UP, SPLIT_HORIZONTALLY, SPLIT_VERTICALLY,
};
-fn get_fake_os_input (fake_win_size: &Winsize) -> FakeInputOutput {
+fn get_fake_os_input(fake_win_size: &Winsize) -> FakeInputOutput {
FakeInputOutput::new(fake_win_size.clone())
}
@@ -33,14 +28,14 @@ pub fn resize_left_with_pane_to_the_left() {
ws_ypixel: 0,
};
let mut fake_input_output = get_fake_os_input(&fake_win_size);
- fake_input_output.add_terminal_input(&[
- SPLIT_VERTICALLY,
- RESIZE_LEFT,
- QUIT,
- ]);
+ fake_input_output.add_terminal_input(&[SPLIT_VERTICALLY, RESIZE_LEFT, QUIT]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -62,15 +57,14 @@ pub fn resize_left_with_pane_to_the_right() {
ws_ypixel: 0,
};
let mut fake_input_output = get_fake_os_input(&fake_win_size);
- fake_input_output.add_terminal_input(&[
- SPLIT_VERTICALLY,
- MOVE_FOCUS,
- RESIZE_LEFT,
- QUIT,
- ]);
+ fake_input_output.add_terminal_input(&[SPLIT_VERTICALLY, MOVE_FOCUS, RESIZE_LEFT, QUIT]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -102,7 +96,11 @@ pub fn resize_left_with_panes_to_the_left_and_right() {
]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -137,7 +135,11 @@ pub fn resize_left_with_multiple_panes_to_the_left() {
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -174,7 +176,11 @@ pub fn resize_left_with_panes_to_the_left_aligned_top_with_current_pane() {
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -208,7 +214,11 @@ pub fn resize_left_with_panes_to_the_right_aligned_top_with_current_pane() {
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -244,7 +254,11 @@ pub fn resize_left_with_panes_to_the_left_aligned_bottom_with_current_pane() {
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -279,7 +293,11 @@ pub fn resize_left_with_panes_to_the_right_aligned_bottom_with_current_pane() {
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -319,7 +337,11 @@ pub fn resize_left_with_panes_to_the_left_aligned_top_and_bottom_with_current_pa
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -361,7 +383,11 @@ pub fn resize_left_with_panes_to_the_right_aligned_top_and_bottom_with_current_p
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -418,7 +444,11 @@ pub fn resize_left_with_panes_to_the_left_aligned_top_and_bottom_with_panes_abov
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -435,7 +465,8 @@ pub fn resize_left_with_panes_to_the_right_aligned_top_and_bottom_with_panes_abo
// ├─────┼─────┤ ├───┴─┬─────┤
// └─────┴─────┘ └─────┴─────┘
// █ == focused pane
- let fake_win_size = Winsize { // TODO: combine with above
+ let fake_win_size = Winsize {
+ // TODO: combine with above
ws_col: 121,
ws_row: 40,
ws_xpixel: 0,
@@ -477,7 +508,11 @@ pub fn resize_left_with_panes_to_the_right_aligned_top_and_bottom_with_panes_abo
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
diff --git a/src/tests/integration/resize_right.rs b/src/tests/integration/resize_right.rs
index ee809b41..b2201591 100644
--- a/src/tests/integration/resize_right.rs
+++ b/src/tests/integration/resize_right.rs
@@ -1,20 +1,15 @@
-use ::nix::pty::Winsize;
use ::insta::assert_snapshot;
+use ::nix::pty::Winsize;
-use crate::{start, Opt};
-use crate::tests::fakes::{FakeInputOutput};
+use crate::tests::fakes::FakeInputOutput;
use crate::tests::utils::get_output_frame_snapshots;
+use crate::{start, Opt};
use crate::tests::utils::commands::{
- SPLIT_HORIZONTALLY,
- SPLIT_VERTICALLY,
- RESIZE_UP,
- MOVE_FOCUS,
- RESIZE_RIGHT,
- QUIT,
+ MOVE_FOCUS, QUIT, RESIZE_RIGHT, RESIZE_UP, SPLIT_HORIZONTALLY, SPLIT_VERTICALLY,
};
-fn get_fake_os_input (fake_win_size: &Winsize) -> FakeInputOutput {
+fn get_fake_os_input(fake_win_size: &Winsize) -> FakeInputOutput {
FakeInputOutput::new(fake_win_size.clone())
}
@@ -33,14 +28,14 @@ pub fn resize_right_with_pane_to_the_left() {
ws_ypixel: 0,
};
let mut fake_input_output = get_fake_os_input(&fake_win_size);
- fake_input_output.add_terminal_input(&[
- SPLIT_VERTICALLY,
- RESIZE_RIGHT,
- QUIT,
- ]);
+ fake_input_output.add_terminal_input(&[SPLIT_VERTICALLY, RESIZE_RIGHT, QUIT]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -62,15 +57,14 @@ pub fn resize_right_with_pane_to_the_right() {
ws_ypixel: 0,
};
let mut fake_input_output = get_fake_os_input(&fake_win_size);
- fake_input_output.add_terminal_input(&[
- SPLIT_VERTICALLY,
- MOVE_FOCUS,
- RESIZE_RIGHT,
- QUIT,
- ]);
+ fake_input_output.add_terminal_input(&[SPLIT_VERTICALLY, MOVE_FOCUS, RESIZE_RIGHT, QUIT]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -102,7 +96,11 @@ pub fn resize_right_with_panes_to_the_left_and_right() {
]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -137,7 +135,11 @@ pub fn resize_right_with_multiple_panes_to_the_left() {
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -174,7 +176,11 @@ pub fn resize_right_with_panes_to_the_left_aligned_top_with_current_pane() {
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -208,7 +214,11 @@ pub fn resize_right_with_panes_to_the_right_aligned_top_with_current_pane() {
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -244,7 +254,11 @@ pub fn resize_right_with_panes_to_the_left_aligned_bottom_with_current_pane() {
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -279,7 +293,11 @@ pub fn resize_right_with_panes_to_the_right_aligned_bottom_with_current_pane() {
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -314,12 +332,16 @@ pub fn resize_right_with_panes_to_the_left_aligned_top_and_bottom_with_current_p
MOVE_FOCUS,
SPLIT_VERTICALLY,
RESIZE_RIGHT,
- QUIT
+ QUIT,
]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -361,7 +383,11 @@ pub fn resize_right_with_panes_to_the_right_aligned_top_and_bottom_with_current_
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -418,7 +444,11 @@ pub fn resize_right_with_panes_to_the_left_aligned_top_and_bottom_with_panes_abo
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -477,7 +507,11 @@ pub fn resize_right_with_panes_to_the_right_aligned_top_and_bottom_with_panes_ab
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
diff --git a/src/tests/integration/resize_up.rs b/src/tests/integration/resize_up.rs
index 4b0fcc45..d4e75376 100644
--- a/src/tests/integration/resize_up.rs
+++ b/src/tests/integration/resize_up.rs
@@ -1,20 +1,15 @@
-use ::nix::pty::Winsize;
use ::insta::assert_snapshot;
+use ::nix::pty::Winsize;
-use crate::{start, Opt};
-use crate::tests::fakes::{FakeInputOutput};
+use crate::tests::fakes::FakeInputOutput;
use crate::tests::utils::get_output_frame_snapshots;
+use crate::{start, Opt};
use crate::tests::utils::commands::{
- SPLIT_HORIZONTALLY,
- SPLIT_VERTICALLY,
- RESIZE_UP,
- MOVE_FOCUS,
- RESIZE_LEFT,
- QUIT,
+ MOVE_FOCUS, QUIT, RESIZE_LEFT, RESIZE_UP, SPLIT_HORIZONTALLY, SPLIT_VERTICALLY,
};
-fn get_fake_os_input (fake_win_size: &Winsize) -> FakeInputOutput {
+fn get_fake_os_input(fake_win_size: &Winsize) -> FakeInputOutput {
FakeInputOutput::new(fake_win_size.clone())
}
@@ -35,14 +30,14 @@ pub fn resize_up_with_pane_above() {
ws_ypixel: 0,
};
let mut fake_input_output = get_fake_os_input(&fake_win_size);
- fake_input_output.add_terminal_input(&[
- SPLIT_HORIZONTALLY,
- RESIZE_UP,
- QUIT
- ]);
+ fake_input_output.add_terminal_input(&[SPLIT_HORIZONTALLY, RESIZE_UP, QUIT]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -66,15 +61,14 @@ pub fn resize_up_with_pane_below() {
ws_ypixel: 0,
};
let mut fake_input_output = get_fake_os_input(&fake_win_size);
- fake_input_output.add_terminal_input(&[
- SPLIT_HORIZONTALLY,
- MOVE_FOCUS,
- RESIZE_UP,
- QUIT,
- ]);
+ fake_input_output.add_terminal_input(&[SPLIT_HORIZONTALLY, MOVE_FOCUS, RESIZE_UP, QUIT]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -104,13 +98,18 @@ pub fn resize_up_with_panes_above_and_below() {
fake_input_output.add_terminal_input(&[
SPLIT_HORIZONTALLY,
SPLIT_HORIZONTALLY,
- MOVE_FOCUS, MOVE_FOCUS,
+ MOVE_FOCUS,
+ MOVE_FOCUS,
RESIZE_UP,
QUIT,
]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -146,7 +145,11 @@ pub fn resize_up_with_multiple_panes_above() {
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -183,7 +186,11 @@ pub fn resize_up_with_panes_above_aligned_left_with_current_pane() {
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -216,12 +223,16 @@ pub fn resize_up_with_panes_below_aligned_left_with_current_pane() {
MOVE_FOCUS,
MOVE_FOCUS,
RESIZE_UP,
- QUIT
+ QUIT,
]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -257,7 +268,11 @@ pub fn resize_up_with_panes_above_aligned_right_with_current_pane() {
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -294,7 +309,11 @@ pub fn resize_up_with_panes_below_aligned_right_with_current_pane() {
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -334,7 +353,11 @@ pub fn resize_up_with_panes_above_aligned_left_and_right_with_current_pane() {
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -371,12 +394,16 @@ pub fn resize_up_with_panes_below_aligned_left_and_right_with_current_pane() {
MOVE_FOCUS,
MOVE_FOCUS,
RESIZE_UP,
- QUIT
+ QUIT,
]);
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -433,7 +460,11 @@ pub fn resize_up_with_panes_above_aligned_left_and_right_with_panes_to_the_left_
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
@@ -492,7 +523,11 @@ pub fn resize_up_with_panes_below_aligned_left_and_right_with_to_the_left_and_ri
start(Box::new(fake_input_output.clone()), Opt::default());
- let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
+ let output_frames = fake_input_output
+ .stdout_writer
+ .output_frames
+ .lock()
+ .unwrap();
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
for snapshot in snapshots {
assert_snapshot!(snapshot);
diff --git a/src/tests/mod.rs b/src/tests/mod.rs
index 5bf3c0ea..6e07c96d 100644
--- a/src/tests/mod.rs
+++ b/src/tests/mod.rs
@@ -1,5 +1,5 @@
+pub mod fakes;
pub mod integration;
pub mod possible_tty_inputs;
pub mod tty_inputs;
-pub mod fakes;
pub mod utils;
diff --git a/src/tests/possible_tty_inputs.rs b/src/tests/possible_tty_inputs.rs
index dd6e1e7d..6730591f 100644
--- a/src/tests/possible_tty_inputs.rs
+++ b/src/tests/possible_tty_inputs.rs
@@ -1,7 +1,10 @@
+use crate::tests::tty_inputs::{
+ COL_10, COL_121, COL_14, COL_15, COL_19, COL_20, COL_24, COL_29, COL_30, COL_34, COL_39,
+ COL_40, COL_50, COL_60, COL_70, COL_90,
+};
use std::collections::HashMap;
use std::fs;
use std::path::PathBuf;
-use crate::tests::tty_inputs::{COL_10, COL_60, COL_14, COL_15, COL_19, COL_20, COL_24, COL_29, COL_30, COL_34, COL_39, COL_40, COL_50, COL_70, COL_90, COL_121};
#[derive(Clone, Debug)]
pub struct Bytes {
@@ -13,7 +16,7 @@ impl Bytes {
pub fn new() -> Self {
Bytes {
content: vec![],
- read_position: 0
+ read_position: 0,
}
}
pub fn from_file_in_fixtures(file_name: &str) -> Self {
@@ -22,10 +25,11 @@ impl Bytes {
path_to_file.push("tests");
path_to_file.push("fixtures");
path_to_file.push(file_name);
- let content = fs::read(path_to_file).expect(&format!("could not read fixture {:?}", &file_name));
+ let content =
+ fs::read(path_to_file).expect(&format!("could not read fixture {:?}", &file_name));
Bytes {
content,
- read_position: 0
+ read_position: 0,
}
}
pub fn content_from_str(mut self, content: &[&'static str]) -> Self {
@@ -43,7 +47,8 @@ impl Bytes {
}
}
-pub fn get_possible_tty_inputs () -> HashMap<u16, Bytes> { // the key is the column count for this terminal input
+pub fn get_possible_tty_inputs() -> HashMap<u16, Bytes> {
+ // the key is the column count for this terminal input
let mut possible_inputs = HashMap::new();
let col_10_bytes = Bytes::new().content_from_str(&COL_10);
let col_14_bytes = Bytes::new().content_from_str(&COL_14);
diff --git a/src/tests/utils.rs b/src/tests/utils.rs
index a416a177..de19ff4f 100644
--- a/src/tests/utils.rs
+++ b/src/tests/utils.rs
@@ -1,5 +1,5 @@
-use ::nix::pty::Winsize;
use crate::terminal_pane::TerminalPane;
+use ::nix::pty::Winsize;
pub fn get_output_frame_snapshots(output_frames: &[Vec<u8>], win_size: &Winsize) -> Vec<String> {
let mut vte_parser = vte::Parser::new();
@@ -48,5 +48,6 @@ pub mod commands {
pub const SCROLL_UP: [u8; 10] = [27, 91, 53, 94, 0, 0, 0, 0, 0, 0]; // ctrl-PgUp
pub const SCROLL_DOWN: [u8; 10] = [27, 91, 54, 94, 0, 0, 0, 0, 0, 0]; // ctrl-PgDown
pub const CLOSE_FOCUSED_PANE: [u8; 10] = [24, 0, 0, 0, 0, 0, 0, 0, 0, 0]; // ctrl-x
- pub const TOGGLE_ACTIVE_TERMINAL_FULLSCREEN: [u8; 10] = [5, 0, 0, 0, 0, 0, 0, 0, 0, 0]; // ctrl-e
+ pub const TOGGLE_ACTIVE_TERMINAL_FULLSCREEN: [u8; 10] = [5, 0, 0, 0, 0, 0, 0, 0, 0, 0];
+ // ctrl-e
}