feat(statusbar): max status bar height (#156)

This commit is contained in:
Aram Drevekenin 2021-01-28 18:29:44 +01:00 committed by GitHub
parent 5191dfe416
commit dd56deb2d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 43 additions and 0 deletions

Binary file not shown.

View File

@ -167,6 +167,7 @@ pub enum ScreenContext {
CloseFocusedPane,
ToggleActiveTerminalFullscreen,
SetSelectable,
SetMaxHeight,
ClosePane,
ApplyLayout,
NewTab,
@ -202,6 +203,7 @@ impl From<&ScreenInstruction> for ScreenContext {
ScreenContext::ToggleActiveTerminalFullscreen
}
ScreenInstruction::SetSelectable(..) => ScreenContext::SetSelectable,
ScreenInstruction::SetMaxHeight(..) => ScreenContext::SetMaxHeight,
ScreenInstruction::ClosePane(_) => ScreenContext::ClosePane,
ScreenInstruction::ApplyLayout(_) => ScreenContext::ApplyLayout,
ScreenInstruction::NewTab(_) => ScreenContext::NewTab,

View File

@ -406,6 +406,12 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs) {
// FIXME: Is this needed?
screen.render();
}
ScreenInstruction::SetMaxHeight(id, max_height) => {
screen
.get_active_tab_mut()
.unwrap()
.set_pane_max_height(id, max_height);
}
ScreenInstruction::ClosePane(id) => {
screen.get_active_tab_mut().unwrap().close_pane(id);
screen.render();

View File

@ -13,6 +13,7 @@ pub struct PluginPane {
pub position_and_size: PositionAndSize,
pub position_and_size_override: Option<PositionAndSize>,
pub send_plugin_instructions: SenderWithContext<PluginInstruction>,
pub max_height: Option<usize>,
}
impl PluginPane {
@ -28,6 +29,7 @@ impl PluginPane {
position_and_size,
position_and_size_override: None,
send_plugin_instructions,
max_height: None,
}
}
}
@ -100,6 +102,9 @@ impl Pane for PluginPane {
fn set_selectable(&mut self, selectable: bool) {
self.selectable = selectable;
}
fn set_max_height(&mut self, max_height: usize) {
self.max_height = Some(max_height);
}
fn render(&mut self) -> Option<String> {
// if self.should_render {
if true {
@ -172,4 +177,7 @@ impl Pane for PluginPane {
fn clear_scroll(&mut self) {
unimplemented!()
}
fn max_height(&self) -> Option<usize> {
self.max_height
}
}

View File

@ -46,6 +46,7 @@ pub struct TerminalPane {
pub position_and_size: PositionAndSize,
pub position_and_size_override: Option<PositionAndSize>,
pub cursor_key_mode: bool, // DECCKM - when set, cursor keys should send ANSI direction codes (eg. "OD") instead of the arrow keys (eg. "")
pub max_height: Option<usize>,
pending_styles: CharacterStyles,
clear_viewport_before_rendering: bool,
}
@ -177,6 +178,12 @@ impl Pane for TerminalPane {
fn set_selectable(&mut self, selectable: bool) {
self.selectable = selectable;
}
fn set_max_height(&mut self, max_height: usize) {
self.max_height = Some(max_height);
}
fn max_height(&self) -> Option<usize> {
self.max_height
}
fn render(&mut self) -> Option<String> {
// if self.should_render {
if true {
@ -309,6 +316,7 @@ impl TerminalPane {
position_and_size_override: None,
cursor_key_mode: false,
clear_viewport_before_rendering: false,
max_height: None,
}
}
pub fn mark_for_rerender(&mut self) {

View File

@ -43,6 +43,7 @@ pub enum ScreenInstruction {
CloseFocusedPane,
ToggleActiveTerminalFullscreen,
SetSelectable(PaneId, bool),
SetMaxHeight(PaneId, usize),
ClosePane(PaneId),
ApplyLayout((Layout, Vec<RawFd>)),
NewTab(RawFd),

View File

@ -86,6 +86,7 @@ pub trait Pane {
fn set_should_render(&mut self, should_render: bool);
fn selectable(&self) -> bool;
fn set_selectable(&mut self, selectable: bool);
fn set_max_height(&mut self, max_height: usize);
fn render(&mut self) -> Option<String>;
fn pid(&self) -> PaneId;
fn reduce_height_down(&mut self, count: usize);
@ -1894,6 +1895,11 @@ impl Tab {
}
}
}
pub fn set_pane_max_height(&mut self, id: PaneId, max_height: usize) {
if let Some(pane) = self.panes.get_mut(&id) {
pane.set_max_height(max_height);
}
}
pub fn close_pane(&mut self, id: PaneId) {
if self.panes.get(&id).is_some() {
self.close_pane_without_rerender(id);

View File

@ -35,6 +35,7 @@ pub fn mosaic_imports(store: &Store, plugin_env: &PluginEnv) -> ImportObject {
imports! {
"mosaic" => {
"host_open_file" => Function::new_native_with_env(store, plugin_env.clone(), host_open_file),
"host_set_max_height" => Function::new_native_with_env(store, plugin_env.clone(), host_set_max_height),
"host_set_selectable" => Function::new_native_with_env(store, plugin_env.clone(), host_set_selectable),
"host_get_help" => Function::new_native_with_env(store, plugin_env.clone(), host_get_help),
}
@ -62,6 +63,17 @@ fn host_set_selectable(plugin_env: &PluginEnv, selectable: i32) {
.unwrap()
}
fn host_set_max_height(plugin_env: &PluginEnv, max_height: i32) {
let max_height = max_height as usize;
plugin_env
.send_screen_instructions
.send(ScreenInstruction::SetMaxHeight(
PaneId::Plugin(plugin_env.plugin_id),
max_height,
))
.unwrap()
}
fn host_get_help(plugin_env: &PluginEnv) {
let (state_tx, state_rx) = channel();
// FIXME: If I changed the application so that threads were sent the termination