Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyshew committed Dec 7, 2024
1 parent 87f39e5 commit 4fe26b8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
4 changes: 2 additions & 2 deletions crates/turborepo-ui/src/tui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -872,10 +872,10 @@ fn view<W>(app: &mut App<W>, f: &mut Frame) {
f.render_widget(&pane_to_render, pane);

if app.showing_help_popup {
let area = popup_area(app.size);
let area = popup_area(*f.buffer_mut().area());
let area = area.intersection(*f.buffer_mut().area());
f.render_widget(Clear, area); // Clears background underneath popup
f.render_widget(popup(app.size), area);
f.render_widget(popup(area), area);
}
}

Expand Down
1 change: 0 additions & 1 deletion crates/turborepo-ui/src/tui/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ fn translate_key_event(options: InputOptions, key_event: KeyEvent) -> Option<Eve
KeyCode::Char('n') if key_event.modifiers == KeyModifiers::CONTROL => {
Some(Event::ScrollDown)
}
KeyCode::Char('h') => Some(Event::ToggleSidebar),
KeyCode::Char('m') => Some(Event::ToggleHelpPopup),
KeyCode::Up | KeyCode::Char('k') => Some(Event::Up),
KeyCode::Down | KeyCode::Char('j') => Some(Event::Down),
Expand Down
27 changes: 12 additions & 15 deletions crates/turborepo-ui/src/tui/popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ use std::cmp::min;
use ratatui::{
layout::{Constraint, Flex, Layout, Rect},
text::Line,
widgets::{Block, List, ListItem, Padding, Paragraph},
widgets::{Block, List, ListItem, Padding},
};

use super::size::SizeInfo;

const BIND_LIST_ITEMS: [&str; 11] = [
"m - Toggle this help popup",
"↑ or j - Select previous task",
Expand All @@ -22,9 +20,9 @@ const BIND_LIST_ITEMS: [&str; 11] = [
"Ctrl+p - Scroll logs down",
];

pub fn popup_area(area: SizeInfo) -> Rect {
let screen_width = area.task_list_width() + area.pane_cols();
let screen_height = area.pane_rows();
pub fn popup_area(area: Rect) -> Rect {
let screen_width = area.width;
let screen_height = area.height;

let popup_width = BIND_LIST_ITEMS
.iter()
Expand All @@ -41,6 +39,7 @@ pub fn popup_area(area: SizeInfo) -> Rect {

let vertical = Layout::vertical([Constraint::Percentage(100)]).flex(Flex::Center);
let horizontal = Layout::horizontal([Constraint::Percentage(100)]).flex(Flex::Center);

let [area] = vertical.areas(Rect {
x,
y,
Expand All @@ -51,23 +50,21 @@ pub fn popup_area(area: SizeInfo) -> Rect {
area
}

pub fn popup(area: SizeInfo) -> List<'static> {
let available_height = area.pane_rows().saturating_sub(4);
pub fn popup(area: Rect) -> List<'static> {
let available_height = area.height.saturating_sub(4) as usize;

let items: Vec<ListItem> = BIND_LIST_ITEMS
.iter()
.take(available_height as usize)
.take(available_height)
.map(|item| ListItem::new(Line::from(*item)))
.collect();

let title_bottom = if area.pane_rows().saturating_sub(4) < BIND_LIST_ITEMS.len() as u16 {
let binds_not_visible = BIND_LIST_ITEMS
.len()
.saturating_sub(area.pane_rows().saturating_sub(4) as usize);
let title_bottom = if available_height < BIND_LIST_ITEMS.len() {
let binds_not_visible = BIND_LIST_ITEMS.len().saturating_sub(available_height);

let pluralize = if binds_not_visible > 1 { "s" } else { "" };
let message = format!(
"{} more bind{}. Make your terminal taller.",
" {} more bind{}. Make your terminal taller. ",
binds_not_visible, pluralize
);
Line::from(message)
Expand All @@ -77,7 +74,7 @@ pub fn popup(area: SizeInfo) -> List<'static> {

let outer = Block::bordered()
.title(" Keybinds ")
.title_bottom(format!("{title_bottom}").to_string())
.title_bottom(title_bottom.to_string())
.padding(Padding::uniform(1));

List::new(items).block(outer)
Expand Down

0 comments on commit 4fe26b8

Please sign in to comment.