Skip to content

Commit 64869b3

Browse files
committed
feat(ultracompact): reduce complexity of interactive draw(...)
1 parent c4f483c commit 64869b3

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

crates/atuin/src/command/client/search/interactive.rs

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,6 @@ impl State {
658658
}
659659
}
660660

661-
#[allow(clippy::cast_possible_truncation)]
662661
#[allow(clippy::bool_to_int_with_if)]
663662
#[allow(clippy::too_many_lines)]
664663
fn draw(
@@ -843,9 +842,6 @@ impl State {
843842
}
844843

845844
if !matches!(compactness, Compactness::Ultracompact) {
846-
let input = self.build_input(style);
847-
f.render_widget(input, input_chunk);
848-
849845
let preview_width = match compactness {
850846
Compactness::Full => preview_width - 2,
851847
_ => preview_width,
@@ -857,20 +853,36 @@ impl State {
857853
preview_chunk.width.into(),
858854
theme,
859855
);
860-
f.render_widget(preview, preview_chunk);
856+
self.draw_preview(f, style, input_chunk, compactness, preview_chunk, preview);
857+
};
858+
}
861859

862-
let extra_width = UnicodeWidthStr::width(self.search.input.substring());
860+
#[allow(clippy::cast_possible_truncation)]
861+
fn draw_preview(
862+
&self,
863+
f: &mut Frame,
864+
style: StyleState,
865+
input_chunk: Rect,
866+
compactness: Compactness,
867+
preview_chunk: Rect,
868+
preview: Paragraph,
869+
) {
870+
let input = self.build_input(style);
871+
f.render_widget(input, input_chunk);
863872

864-
let cursor_offset = match compactness {
865-
Compactness::Full => 1,
866-
_ => 0,
867-
};
868-
f.set_cursor(
869-
// Put cursor past the end of the input text
870-
input_chunk.x + extra_width as u16 + PREFIX_LENGTH + 1 + cursor_offset,
871-
input_chunk.y + cursor_offset,
872-
);
873-
}
873+
f.render_widget(preview, preview_chunk);
874+
875+
let extra_width = UnicodeWidthStr::width(self.search.input.substring());
876+
877+
let cursor_offset = match compactness {
878+
Compactness::Full => 1,
879+
_ => 0,
880+
};
881+
f.set_cursor(
882+
// Put cursor past the end of the input text
883+
input_chunk.x + extra_width as u16 + PREFIX_LENGTH + 1 + cursor_offset,
884+
input_chunk.y + cursor_offset,
885+
);
874886
}
875887

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

0 commit comments

Comments
 (0)