Skip to content

Commit

Permalink
feat(ultracompact): reduce complexity of interactive draw(...)
Browse files Browse the repository at this point in the history
  • Loading branch information
philtweir committed Oct 20, 2024
1 parent d576674 commit 55f5da5
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions crates/atuin/src/command/client/search/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,6 @@ impl State {
}
}

#[allow(clippy::cast_possible_truncation)]
#[allow(clippy::bool_to_int_with_if)]
#[allow(clippy::too_many_lines)]
fn draw(
Expand Down Expand Up @@ -844,9 +843,6 @@ impl State {
}

if !matches!(compactness, Compactness::Ultracompact) {
let input = self.build_input(style);
f.render_widget(input, input_chunk);

let preview_width = match compactness {
Compactness::Full => preview_width - 2,
_ => preview_width,
Expand All @@ -858,20 +854,36 @@ impl State {
preview_chunk.width.into(),
theme,
);
f.render_widget(preview, preview_chunk);
self.draw_preview(f, style, input_chunk, compactness, preview_chunk, preview);
};
}

let extra_width = UnicodeWidthStr::width(self.search.input.substring());
#[allow(clippy::cast_possible_truncation)]
fn draw_preview(
&self,
f: &mut Frame,
style: StyleState,
input_chunk: Rect,
compactness: Compactness,
preview_chunk: Rect,
preview: Paragraph,
) {
let input = self.build_input(style);
f.render_widget(input, input_chunk);

let cursor_offset = match compactness {
Compactness::Full => 1,
_ => 0,
};
f.set_cursor(
// Put cursor past the end of the input text
input_chunk.x + extra_width as u16 + PREFIX_LENGTH + 1 + cursor_offset,
input_chunk.y + cursor_offset,
);
}
f.render_widget(preview, preview_chunk);

let extra_width = UnicodeWidthStr::width(self.search.input.substring());

let cursor_offset = match compactness {
Compactness::Full => 1,
_ => 0,
};
f.set_cursor(
// Put cursor past the end of the input text
input_chunk.x + extra_width as u16 + PREFIX_LENGTH + 1 + cursor_offset,
input_chunk.y + cursor_offset,
);
}

fn build_title(&self, theme: &Theme) -> Paragraph {
Expand Down

0 comments on commit 55f5da5

Please sign in to comment.