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

feat(ui): Hide task list with h key. #9350

Merged
merged 4 commits into from
Oct 31, 2024
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
14 changes: 12 additions & 2 deletions crates/turborepo-ui/src/tui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub struct App<W> {
scroll: TableState,
selected_task_index: usize,
has_user_scrolled: bool,
has_sidebar: bool,
done: bool,
}

Expand Down Expand Up @@ -92,6 +93,7 @@ impl<W> App<W> {
tasks_by_status,
scroll: TableState::default().with_selected(selected_task_index),
selected_task_index,
has_sidebar: true,
has_user_scrolled: has_user_interacted,
}
}
Expand Down Expand Up @@ -771,6 +773,9 @@ fn update(
app.has_user_scrolled = true;
app.interact()?;
}
Event::ToggleSidebar => {
app.has_sidebar = !app.has_sidebar;
}
Event::Input { bytes } => {
app.forward_input(&bytes)?;
}
Expand Down Expand Up @@ -822,13 +827,18 @@ fn update(

fn view<W>(app: &mut App<W>, f: &mut Frame) {
let cols = app.size.pane_cols();
let horizontal = Layout::horizontal([Constraint::Fill(1), Constraint::Length(cols)]);
let horizontal = if app.has_sidebar {
Layout::horizontal([Constraint::Fill(1), Constraint::Length(cols)])
} else {
Layout::horizontal([Constraint::Max(0), Constraint::Length(cols)])
};
let [table, pane] = horizontal.areas(f.size());

let active_task = app.active_task().unwrap().to_string();

let output_logs = app.tasks.get(&active_task).unwrap();
let pane_to_render: TerminalPane<W> = TerminalPane::new(output_logs, &active_task, &app.focus);
let pane_to_render: TerminalPane<W> =
TerminalPane::new(output_logs, &active_task, &app.focus, app.has_sidebar);

let table_to_render = TaskTable::new(&app.tasks_by_status);

Expand Down
1 change: 1 addition & 0 deletions crates/turborepo-ui/src/tui/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub enum Event {
rows: u16,
cols: u16,
},
ToggleSidebar,
SearchEnter,
SearchExit {
restore_scroll: bool,
Expand Down
1 change: 1 addition & 0 deletions crates/turborepo-ui/src/tui/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ fn translate_key_event(options: InputOptions, key_event: KeyEvent) -> Option<Eve
restore_scroll: true,
})
}
KeyCode::Char('h') => Some(Event::ToggleSidebar),
KeyCode::Enter if matches!(options.focus, LayoutSections::Search { .. }) => {
Some(Event::SearchExit {
restore_scroll: false,
Expand Down
29 changes: 21 additions & 8 deletions crates/turborepo-ui/src/tui/pane.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ratatui::{
style::Style,
text::Line,
widgets::{Block, Borders, Widget},
widgets::{Block, Widget},
};
use tui_term::widget::PseudoTerminal;

Expand All @@ -10,23 +10,27 @@ use super::{app::LayoutSections, TerminalOutput};
const FOOTER_TEXT_ACTIVE: &str = "Press`Ctrl-Z` to stop interacting.";
const FOOTER_TEXT_INACTIVE: &str = "Press `Enter` to interact.";
const HAS_SELECTION: &str = "Press `c` to copy selection";
const TASK_LIST_HIDDEN: &str = "Press `h` to show task list.";

pub struct TerminalPane<'a, W> {
terminal_output: &'a TerminalOutput<W>,
task_name: &'a str,
section: &'a LayoutSections,
has_sidebar: bool,
}

impl<'a, W> TerminalPane<'a, W> {
pub fn new(
terminal_output: &'a TerminalOutput<W>,
task_name: &'a str,
section: &'a LayoutSections,
has_sidebar: bool,
) -> Self {
Self {
terminal_output,
section,
task_name,
has_sidebar,
}
}

Expand All @@ -35,15 +39,25 @@ impl<'a, W> TerminalPane<'a, W> {
}

fn footer(&self) -> Line {
let task_list_message = if !self.has_sidebar {
TASK_LIST_HIDDEN
} else {
""
};

match self.section {
LayoutSections::Pane if self.terminal_output.has_selection() => {
Line::from(format!("{FOOTER_TEXT_ACTIVE} {HAS_SELECTION}")).centered()
}
LayoutSections::Pane if self.terminal_output.has_selection() => Line::from(format!(
"{FOOTER_TEXT_ACTIVE} {task_list_message} {HAS_SELECTION}"
))
.centered(),
LayoutSections::Pane => Line::from(FOOTER_TEXT_ACTIVE.to_owned()).centered(),
LayoutSections::TaskList if self.terminal_output.has_selection() => {
Line::from(format!("{FOOTER_TEXT_INACTIVE} {HAS_SELECTION}")).centered()
LayoutSections::TaskList if self.terminal_output.has_selection() => Line::from(
format!("{FOOTER_TEXT_INACTIVE} {task_list_message} {HAS_SELECTION}"),
)
.centered(),
LayoutSections::TaskList => {
Line::from(format!("{FOOTER_TEXT_INACTIVE} {task_list_message}")).centered()
}
LayoutSections::TaskList => Line::from(FOOTER_TEXT_INACTIVE.to_owned()).centered(),
LayoutSections::Search { results, .. } => {
Line::from(format!("/ {}", results.query())).left_aligned()
}
Expand All @@ -58,7 +72,6 @@ impl<'a, W> Widget for &TerminalPane<'a, W> {
{
let screen = self.terminal_output.parser.screen();
let block = Block::default()
.borders(Borders::LEFT)
.title(self.terminal_output.title(self.task_name))
.title_bottom(self.footer())
.style(if self.highlight() {
Expand Down
8 changes: 5 additions & 3 deletions crates/turborepo-ui/src/tui/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ratatui::{
layout::{Constraint, Rect},
style::{Color, Style, Stylize},
text::Text,
widgets::{Cell, Row, StatefulWidget, Table, TableState},
widgets::{Block, Borders, Cell, Row, StatefulWidget, Table, TableState},
};

use super::{event::TaskResult, spinner::SpinnerState, task::TasksByStatus};
Expand All @@ -17,6 +17,7 @@ pub struct TaskTable<'b> {
}

const TASK_NAVIGATE_INSTRUCTIONS: &str = "↑ ↓ to navigate";
const HIDE_INSTRUCTIONS: &str = "h to hide";

impl<'b> TaskTable<'b> {
/// Construct a new table with all of the planned tasks
Expand Down Expand Up @@ -105,6 +106,7 @@ impl<'a> StatefulWidget for &'a TaskTable<'a> {
)
.highlight_style(Style::default().fg(Color::Yellow))
.column_spacing(0)
.block(Block::new().borders(Borders::RIGHT))
.header(
vec![format!("Tasks\n{bar}"), " \n─".to_owned()]
.into_iter()
Expand All @@ -114,13 +116,13 @@ impl<'a> StatefulWidget for &'a TaskTable<'a> {
)
.footer(
vec![
format!("{bar}\n{TASK_NAVIGATE_INSTRUCTIONS}"),
format!("{bar}\n{TASK_NAVIGATE_INSTRUCTIONS}\n{HIDE_INSTRUCTIONS}"),
format!("─\n "),
]
.into_iter()
.map(Cell::from)
.collect::<Row>()
.height(2),
.height(3),
);
StatefulWidget::render(table, area, buf, state);
}
Expand Down
Loading