Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui): draw ui properly on terminal start #323

Merged
merged 2 commits into from
Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions src/client/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,26 @@ fn split_space_to_parts_vertically(

// First fit in the parameterized sizes
for size in sizes {
let columns = match size {
let (columns, max_columns) = match size {
Some(SplitSize::Percent(percent)) => {
(max_width as f32 * (percent as f32 / 100.0)) as usize
((max_width as f32 * (percent as f32 / 100.0)) as usize, None)
} // TODO: round properly
Some(SplitSize::Fixed(size)) => size as usize,
Some(SplitSize::Fixed(size)) => (size as usize, Some(size as usize)),
None => {
parts_to_grow.push(current_x_position);
1 // This is grown later on
(
1, // This is grown later on
None,
)
}
};
split_parts.push(PositionAndSize {
x: current_x_position,
y: space_to_split.y,
columns,
rows: space_to_split.rows,
max_columns,
..Default::default()
});
current_width += columns;
current_x_position += columns + 1; // 1 for gap
Expand Down Expand Up @@ -80,21 +85,27 @@ fn split_space_to_parts_horizontally(
let mut parts_to_grow = Vec::new();

for size in sizes {
let rows = match size {
Some(SplitSize::Percent(percent)) => {
(max_height as f32 * (percent as f32 / 100.0)) as usize
} // TODO: round properly
Some(SplitSize::Fixed(size)) => size as usize,
let (rows, max_rows) = match size {
Some(SplitSize::Percent(percent)) => (
(max_height as f32 * (percent as f32 / 100.0)) as usize,
None,
), // TODO: round properly
Some(SplitSize::Fixed(size)) => (size as usize, Some(size as usize)),
None => {
parts_to_grow.push(current_y_position);
1 // This is grown later on
(
1, // This is grown later on
None,
)
}
};
split_parts.push(PositionAndSize {
x: space_to_split.x,
y: current_y_position,
columns: space_to_split.columns,
rows,
max_rows,
..Default::default()
});
current_height += rows;
current_y_position += rows + 1; // 1 for gap
Expand Down
9 changes: 9 additions & 0 deletions src/client/panes/plugin_pane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub struct PluginPane {
pub position_and_size_override: Option<PositionAndSize>,
pub send_plugin_instructions: SenderWithContext<PluginInstruction>,
pub max_height: Option<usize>,
pub max_width: Option<usize>,
}

impl PluginPane {
Expand All @@ -30,6 +31,7 @@ impl PluginPane {
position_and_size_override: None,
send_plugin_instructions,
max_height: None,
max_width: None,
}
}
}
Expand Down Expand Up @@ -73,6 +75,7 @@ impl Pane for PluginPane {
y,
rows: size.rows,
columns: size.columns,
..Default::default()
};
self.position_and_size_override = Some(position_and_size_override);
self.should_render = true;
Expand Down Expand Up @@ -108,6 +111,9 @@ impl Pane for PluginPane {
fn set_max_height(&mut self, max_height: usize) {
self.max_height = Some(max_height);
}
fn set_max_width(&mut self, max_width: usize) {
self.max_width = Some(max_width);
}
fn render(&mut self) -> Option<String> {
// if self.should_render {
if true {
Expand Down Expand Up @@ -195,6 +201,9 @@ impl Pane for PluginPane {
fn max_height(&self) -> Option<usize> {
self.max_height
}
fn max_width(&self) -> Option<usize> {
self.max_width
}
fn invisible_borders(&self) -> bool {
self.invisible_borders
}
Expand Down
11 changes: 11 additions & 0 deletions src/client/panes/terminal_pane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub struct PositionAndSize {
pub y: usize,
pub rows: usize,
pub columns: usize,
pub max_rows: Option<usize>,
pub max_columns: Option<usize>,
}

impl From<Winsize> for PositionAndSize {
Expand All @@ -42,6 +44,7 @@ pub struct TerminalPane {
pub position_and_size: PositionAndSize,
pub position_and_size_override: Option<PositionAndSize>,
pub max_height: Option<usize>,
pub max_width: Option<usize>,
vte_parser: vte::Parser,
}

Expand Down Expand Up @@ -73,6 +76,7 @@ impl Pane for TerminalPane {
y,
rows: size.rows,
columns: size.columns,
..Default::default()
};
self.position_and_size_override = Some(position_and_size_override);
self.reflow_lines();
Expand Down Expand Up @@ -147,12 +151,18 @@ impl Pane for TerminalPane {
fn set_max_height(&mut self, max_height: usize) {
self.max_height = Some(max_height);
}
fn set_max_width(&mut self, max_width: usize) {
self.max_width = Some(max_width);
}
fn set_invisible_borders(&mut self, _invisible_borders: bool) {
unimplemented!();
}
fn max_height(&self) -> Option<usize> {
self.max_height
}
fn max_width(&self) -> Option<usize> {
self.max_width
}
fn render(&mut self) -> Option<String> {
// FIXME:
// the below conditional is commented out because it causes several bugs:
Expand Down Expand Up @@ -284,6 +294,7 @@ impl TerminalPane {
position_and_size,
position_and_size_override: None,
max_height: None,
max_width: None,
vte_parser: vte::Parser::new(),
}
}
Expand Down
20 changes: 19 additions & 1 deletion src/client/tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ pub trait Pane {
fn set_selectable(&mut self, selectable: bool);
fn set_invisible_borders(&mut self, invisible_borders: bool);
fn set_max_height(&mut self, max_height: usize);
fn set_max_width(&mut self, max_width: usize);
fn render(&mut self) -> Option<String>;
fn pid(&self) -> PaneId;
fn reduce_height_down(&mut self, count: usize);
Expand Down Expand Up @@ -170,6 +171,7 @@ pub trait Pane {
y: self.y(),
columns: self.columns(),
rows: self.rows(),
..Default::default()
}
}
fn can_increase_height_by(&self, increase_by: usize) -> bool {
Expand Down Expand Up @@ -260,6 +262,7 @@ impl Tab {
y: 0,
rows: self.full_screen_ws.rows,
columns: self.full_screen_ws.columns,
..Default::default()
};
self.panes_to_hide.clear();
let positions_in_layout = layout.position_panes_in_space(&free_space);
Expand All @@ -270,6 +273,12 @@ impl Tab {
match positions_and_size.next() {
Some((_, position_and_size)) => {
terminal_pane.reset_size_and_position_override();
if let Some(max_rows) = position_and_size.max_rows {
terminal_pane.set_max_height(max_rows);
}
if let Some(max_columns) = position_and_size.max_columns {
terminal_pane.set_max_width(max_columns);
}
terminal_pane.change_pos_and_size(&position_and_size);
self.os_api.set_terminal_size_using_fd(
*pid,
Expand All @@ -294,11 +303,17 @@ impl Tab {
.send(PluginInstruction::Load(pid_tx, plugin.clone()))
.unwrap();
let pid = pid_rx.recv().unwrap();
let new_plugin = PluginPane::new(
let mut new_plugin = PluginPane::new(
pid,
*position_and_size,
self.send_plugin_instructions.clone(),
);
if let Some(max_rows) = position_and_size.max_rows {
new_plugin.set_max_height(max_rows);
}
if let Some(max_columns) = position_and_size.max_columns {
new_plugin.set_max_width(max_columns);
}
self.panes.insert(PaneId::Plugin(pid), Box::new(new_plugin));
// Send an initial mode update to the newly loaded plugin only!
self.send_plugin_instructions
Expand Down Expand Up @@ -381,6 +396,7 @@ impl Tab {
columns: terminal_to_split.columns(),
x: terminal_to_split.x(),
y: terminal_to_split.y(),
..Default::default()
};
if terminal_to_split.rows() * CURSOR_HEIGHT_WIDTH_RATIO > terminal_to_split.columns()
&& terminal_to_split.rows() > terminal_to_split.min_height() * 2
Expand Down Expand Up @@ -459,6 +475,7 @@ impl Tab {
y: active_pane.y(),
rows: active_pane.rows(),
columns: active_pane.columns(),
..Default::default()
};
let (top_winsize, bottom_winsize) = split_horizontally_with_gap(&terminal_ws);

Expand Down Expand Up @@ -515,6 +532,7 @@ impl Tab {
y: active_pane.y(),
rows: active_pane.rows(),
columns: active_pane.columns(),
..Default::default()
};
let (left_winsize, right_winsize) = split_vertically_with_gap(&terminal_ws);

Expand Down
13 changes: 13 additions & 0 deletions src/tests/integration/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub fn starts_with_one_terminal() {
rows: 20,
x: 0,
y: 0,
..Default::default()
};
let mut fake_input_output = get_fake_os_input(&fake_win_size);
fake_input_output.add_terminal_input(&[&QUIT]);
Expand All @@ -44,6 +45,7 @@ pub fn split_terminals_vertically() {
rows: 20,
x: 0,
y: 0,
..Default::default()
};
let mut fake_input_output = get_fake_os_input(&fake_win_size);
fake_input_output.add_terminal_input(&[&PANE_MODE, &SPLIT_RIGHT_IN_PANE_MODE, &QUIT]);
Expand All @@ -66,6 +68,7 @@ pub fn split_terminals_horizontally() {
rows: 20,
x: 0,
y: 0,
..Default::default()
};
let mut fake_input_output = get_fake_os_input(&fake_win_size);
fake_input_output.add_terminal_input(&[&PANE_MODE, &SPLIT_DOWN_IN_PANE_MODE, &QUIT]);
Expand All @@ -89,6 +92,7 @@ pub fn split_largest_terminal() {
rows: 20,
x: 0,
y: 0,
..Default::default()
};
let mut fake_input_output = get_fake_os_input(&fake_win_size);
fake_input_output.add_terminal_input(&[
Expand Down Expand Up @@ -117,6 +121,7 @@ pub fn cannot_split_terminals_vertically_when_active_terminal_is_too_small() {
rows: 20,
x: 0,
y: 0,
..Default::default()
};
let mut fake_input_output = get_fake_os_input(&fake_win_size);
fake_input_output.add_terminal_input(&[&PANE_MODE, &SPLIT_RIGHT_IN_PANE_MODE, &QUIT]);
Expand All @@ -139,6 +144,7 @@ pub fn cannot_split_terminals_horizontally_when_active_terminal_is_too_small() {
rows: 4,
x: 0,
y: 0,
..Default::default()
};
let mut fake_input_output = get_fake_os_input(&fake_win_size);
fake_input_output.add_terminal_input(&[&PANE_MODE, &SPLIT_DOWN_IN_PANE_MODE, &QUIT]);
Expand All @@ -161,6 +167,7 @@ pub fn cannot_split_largest_terminal_when_there_is_no_room() {
rows: 4,
x: 0,
y: 0,
..Default::default()
};
let mut fake_input_output = get_fake_os_input(&fake_win_size);
fake_input_output.add_terminal_input(&[&PANE_MODE, &SPAWN_TERMINAL_IN_PANE_MODE, &QUIT]);
Expand All @@ -183,6 +190,7 @@ pub fn scrolling_up_inside_a_pane() {
rows: 20,
x: 0,
y: 0,
..Default::default()
};
let mut fake_input_output = get_fake_os_input(&fake_win_size);
fake_input_output.add_terminal_input(&[
Expand Down Expand Up @@ -213,6 +221,7 @@ pub fn scrolling_down_inside_a_pane() {
rows: 20,
x: 0,
y: 0,
..Default::default()
};
let mut fake_input_output = get_fake_os_input(&fake_win_size);
fake_input_output.add_terminal_input(&[
Expand Down Expand Up @@ -245,6 +254,7 @@ pub fn scrolling_page_up_inside_a_pane() {
rows: 20,
x: 0,
y: 0,
..Default::default()
};
let mut fake_input_output = get_fake_os_input(&fake_win_size);
fake_input_output.add_terminal_input(&[
Expand Down Expand Up @@ -274,6 +284,7 @@ pub fn scrolling_page_down_inside_a_pane() {
rows: 20,
x: 0,
y: 0,
..Default::default()
};
let mut fake_input_output = get_fake_os_input(&fake_win_size);
fake_input_output.add_terminal_input(&[
Expand Down Expand Up @@ -308,6 +319,7 @@ pub fn max_panes() {
rows: 20,
x: 0,
y: 0,
..Default::default()
};
let mut fake_input_output = get_fake_os_input(&fake_win_size);
fake_input_output.add_terminal_input(&[
Expand Down Expand Up @@ -339,6 +351,7 @@ pub fn toggle_focused_pane_fullscreen() {
rows: 20,
x: 0,
y: 0,
..Default::default()
};
let mut fake_input_output = get_fake_os_input(&fake_win_size);
fake_input_output.add_terminal_input(&[
Expand Down
Loading