wip: active pane color, able to type / not able to type inside a pane distinction
This commit is contained in:
parent
3dd776834a
commit
59d2da54ca
2 changed files with 49 additions and 31 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
use crate::tab::Pane;
|
use crate::common::utils::logging::debug_log_to_file;
|
||||||
|
use crate::{common::input::handler::InputMode, tab::Pane};
|
||||||
use ansi_term::Colour::{self, Fixed};
|
use ansi_term::Colour::{self, Fixed};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
|
@ -18,6 +19,13 @@ pub mod boundary_type {
|
||||||
pub const CROSS: &str = "┼";
|
pub const CROSS: &str = "┼";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod colors {
|
||||||
|
use ansi_term::Colour::{self, Fixed};
|
||||||
|
pub const WHITE: Colour = Fixed(255);
|
||||||
|
pub const GREEN: Colour = Fixed(154);
|
||||||
|
pub const GRAY: Colour = Fixed(238);
|
||||||
|
}
|
||||||
|
|
||||||
pub type BoundaryType = &'static str; // easy way to refer to boundary_type above
|
pub type BoundaryType = &'static str; // easy way to refer to boundary_type above
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
|
|
@ -34,18 +42,13 @@ impl BoundarySymbol {
|
||||||
boundary_type,
|
boundary_type,
|
||||||
invisible: false,
|
invisible: false,
|
||||||
should_be_colored,
|
should_be_colored,
|
||||||
color: Fixed(245),
|
color: colors::GRAY,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn invisible(mut self) -> Self {
|
pub fn invisible(mut self) -> Self {
|
||||||
self.invisible = true;
|
self.invisible = true;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
pub fn color(mut self, color: Colour) -> Self {
|
|
||||||
self.color = color;
|
|
||||||
self.should_be_colored = true;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for BoundarySymbol {
|
impl Display for BoundarySymbol {
|
||||||
|
|
@ -63,14 +66,23 @@ impl Display for BoundarySymbol {
|
||||||
fn combine_symbols(
|
fn combine_symbols(
|
||||||
current_symbol: BoundarySymbol,
|
current_symbol: BoundarySymbol,
|
||||||
next_symbol: BoundarySymbol,
|
next_symbol: BoundarySymbol,
|
||||||
|
input_mode: InputMode,
|
||||||
) -> Option<BoundarySymbol> {
|
) -> Option<BoundarySymbol> {
|
||||||
let invisible = current_symbol.invisible || next_symbol.invisible;
|
let invisible = current_symbol.invisible || next_symbol.invisible;
|
||||||
let should_be_colored = current_symbol.should_be_colored || next_symbol.should_be_colored;
|
let should_be_colored = current_symbol.should_be_colored || next_symbol.should_be_colored;
|
||||||
let current_symbol = current_symbol.boundary_type;
|
let current_symbol = current_symbol.boundary_type;
|
||||||
let next_symbol = next_symbol.boundary_type;
|
let next_symbol = next_symbol.boundary_type;
|
||||||
let color = match should_be_colored {
|
let color = match should_be_colored {
|
||||||
true => Fixed(154),
|
true => match input_mode {
|
||||||
false => Fixed(245),
|
InputMode::Normal => colors::GREEN,
|
||||||
|
InputMode::Locked => colors::GREEN,
|
||||||
|
InputMode::Pane => colors::WHITE,
|
||||||
|
InputMode::RenameTab => colors::WHITE,
|
||||||
|
InputMode::Resize => colors::WHITE,
|
||||||
|
InputMode::Scroll => colors::WHITE,
|
||||||
|
InputMode::Tab => colors::WHITE,
|
||||||
|
},
|
||||||
|
false => colors::WHITE,
|
||||||
};
|
};
|
||||||
match (current_symbol, next_symbol) {
|
match (current_symbol, next_symbol) {
|
||||||
(boundary_type::TOP_RIGHT, boundary_type::TOP_RIGHT) => {
|
(boundary_type::TOP_RIGHT, boundary_type::TOP_RIGHT) => {
|
||||||
|
|
@ -740,11 +752,12 @@ fn combine_symbols(
|
||||||
fn find_next_symbol(
|
fn find_next_symbol(
|
||||||
first_symbol: BoundarySymbol,
|
first_symbol: BoundarySymbol,
|
||||||
second_symbol: BoundarySymbol,
|
second_symbol: BoundarySymbol,
|
||||||
|
input_mode: InputMode,
|
||||||
) -> Option<BoundarySymbol> {
|
) -> Option<BoundarySymbol> {
|
||||||
if let Some(symbol) = combine_symbols(first_symbol, second_symbol) {
|
if let Some(symbol) = combine_symbols(first_symbol, second_symbol, input_mode) {
|
||||||
Some(symbol)
|
Some(symbol)
|
||||||
} else {
|
} else {
|
||||||
combine_symbols(second_symbol, first_symbol)
|
combine_symbols(second_symbol, first_symbol, input_mode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -826,7 +839,7 @@ impl Boundaries {
|
||||||
boundary_characters: HashMap::new(),
|
boundary_characters: HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn add_rect(&mut self, rect: &dyn Pane, should_be_colored: bool) {
|
pub fn add_rect(&mut self, rect: &dyn Pane, should_be_colored: bool, input_mode: InputMode) {
|
||||||
if rect.x() > 0 {
|
if rect.x() > 0 {
|
||||||
let boundary_x_coords = rect.x() - 1;
|
let boundary_x_coords = rect.x() - 1;
|
||||||
let first_row_coordinates = self.rect_right_boundary_row_start(rect);
|
let first_row_coordinates = self.rect_right_boundary_row_start(rect);
|
||||||
|
|
@ -843,13 +856,12 @@ impl Boundaries {
|
||||||
if rect.invisible_borders() {
|
if rect.invisible_borders() {
|
||||||
symbol_to_add = symbol_to_add.invisible();
|
symbol_to_add = symbol_to_add.invisible();
|
||||||
}
|
}
|
||||||
if rect.colored_borders() {
|
|
||||||
symbol_to_add = symbol_to_add.color(Fixed(154));
|
|
||||||
}
|
|
||||||
let next_symbol = self
|
let next_symbol = self
|
||||||
.boundary_characters
|
.boundary_characters
|
||||||
.remove(&coordinates)
|
.remove(&coordinates)
|
||||||
.and_then(|current_symbol| find_next_symbol(current_symbol, symbol_to_add))
|
.and_then(|current_symbol| {
|
||||||
|
find_next_symbol(current_symbol, symbol_to_add, input_mode)
|
||||||
|
})
|
||||||
.unwrap_or(symbol_to_add);
|
.unwrap_or(symbol_to_add);
|
||||||
self.boundary_characters.insert(coordinates, next_symbol);
|
self.boundary_characters.insert(coordinates, next_symbol);
|
||||||
}
|
}
|
||||||
|
|
@ -870,13 +882,12 @@ impl Boundaries {
|
||||||
if rect.invisible_borders() {
|
if rect.invisible_borders() {
|
||||||
symbol_to_add = symbol_to_add.invisible();
|
symbol_to_add = symbol_to_add.invisible();
|
||||||
}
|
}
|
||||||
if rect.colored_borders() {
|
|
||||||
symbol_to_add = symbol_to_add.color(Fixed(154));
|
|
||||||
}
|
|
||||||
let next_symbol = self
|
let next_symbol = self
|
||||||
.boundary_characters
|
.boundary_characters
|
||||||
.remove(&coordinates)
|
.remove(&coordinates)
|
||||||
.and_then(|current_symbol| find_next_symbol(current_symbol, symbol_to_add))
|
.and_then(|current_symbol| {
|
||||||
|
find_next_symbol(current_symbol, symbol_to_add, input_mode)
|
||||||
|
})
|
||||||
.unwrap_or(symbol_to_add);
|
.unwrap_or(symbol_to_add);
|
||||||
self.boundary_characters.insert(coordinates, next_symbol);
|
self.boundary_characters.insert(coordinates, next_symbol);
|
||||||
}
|
}
|
||||||
|
|
@ -898,13 +909,12 @@ impl Boundaries {
|
||||||
if rect.invisible_borders() {
|
if rect.invisible_borders() {
|
||||||
symbol_to_add = symbol_to_add.invisible();
|
symbol_to_add = symbol_to_add.invisible();
|
||||||
}
|
}
|
||||||
if rect.colored_borders() {
|
|
||||||
symbol_to_add = symbol_to_add.color(Fixed(154));
|
|
||||||
}
|
|
||||||
let next_symbol = self
|
let next_symbol = self
|
||||||
.boundary_characters
|
.boundary_characters
|
||||||
.remove(&coordinates)
|
.remove(&coordinates)
|
||||||
.and_then(|current_symbol| find_next_symbol(current_symbol, symbol_to_add))
|
.and_then(|current_symbol| {
|
||||||
|
find_next_symbol(current_symbol, symbol_to_add, input_mode)
|
||||||
|
})
|
||||||
.unwrap_or(symbol_to_add);
|
.unwrap_or(symbol_to_add);
|
||||||
self.boundary_characters.insert(coordinates, next_symbol);
|
self.boundary_characters.insert(coordinates, next_symbol);
|
||||||
}
|
}
|
||||||
|
|
@ -925,13 +935,12 @@ impl Boundaries {
|
||||||
if rect.invisible_borders() {
|
if rect.invisible_borders() {
|
||||||
symbol_to_add = symbol_to_add.invisible();
|
symbol_to_add = symbol_to_add.invisible();
|
||||||
}
|
}
|
||||||
if rect.colored_borders() {
|
|
||||||
symbol_to_add = symbol_to_add.color(Fixed(154));
|
|
||||||
}
|
|
||||||
let next_symbol = self
|
let next_symbol = self
|
||||||
.boundary_characters
|
.boundary_characters
|
||||||
.remove(&coordinates)
|
.remove(&coordinates)
|
||||||
.and_then(|current_symbol| find_next_symbol(current_symbol, symbol_to_add))
|
.and_then(|current_symbol| {
|
||||||
|
find_next_symbol(current_symbol, symbol_to_add, input_mode)
|
||||||
|
})
|
||||||
.unwrap_or(symbol_to_add);
|
.unwrap_or(symbol_to_add);
|
||||||
self.boundary_characters.insert(coordinates, next_symbol);
|
self.boundary_characters.insert(coordinates, next_symbol);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
//! `Tab`s holds multiple panes. It tracks their coordinates (x/y) and size,
|
//! `Tab`s holds multiple panes. It tracks their coordinates (x/y) and size,
|
||||||
//! as well as how they should be resized
|
//! as well as how they should be resized
|
||||||
|
|
||||||
use crate::common::{AppInstruction, SenderWithContext};
|
use crate::common::input::handler::get_help;
|
||||||
|
use crate::common::{input::handler::InputMode, AppInstruction, AppState, SenderWithContext};
|
||||||
use crate::layout::Layout;
|
use crate::layout::Layout;
|
||||||
use crate::panes::{PaneId, PositionAndSize, TerminalPane};
|
use crate::panes::{PaneId, PositionAndSize, TerminalPane};
|
||||||
use crate::pty_bus::{PtyInstruction, VteEvent};
|
use crate::pty_bus::{PtyInstruction, VteEvent};
|
||||||
|
|
@ -21,7 +22,13 @@ const MIN_TERMINAL_HEIGHT: usize = 2;
|
||||||
const MIN_TERMINAL_WIDTH: usize = 4;
|
const MIN_TERMINAL_WIDTH: usize = 4;
|
||||||
|
|
||||||
type BorderAndPaneIds = (usize, Vec<PaneId>);
|
type BorderAndPaneIds = (usize, Vec<PaneId>);
|
||||||
|
fn get_state(app_tx: &SenderWithContext<AppInstruction>) -> InputMode {
|
||||||
|
let (state_tx, state_rx) = channel();
|
||||||
|
|
||||||
|
drop(app_tx.send(AppInstruction::GetState(state_tx)));
|
||||||
|
let state = state_rx.recv().unwrap();
|
||||||
|
state.input_mode
|
||||||
|
}
|
||||||
fn split_vertically_with_gap(rect: &PositionAndSize) -> (PositionAndSize, PositionAndSize) {
|
fn split_vertically_with_gap(rect: &PositionAndSize) -> (PositionAndSize, PositionAndSize) {
|
||||||
let width_of_each_half = (rect.columns - 1) / 2;
|
let width_of_each_half = (rect.columns - 1) / 2;
|
||||||
let mut first_rect = *rect;
|
let mut first_rect = *rect;
|
||||||
|
|
@ -631,6 +638,7 @@ impl Tab {
|
||||||
pub fn toggle_fullscreen_is_active(&mut self) {
|
pub fn toggle_fullscreen_is_active(&mut self) {
|
||||||
self.fullscreen_is_active = !self.fullscreen_is_active;
|
self.fullscreen_is_active = !self.fullscreen_is_active;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render(&mut self) {
|
pub fn render(&mut self) {
|
||||||
if self.active_terminal.is_none() {
|
if self.active_terminal.is_none() {
|
||||||
// we might not have an active terminal if we closed the last pane
|
// we might not have an active terminal if we closed the last pane
|
||||||
|
|
@ -643,14 +651,15 @@ impl Tab {
|
||||||
self.full_screen_ws.rows as u16,
|
self.full_screen_ws.rows as u16,
|
||||||
);
|
);
|
||||||
let hide_cursor = "\u{1b}[?25l";
|
let hide_cursor = "\u{1b}[?25l";
|
||||||
|
let input_mode = get_state(&self.send_app_instructions);
|
||||||
stdout
|
stdout
|
||||||
.write_all(&hide_cursor.as_bytes())
|
.write_all(&hide_cursor.as_bytes())
|
||||||
.expect("cannot write to stdout");
|
.expect("cannot write to stdout");
|
||||||
for (kind, terminal) in self.panes.iter_mut() {
|
for (kind, terminal) in self.panes.iter_mut() {
|
||||||
if !self.panes_to_hide.contains(&terminal.pid()) {
|
if !self.panes_to_hide.contains(&terminal.pid()) {
|
||||||
match self.active_terminal.unwrap() == terminal.pid() {
|
match self.active_terminal.unwrap() == terminal.pid() {
|
||||||
true => boundaries.add_rect(terminal.as_ref(), true),
|
true => boundaries.add_rect(terminal.as_ref(), true, input_mode),
|
||||||
false => boundaries.add_rect(terminal.as_ref(), false),
|
false => boundaries.add_rect(terminal.as_ref(), false, input_mode),
|
||||||
}
|
}
|
||||||
if let Some(vte_output) = terminal.render() {
|
if let Some(vte_output) = terminal.render() {
|
||||||
let vte_output = if let PaneId::Terminal(_) = kind {
|
let vte_output = if let PaneId::Terminal(_) = kind {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue