Skip to content

Commit

Permalink
chore(tui): remove allocations for current task name
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-olszewski committed Jul 24, 2024
1 parent dc5fd71 commit 08a242d
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions crates/turborepo-ui/src/tui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,8 @@ impl<W> App<W> {
}
}

pub fn active_task(&self) -> String {
self.tasks_by_status
.task_name(self.selected_task_index)
.to_string()
pub fn active_task(&self) -> &str {
self.tasks_by_status.task_name(self.selected_task_index)
}

fn input_options(&self) -> InputOptions {
Expand All @@ -118,11 +116,11 @@ impl<W> App<W> {
}

pub fn get_full_task(&self) -> &TerminalOutput<W> {
self.tasks.get(&self.active_task()).unwrap()
self.tasks.get(self.active_task()).unwrap()
}

pub fn get_full_task_mut(&mut self) -> &mut TerminalOutput<W> {
self.tasks.get_mut(&self.active_task()).unwrap()
self.tasks.get_mut(&self.active_task().to_owned()).unwrap()
}

#[tracing::instrument(skip(self))]
Expand All @@ -147,11 +145,7 @@ impl<W> App<W> {

#[tracing::instrument(skip_all)]
pub fn scroll_terminal_output(&mut self, direction: Direction) {
self.tasks
.get_mut(&self.active_task())
.unwrap()
.scroll(direction)
.unwrap_or_default();
self.get_full_task_mut().scroll(direction).unwrap();
}

/// Mark the given task as started.
Expand Down Expand Up @@ -267,8 +261,7 @@ impl<W> App<W> {
}

pub fn has_stdin(&self) -> bool {
let active_task = self.active_task();
if let Some(term) = self.tasks.get(&active_task) {
if let Some(term) = self.tasks.get(self.active_task()) {
term.stdin.is_some()
} else {
false
Expand Down Expand Up @@ -354,7 +347,7 @@ impl<W> App<W> {
pub fn copy_selection(&self) {
let task = self
.tasks
.get(&self.active_task())
.get(self.active_task())
.expect("active task should exist");
let Some(text) = task.copy_selection() else {
return;
Expand Down Expand Up @@ -382,7 +375,7 @@ impl<W: Write> App<W> {
let task_output = self.get_full_task_mut();
if let Some(stdin) = &mut task_output.stdin {
stdin.write_all(bytes).map_err(|e| Error::Stdin {
name: self.active_task(),
name: self.active_task().to_owned(),
e,
})?;
}
Expand Down Expand Up @@ -587,7 +580,7 @@ fn view<W>(app: &mut App<W>, f: &mut Frame) {
let horizontal = Layout::horizontal([Constraint::Fill(1), Constraint::Length(cols)]);
let [table, pane] = horizontal.areas(f.size());

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

let output_logs = app.tasks.get(&active_task).unwrap();
let pane_to_render: TerminalPane<W> =
Expand Down

0 comments on commit 08a242d

Please sign in to comment.