feat: add rustfmt, update action workflow to check for formatting (#45)

This commit is contained in:
Denis Maximov 2020-11-14 19:59:37 +02:00 committed by GitHub
parent b66dffe5cf
commit a2914066bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 2058 additions and 1097 deletions

View file

@ -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

0
rustfmt.toml Normal file
View file

View file

@ -3,7 +3,11 @@ use std::collections::HashMap;
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(┼)
@ -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,7 +258,9 @@ 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);
@ -204,7 +270,12 @@ impl Boundaries {
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
}
@ -215,21 +286,37 @@ impl Boundaries {
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
}
}
}

View file

@ -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) {
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,25 +165,26 @@ 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
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);
}
@ -208,8 +235,8 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: Opt) {
}
}
}
}
}).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();
}

View file

@ -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),
};
}
@ -68,7 +61,11 @@ pub fn set_terminal_size_using_fd(fd: RawFd, columns: u16, rows: u16) {
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,7 +93,7 @@ fn handle_command_exit(mut child: Child) {
}
_ => {}
}
};
}
}
}
@ -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 {
}
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 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");
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,8 +211,7 @@ 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()
}
@ -219,7 +220,5 @@ impl Clone for Box<dyn OsApi>
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 }
}

View file

@ -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;
@ -29,7 +29,11 @@ impl ReadFromPid {
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,7 +91,8 @@ 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
Hook(Vec<i64>, Vec<u8>, bool, char), // params, intermediates, ignore, char
@ -111,45 +116,57 @@ impl VteEventSender {
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();

File diff suppressed because it is too large Load diff

View file

@ -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::*;

View file

@ -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) {
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| {
.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,14 +140,14 @@ 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) {
@ -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);
@ -267,17 +288,20 @@ impl Scroll {
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,15 +502,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 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());
}
}
}
@ -461,7 +523,6 @@ impl Scroll {
} else {
self.viewport_bottom_offset = Some(count);
}
}
pub fn move_viewport_down(&mut self, count: usize) {
if let Some(current_offset) = self.viewport_bottom_offset.as_mut() {

View file

@ -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,20 +151,24 @@ 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) {
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);
@ -176,7 +180,7 @@ impl CharacterStyles {
self.bold = Some(AnsiCode::Reset);
self.dim = Some(AnsiCode::Reset);
self.italic = Some(AnsiCode::Reset);
return Some(*new_styles)
return Some(*new_styles);
};
if self.foreground != new_styles.foreground {
@ -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,130 +364,118 @@ impl Display for CharacterStyles {
}
if let Some(ansi_code) = self.strike {
match ansi_code {
AnsiCode::Code((param1, param2)) => {
match (param1, param2) {
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) {
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) {
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) {
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) {
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) {
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 => {
write!(f, "\u{1b}[22m\u{1b}[24m")?;
// 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,39 +484,35 @@ impl Display for CharacterStyles {
// otherwise
if let Some(ansi_code) = self.underline {
match ansi_code {
AnsiCode::Code((param1, param2)) => {
match (param1, param2) {
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) {
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 => {
if let Some(bold) = self.bold {
@ -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) {
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")?;
},
}
_ => {}
}
};

View file

@ -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 {
@ -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,42 +142,26 @@ 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) {
@ -188,7 +169,8 @@ impl TerminalPane {
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)
@ -228,7 +212,8 @@ impl TerminalPane {
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) {
@ -279,7 +264,11 @@ 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)
} 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
} 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 {

View file

@ -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 {
@ -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;
}

View file

@ -1,22 +1,13 @@
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 {
FakeInputOutput::new(fake_win_size.clone())
@ -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);
@ -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);
@ -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);
@ -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);

View file

@ -1,19 +1,13 @@
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 {
@ -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);

View file

@ -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;
@ -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);
@ -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);

View file

@ -1,7 +1,7 @@
pub mod basic;
pub mod compatibility;
pub mod resize_right;
pub mod resize_left;
pub mod resize_up;
pub mod resize_down;
pub mod close_pane;
pub mod compatibility;
pub mod resize_down;
pub mod resize_left;
pub mod resize_right;
pub mod resize_up;

View file

@ -1,17 +1,12 @@
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 {
@ -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);

View file

@ -1,17 +1,12 @@
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 {
@ -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);

View file

@ -1,17 +1,12 @@
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 {
@ -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);

View file

@ -1,17 +1,12 @@
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 {
@ -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);

View file

@ -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;

View file

@ -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);

View file

@ -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
}