The RawFd has been slain...

This commit is contained in:
Brooks J Rady 2021-01-06 16:41:02 +00:00
parent 931384d42f
commit fc2205c415
7 changed files with 481 additions and 484 deletions

View file

@ -23,6 +23,7 @@ use std::thread;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use structopt::StructOpt; use structopt::StructOpt;
use terminal_pane::PaneId;
use crate::command_is_executing::CommandIsExecuting; use crate::command_is_executing::CommandIsExecuting;
use crate::errors::{AppContext, ContextType, ErrorContext, PtyContext, ScreenContext}; use crate::errors::{AppContext, ContextType, ErrorContext, PtyContext, ScreenContext};
@ -222,21 +223,21 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: Opt) {
let pid = pty_bus.spawn_terminal(file_to_open); let pid = pty_bus.spawn_terminal(file_to_open);
pty_bus pty_bus
.send_screen_instructions .send_screen_instructions
.send(ScreenInstruction::NewPane(pid)) .send(ScreenInstruction::NewPane(PaneId::Terminal(pid)))
.unwrap(); .unwrap();
} }
PtyInstruction::SpawnTerminalVertically(file_to_open) => { PtyInstruction::SpawnTerminalVertically(file_to_open) => {
let pid = pty_bus.spawn_terminal(file_to_open); let pid = pty_bus.spawn_terminal(file_to_open);
pty_bus pty_bus
.send_screen_instructions .send_screen_instructions
.send(ScreenInstruction::VerticalSplit(pid)) .send(ScreenInstruction::VerticalSplit(PaneId::Terminal(pid)))
.unwrap(); .unwrap();
} }
PtyInstruction::SpawnTerminalHorizontally(file_to_open) => { PtyInstruction::SpawnTerminalHorizontally(file_to_open) => {
let pid = pty_bus.spawn_terminal(file_to_open); let pid = pty_bus.spawn_terminal(file_to_open);
pty_bus pty_bus
.send_screen_instructions .send_screen_instructions
.send(ScreenInstruction::HorizontalSplit(pid)) .send(ScreenInstruction::HorizontalSplit(PaneId::Terminal(pid)))
.unwrap(); .unwrap();
} }
PtyInstruction::NewTab => { PtyInstruction::NewTab => {
@ -378,7 +379,7 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: Opt) {
screen screen
.get_active_tab_mut() .get_active_tab_mut()
.unwrap() .unwrap()
.toggle_active_terminal_fullscreen(); .toggle_active_pane_fullscreen();
} }
ScreenInstruction::NewTab(pane_id) => { ScreenInstruction::NewTab(pane_id) => {
screen.new_tab(pane_id); screen.new_tab(pane_id);

View file

@ -9,10 +9,13 @@ use ::std::time::{Duration, Instant};
use ::vte; use ::vte;
use std::path::PathBuf; use std::path::PathBuf;
use crate::errors::{ContextType, ErrorContext};
use crate::layout::Layout; use crate::layout::Layout;
use crate::os_input_output::OsApi; use crate::os_input_output::OsApi;
use crate::utils::logging::debug_to_file; use crate::utils::logging::debug_to_file;
use crate::{
errors::{ContextType, ErrorContext},
terminal_pane::PaneId,
};
use crate::{ScreenInstruction, SenderWithContext, OPENCALLS}; use crate::{ScreenInstruction, SenderWithContext, OPENCALLS};
pub struct ReadFromPid { pub struct ReadFromPid {
@ -148,8 +151,8 @@ pub enum PtyInstruction {
SpawnTerminalVertically(Option<PathBuf>), SpawnTerminalVertically(Option<PathBuf>),
SpawnTerminalHorizontally(Option<PathBuf>), SpawnTerminalHorizontally(Option<PathBuf>),
NewTab, NewTab,
ClosePane(RawFd), ClosePane(PaneId),
CloseTab(Vec<RawFd>), CloseTab(Vec<PaneId>),
Quit, Quit,
} }
@ -231,7 +234,7 @@ fn stream_terminal_bytes(
// we read everything, rather than hanging until there is new data // 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 // a better solution would be to fix the test fakes, but this will do for now
send_screen_instructions send_screen_instructions
.send(ScreenInstruction::ClosePane(pid)) .send(ScreenInstruction::ClosePane(PaneId::Terminal(pid)))
.unwrap(); .unwrap();
} }
}); });
@ -287,11 +290,13 @@ impl PtyBus {
); );
} }
} }
pub fn close_pane(&mut self, id: RawFd) { pub fn close_pane(&mut self, id: PaneId) {
let child_pid = self.id_to_child_pid.get(&id).unwrap(); if let PaneId::Terminal(id) = id {
self.os_input.kill(*child_pid).unwrap(); let child_pid = self.id_to_child_pid.get(&id).unwrap();
self.os_input.kill(*child_pid).unwrap();
}
} }
pub fn close_tab(&mut self, ids: Vec<RawFd>) { pub fn close_tab(&mut self, ids: Vec<PaneId>) {
ids.iter().for_each(|id| self.close_pane(*id)); ids.iter().for_each(|id| self.close_pane(*id));
} }
} }

View file

@ -2,12 +2,12 @@ use std::collections::BTreeMap;
use std::os::unix::io::RawFd; use std::os::unix::io::RawFd;
use std::sync::mpsc::Receiver; use std::sync::mpsc::Receiver;
use crate::layout::Layout;
use crate::os_input_output::OsApi; use crate::os_input_output::OsApi;
use crate::pty_bus::{PtyInstruction, VteEvent}; use crate::pty_bus::{PtyInstruction, VteEvent};
use crate::tab::Tab; use crate::tab::Tab;
use crate::terminal_pane::PositionAndSize; use crate::terminal_pane::PositionAndSize;
use crate::{errors::ErrorContext, wasm_vm::PluginInstruction}; use crate::{errors::ErrorContext, wasm_vm::PluginInstruction};
use crate::{layout::Layout, terminal_pane::PaneId};
use crate::{AppInstruction, SenderWithContext}; use crate::{AppInstruction, SenderWithContext};
/* /*
@ -23,9 +23,9 @@ use crate::{AppInstruction, SenderWithContext};
pub enum ScreenInstruction { pub enum ScreenInstruction {
Pty(RawFd, VteEvent), Pty(RawFd, VteEvent),
Render, Render,
NewPane(RawFd), NewPane(PaneId),
HorizontalSplit(RawFd), HorizontalSplit(PaneId),
VerticalSplit(RawFd), VerticalSplit(PaneId),
WriteCharacter(Vec<u8>), WriteCharacter(Vec<u8>),
ResizeLeft, ResizeLeft,
ResizeRight, ResizeRight,
@ -42,7 +42,7 @@ pub enum ScreenInstruction {
ClearScroll, ClearScroll,
CloseFocusedPane, CloseFocusedPane,
ToggleActiveTerminalFullscreen, ToggleActiveTerminalFullscreen,
ClosePane(RawFd), ClosePane(PaneId),
ApplyLayout((Layout, Vec<RawFd>)), ApplyLayout((Layout, Vec<RawFd>)),
NewTab(RawFd), NewTab(RawFd),
SwitchTabNext, SwitchTabNext,
@ -94,7 +94,7 @@ impl Screen {
self.send_plugin_instructions.clone(), self.send_plugin_instructions.clone(),
self.send_app_instructions.clone(), self.send_app_instructions.clone(),
self.max_panes, self.max_panes,
Some(pane_id), Some(PaneId::Terminal(pane_id)),
); );
self.active_tab_index = Some(tab_index); self.active_tab_index = Some(tab_index);
self.tabs.insert(tab_index, tab); self.tabs.insert(tab_index, tab);
@ -139,7 +139,7 @@ impl Screen {
self.switch_tab_prev(); self.switch_tab_prev();
} }
let mut active_tab = self.tabs.remove(&active_tab_index).unwrap(); let mut active_tab = self.tabs.remove(&active_tab_index).unwrap();
let pane_ids = active_tab.get_terminal_pane_ids(); let pane_ids = active_tab.get_pane_ids();
self.send_pty_instructions self.send_pty_instructions
.send(PtyInstruction::CloseTab(pane_ids)) .send(PtyInstruction::CloseTab(pane_ids))
.unwrap(); .unwrap();

File diff suppressed because it is too large Load diff

View file

@ -1,12 +1,10 @@
#![allow(clippy::clippy::if_same_then_else)] #![allow(clippy::clippy::if_same_then_else)]
use crate::{ use crate::{pty_bus::VteEvent, tab::Pane, wasm_vm::PluginInstruction, SenderWithContext};
pty_bus::VteEvent, tab::Pane, utils::shared::*, wasm_vm::PluginInstruction, SenderWithContext,
};
use std::{iter, os::unix::prelude::RawFd, sync::mpsc::channel}; use std::{sync::mpsc::channel, unimplemented};
use crate::terminal_pane::PositionAndSize; use crate::terminal_pane::{PaneId, PositionAndSize};
pub struct PluginPane { pub struct PluginPane {
pub pid: u32, pub pid: u32,
@ -75,14 +73,14 @@ impl Pane for PluginPane {
self.position_and_size_override = Some(position_and_size_override); self.position_and_size_override = Some(position_and_size_override);
self.should_render = true; self.should_render = true;
} }
fn handle_event(&mut self, event: VteEvent) { fn handle_event(&mut self, _event: VteEvent) {
todo!() unimplemented!()
} }
fn cursor_coordinates(&self) -> Option<(usize, usize)> { fn cursor_coordinates(&self) -> Option<(usize, usize)> {
None None
} }
fn adjust_input_to_terminal(&self, input_bytes: Vec<u8>) -> Vec<u8> { fn adjust_input_to_terminal(&self, _input_bytes: Vec<u8>) -> Vec<u8> {
todo!() // FIXME: Shouldn't need this implmented? unimplemented!() // FIXME: Shouldn't need this implmented?
} }
fn position_and_size_override(&self) -> Option<PositionAndSize> { fn position_and_size_override(&self) -> Option<PositionAndSize> {
@ -118,10 +116,8 @@ impl Pane for PluginPane {
None None
} }
} }
// FIXME: Really shouldn't be in this trait... fn pid(&self) -> PaneId {
fn pid(&self) -> RawFd { PaneId::Plugin(self.pid)
// FIXME: This looks like a really bad idea!
100 + self.pid as RawFd
} }
fn reduce_height_down(&mut self, count: usize) { fn reduce_height_down(&mut self, count: usize) {
self.position_and_size.y += count; self.position_and_size.y += count;
@ -159,13 +155,13 @@ impl Pane for PluginPane {
self.position_and_size.columns += count; self.position_and_size.columns += count;
self.should_render = true; self.should_render = true;
} }
fn scroll_up(&mut self, count: usize) { fn scroll_up(&mut self, _count: usize) {
todo!() unimplemented!()
} }
fn scroll_down(&mut self, count: usize) { fn scroll_down(&mut self, _count: usize) {
todo!() unimplemented!()
} }
fn clear_scroll(&mut self) { fn clear_scroll(&mut self) {
todo!() unimplemented!()
} }
} }

View file

@ -1,15 +1,22 @@
#![allow(clippy::clippy::if_same_then_else)] #![allow(clippy::clippy::if_same_then_else)]
use crate::{tab::Pane, utils::shared::ansi_len}; use crate::tab::Pane;
use ::nix::pty::Winsize; use ::nix::pty::Winsize;
use ::std::os::unix::io::RawFd; use ::std::os::unix::io::RawFd;
use ::vte::Perform; use ::vte::Perform;
use crate::terminal_pane::terminal_character::{CharacterStyles, NamedColor, TerminalCharacter}; use crate::terminal_pane::terminal_character::{CharacterStyles, TerminalCharacter};
use crate::terminal_pane::Scroll; use crate::terminal_pane::Scroll;
use crate::utils::logging::debug_log_to_file; use crate::utils::logging::debug_log_to_file;
use crate::VteEvent; use crate::VteEvent;
#[derive(PartialEq, Eq, Ord, PartialOrd, Hash, Clone, Copy, Debug)]
pub enum PaneId {
Terminal(RawFd),
Plugin(u32), // FIXME: Drop the trait object, make this a wrapper for the struct?
BuiltIn(u32),
}
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct PositionAndSize { pub struct PositionAndSize {
pub x: usize, pub x: usize,
@ -200,8 +207,8 @@ impl Pane for TerminalPane {
None None
} }
} }
fn pid(&self) -> RawFd { fn pid(&self) -> PaneId {
self.pid PaneId::Terminal(self.pid)
} }
fn reduce_height_down(&mut self, count: usize) { fn reduce_height_down(&mut self, count: usize) {
self.position_and_size.y += count; self.position_and_size.y += count;
@ -279,7 +286,8 @@ impl TerminalPane {
pub fn mark_for_rerender(&mut self) { pub fn mark_for_rerender(&mut self) {
self.should_render = true; self.should_render = true;
} }
pub fn handle_event(&mut self, event: VteEvent) { // FIXME: Should this be removed?
pub fn _handle_event(&mut self, event: VteEvent) {
match event { match event {
VteEvent::Print(c) => { VteEvent::Print(c) => {
self.print(c); self.print(c);

View file

@ -4,7 +4,10 @@ use strip_ansi_escapes::strip;
// FIXME: Should this be an extension trait? Or here at all? // FIXME: Should this be an extension trait? Or here at all?
pub fn ansi_len(s: &str) -> usize { pub fn ansi_len(s: &str) -> usize {
from_utf8(&strip(s.as_bytes()).unwrap()).unwrap().chars().count() from_utf8(&strip(s.as_bytes()).unwrap())
.unwrap()
.chars()
.count()
} }
pub fn pad_to_size(s: &str, rows: usize, columns: usize) -> String { pub fn pad_to_size(s: &str, rows: usize, columns: usize) -> String {