Acutually pass combined position and size
This commit is contained in:
parent
e19f674a21
commit
d25df96eef
3 changed files with 41 additions and 83 deletions
106
src/tab.rs
106
src/tab.rs
|
|
@ -30,6 +30,7 @@ fn split_vertically_with_gap(rect: &PositionAndSize) -> (PositionAndSize, Positi
|
||||||
} else {
|
} else {
|
||||||
first_rect.columns = width_of_each_half;
|
first_rect.columns = width_of_each_half;
|
||||||
}
|
}
|
||||||
|
second_rect.x = first_rect.x + first_rect.columns + 1;
|
||||||
second_rect.columns = width_of_each_half;
|
second_rect.columns = width_of_each_half;
|
||||||
(first_rect, second_rect)
|
(first_rect, second_rect)
|
||||||
}
|
}
|
||||||
|
|
@ -43,6 +44,7 @@ fn split_horizontally_with_gap(rect: &PositionAndSize) -> (PositionAndSize, Posi
|
||||||
} else {
|
} else {
|
||||||
first_rect.rows = height_of_each_half;
|
first_rect.rows = height_of_each_half;
|
||||||
}
|
}
|
||||||
|
second_rect.y = first_rect.y + first_rect.rows + 1;
|
||||||
second_rect.rows = height_of_each_half;
|
second_rect.rows = height_of_each_half;
|
||||||
(first_rect, second_rect)
|
(first_rect, second_rect)
|
||||||
}
|
}
|
||||||
|
|
@ -152,7 +154,7 @@ impl Tab {
|
||||||
pane_id: Option<RawFd>,
|
pane_id: Option<RawFd>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let panes = if let Some(pid) = pane_id {
|
let panes = if let Some(pid) = pane_id {
|
||||||
let new_terminal = TerminalPane::new(pid, *full_screen_ws, 0, 0);
|
let new_terminal = TerminalPane::new(pid, *full_screen_ws);
|
||||||
os_api.set_terminal_size_using_fd(
|
os_api.set_terminal_size_using_fd(
|
||||||
new_terminal.pid,
|
new_terminal.pid,
|
||||||
new_terminal.columns() as u16,
|
new_terminal.columns() as u16,
|
||||||
|
|
@ -233,13 +235,7 @@ impl Tab {
|
||||||
} else {
|
} else {
|
||||||
// there are still panes left to fill, use the pids we received in this method
|
// there are still panes left to fill, use the pids we received in this method
|
||||||
let pid = new_pids.next().unwrap(); // if this crashes it means we got less pids than there are panes in this layout
|
let pid = new_pids.next().unwrap(); // if this crashes it means we got less pids than there are panes in this layout
|
||||||
let mut new_terminal = TerminalPane::new(
|
let mut new_terminal = TerminalPane::new(*pid, *position_and_size);
|
||||||
*pid,
|
|
||||||
self.full_screen_ws,
|
|
||||||
position_and_size.x,
|
|
||||||
position_and_size.y,
|
|
||||||
);
|
|
||||||
new_terminal.change_pos_and_size(position_and_size);
|
|
||||||
self.os_api.set_terminal_size_using_fd(
|
self.os_api.set_terminal_size_using_fd(
|
||||||
new_terminal.pid,
|
new_terminal.pid,
|
||||||
new_terminal.columns() as u16,
|
new_terminal.columns() as u16,
|
||||||
|
|
@ -273,9 +269,7 @@ impl Tab {
|
||||||
self.toggle_active_terminal_fullscreen();
|
self.toggle_active_terminal_fullscreen();
|
||||||
}
|
}
|
||||||
if !self.has_terminal_panes() {
|
if !self.has_terminal_panes() {
|
||||||
let x = 0;
|
let new_terminal = TerminalPane::new(pid, self.full_screen_ws);
|
||||||
let y = 0;
|
|
||||||
let new_terminal = TerminalPane::new(pid, self.full_screen_ws, x, y);
|
|
||||||
self.os_api.set_terminal_size_using_fd(
|
self.os_api.set_terminal_size_using_fd(
|
||||||
new_terminal.pid,
|
new_terminal.pid,
|
||||||
new_terminal.columns() as u16,
|
new_terminal.columns() as u16,
|
||||||
|
|
@ -312,9 +306,7 @@ impl Tab {
|
||||||
};
|
};
|
||||||
if terminal_to_split.rows() * CURSOR_HEIGHT_WIDTH_RATIO > terminal_to_split.columns() {
|
if terminal_to_split.rows() * CURSOR_HEIGHT_WIDTH_RATIO > terminal_to_split.columns() {
|
||||||
let (top_winsize, bottom_winsize) = split_horizontally_with_gap(&terminal_ws);
|
let (top_winsize, bottom_winsize) = split_horizontally_with_gap(&terminal_ws);
|
||||||
let bottom_half_y = terminal_ws.y + top_winsize.rows + 1;
|
let new_terminal = TerminalPane::new(pid, bottom_winsize);
|
||||||
let new_terminal =
|
|
||||||
TerminalPane::new(pid, bottom_winsize, terminal_ws.x, bottom_half_y);
|
|
||||||
self.os_api.set_terminal_size_using_fd(
|
self.os_api.set_terminal_size_using_fd(
|
||||||
new_terminal.pid,
|
new_terminal.pid,
|
||||||
bottom_winsize.columns as u16,
|
bottom_winsize.columns as u16,
|
||||||
|
|
@ -331,9 +323,7 @@ impl Tab {
|
||||||
self.active_terminal = Some(pid);
|
self.active_terminal = Some(pid);
|
||||||
} else {
|
} else {
|
||||||
let (left_winszie, right_winsize) = split_vertically_with_gap(&terminal_ws);
|
let (left_winszie, right_winsize) = split_vertically_with_gap(&terminal_ws);
|
||||||
let right_side_x = (terminal_ws.x + left_winszie.columns + 1) as usize;
|
let new_terminal = TerminalPane::new(pid, right_winsize);
|
||||||
let new_terminal =
|
|
||||||
TerminalPane::new(pid, right_winsize, right_side_x, terminal_ws.y);
|
|
||||||
self.os_api.set_terminal_size_using_fd(
|
self.os_api.set_terminal_size_using_fd(
|
||||||
new_terminal.pid,
|
new_terminal.pid,
|
||||||
right_winsize.columns as u16,
|
right_winsize.columns as u16,
|
||||||
|
|
@ -358,9 +348,7 @@ impl Tab {
|
||||||
self.toggle_active_terminal_fullscreen();
|
self.toggle_active_terminal_fullscreen();
|
||||||
}
|
}
|
||||||
if !self.has_terminal_panes() {
|
if !self.has_terminal_panes() {
|
||||||
let x = 0;
|
let new_terminal = TerminalPane::new(pid, self.full_screen_ws);
|
||||||
let y = 0;
|
|
||||||
let new_terminal = TerminalPane::new(pid, self.full_screen_ws, x, y);
|
|
||||||
self.os_api.set_terminal_size_using_fd(
|
self.os_api.set_terminal_size_using_fd(
|
||||||
new_terminal.pid,
|
new_terminal.pid,
|
||||||
new_terminal.columns() as u16,
|
new_terminal.columns() as u16,
|
||||||
|
|
@ -371,37 +359,26 @@ impl Tab {
|
||||||
self.active_terminal = Some(pid);
|
self.active_terminal = Some(pid);
|
||||||
} else {
|
} else {
|
||||||
// TODO: check minimum size of active terminal
|
// TODO: check minimum size of active terminal
|
||||||
let (active_terminal_ws, active_terminal_x, active_terminal_y) = {
|
let active_terminal_id = &self.get_active_terminal_id().unwrap();
|
||||||
let active_terminal = &self.get_active_terminal().unwrap();
|
let active_terminal = self
|
||||||
(
|
.panes
|
||||||
PositionAndSize {
|
.get_mut(&PaneKind::Terminal(*active_terminal_id))
|
||||||
rows: active_terminal.rows(),
|
.unwrap();
|
||||||
columns: active_terminal.columns(),
|
let terminal_ws = PositionAndSize {
|
||||||
x: 0,
|
x: active_terminal.x(),
|
||||||
y: 0,
|
y: active_terminal.y(),
|
||||||
},
|
rows: active_terminal.rows(),
|
||||||
active_terminal.x(),
|
columns: active_terminal.columns(),
|
||||||
active_terminal.y(),
|
|
||||||
)
|
|
||||||
};
|
};
|
||||||
let (top_winsize, bottom_winsize) = split_horizontally_with_gap(&active_terminal_ws);
|
let (top_winsize, bottom_winsize) = split_horizontally_with_gap(&terminal_ws);
|
||||||
let bottom_half_y = active_terminal_y + top_winsize.rows + 1;
|
let new_terminal = TerminalPane::new(pid, bottom_winsize);
|
||||||
let new_terminal =
|
|
||||||
TerminalPane::new(pid, bottom_winsize, active_terminal_x, bottom_half_y);
|
|
||||||
self.os_api.set_terminal_size_using_fd(
|
self.os_api.set_terminal_size_using_fd(
|
||||||
new_terminal.pid,
|
new_terminal.pid,
|
||||||
bottom_winsize.columns as u16,
|
bottom_winsize.columns as u16,
|
||||||
bottom_winsize.rows as u16,
|
bottom_winsize.rows as u16,
|
||||||
);
|
);
|
||||||
|
|
||||||
{
|
active_terminal.change_pos_and_size(&top_winsize);
|
||||||
let active_terminal_id = &self.get_active_terminal_id().unwrap();
|
|
||||||
let active_terminal = &mut self
|
|
||||||
.panes
|
|
||||||
.get_mut(&PaneKind::Terminal(*active_terminal_id))
|
|
||||||
.unwrap();
|
|
||||||
active_terminal.change_pos_and_size(&top_winsize);
|
|
||||||
}
|
|
||||||
|
|
||||||
self.panes
|
self.panes
|
||||||
.insert(PaneKind::Terminal(pid), Box::new(new_terminal));
|
.insert(PaneKind::Terminal(pid), Box::new(new_terminal));
|
||||||
|
|
@ -421,9 +398,7 @@ impl Tab {
|
||||||
self.toggle_active_terminal_fullscreen();
|
self.toggle_active_terminal_fullscreen();
|
||||||
}
|
}
|
||||||
if !self.has_terminal_panes() {
|
if !self.has_terminal_panes() {
|
||||||
let x = 0;
|
let new_terminal = TerminalPane::new(pid, self.full_screen_ws);
|
||||||
let y = 0;
|
|
||||||
let new_terminal = TerminalPane::new(pid, self.full_screen_ws, x, y);
|
|
||||||
self.os_api.set_terminal_size_using_fd(
|
self.os_api.set_terminal_size_using_fd(
|
||||||
new_terminal.pid,
|
new_terminal.pid,
|
||||||
new_terminal.columns() as u16,
|
new_terminal.columns() as u16,
|
||||||
|
|
@ -434,37 +409,26 @@ impl Tab {
|
||||||
self.active_terminal = Some(pid);
|
self.active_terminal = Some(pid);
|
||||||
} else {
|
} else {
|
||||||
// TODO: check minimum size of active terminal
|
// TODO: check minimum size of active terminal
|
||||||
let (active_terminal_ws, active_terminal_x, active_terminal_y) = {
|
let active_terminal_id = &self.get_active_terminal_id().unwrap();
|
||||||
let active_terminal = &self.get_active_terminal().unwrap();
|
let active_terminal = self
|
||||||
(
|
.panes
|
||||||
PositionAndSize {
|
.get_mut(&PaneKind::Terminal(*active_terminal_id))
|
||||||
rows: active_terminal.rows(),
|
.unwrap();
|
||||||
columns: active_terminal.columns(),
|
let terminal_ws = PositionAndSize {
|
||||||
x: 0,
|
x: active_terminal.x(),
|
||||||
y: 0,
|
y: active_terminal.y(),
|
||||||
},
|
rows: active_terminal.rows(),
|
||||||
active_terminal.x(),
|
columns: active_terminal.columns(),
|
||||||
active_terminal.y(),
|
|
||||||
)
|
|
||||||
};
|
};
|
||||||
let (left_winszie, right_winsize) = split_vertically_with_gap(&active_terminal_ws);
|
let (left_winszie, right_winsize) = split_vertically_with_gap(&terminal_ws);
|
||||||
let right_side_x = active_terminal_x + left_winszie.columns + 1;
|
let new_terminal = TerminalPane::new(pid, right_winsize);
|
||||||
let new_terminal =
|
|
||||||
TerminalPane::new(pid, right_winsize, right_side_x, active_terminal_y);
|
|
||||||
self.os_api.set_terminal_size_using_fd(
|
self.os_api.set_terminal_size_using_fd(
|
||||||
new_terminal.pid,
|
new_terminal.pid,
|
||||||
right_winsize.columns as u16,
|
right_winsize.columns as u16,
|
||||||
right_winsize.rows as u16,
|
right_winsize.rows as u16,
|
||||||
);
|
);
|
||||||
|
|
||||||
{
|
active_terminal.change_pos_and_size(&left_winszie);
|
||||||
let active_terminal_id = &self.get_active_terminal_id().unwrap();
|
|
||||||
let active_terminal = &mut self
|
|
||||||
.panes
|
|
||||||
.get_mut(&PaneKind::Terminal(*active_terminal_id))
|
|
||||||
.unwrap();
|
|
||||||
active_terminal.change_pos_and_size(&left_winszie);
|
|
||||||
}
|
|
||||||
|
|
||||||
self.panes
|
self.panes
|
||||||
.insert(PaneKind::Terminal(pid), Box::new(new_terminal));
|
.insert(PaneKind::Terminal(pid), Box::new(new_terminal));
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,8 @@ impl Pane for TerminalPane {
|
||||||
self.mark_for_rerender();
|
self.mark_for_rerender();
|
||||||
}
|
}
|
||||||
fn change_pos_and_size(&mut self, position_and_size: &PositionAndSize) {
|
fn change_pos_and_size(&mut self, position_and_size: &PositionAndSize) {
|
||||||
self.position_and_size = *position_and_size;
|
self.position_and_size.columns = position_and_size.columns;
|
||||||
|
self.position_and_size.rows = position_and_size.rows;
|
||||||
self.reflow_lines();
|
self.reflow_lines();
|
||||||
self.mark_for_rerender();
|
self.mark_for_rerender();
|
||||||
}
|
}
|
||||||
|
|
@ -261,15 +262,10 @@ impl Pane for TerminalPane {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TerminalPane {
|
impl TerminalPane {
|
||||||
pub fn new(pid: RawFd, ws: PositionAndSize, x: usize, y: usize) -> TerminalPane {
|
pub fn new(pid: RawFd, position_and_size: PositionAndSize) -> TerminalPane {
|
||||||
let scroll = Scroll::new(ws.columns, ws.rows);
|
let scroll = Scroll::new(position_and_size.columns, position_and_size.rows);
|
||||||
let pending_styles = CharacterStyles::new();
|
let pending_styles = CharacterStyles::new();
|
||||||
let position_and_size = PositionAndSize {
|
|
||||||
x,
|
|
||||||
y,
|
|
||||||
rows: ws.rows,
|
|
||||||
columns: ws.columns,
|
|
||||||
};
|
|
||||||
TerminalPane {
|
TerminalPane {
|
||||||
pid,
|
pid,
|
||||||
scroll,
|
scroll,
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,7 @@ pub fn get_output_frame_snapshots(
|
||||||
) -> Vec<String> {
|
) -> Vec<String> {
|
||||||
let mut vte_parser = vte::Parser::new();
|
let mut vte_parser = vte::Parser::new();
|
||||||
let main_pid = 0;
|
let main_pid = 0;
|
||||||
let x = 0;
|
let mut terminal_output = TerminalPane::new(main_pid, *win_size);
|
||||||
let y = 0;
|
|
||||||
let mut terminal_output = TerminalPane::new(main_pid, *win_size, x, y);
|
|
||||||
|
|
||||||
let mut snapshots = vec![];
|
let mut snapshots = vec![];
|
||||||
for frame in output_frames.iter() {
|
for frame in output_frames.iter() {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue