Skip to content

Commit

Permalink
feat: render no-changes UI message
Browse files Browse the repository at this point in the history
It's a little confusing when the calling program provides no changes in the UI, which is probably a bug in the caller, but worth explaining explicitly anyways.
  • Loading branch information
arxanas committed Dec 23, 2023
1 parent 8bd8a06 commit e9993d3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2301,8 +2301,28 @@ impl Component for CommitView<'_> {
file_views,
} = self;

let mut y = y;
let commit_message_view_rect = viewport.draw_component(x, y, commit_message_view);
if file_views.is_empty() {
let message = "There are no changes to view.";
let message_rect = centered_rect(
Rect {
x,
y,
width: viewport.mask_rect().width,
height: viewport.mask_rect().height,
},
RectSize {
width: message.len(),
height: 1,
},
50,
50,
);
viewport.draw_text(message_rect.x, message_rect.y, &Span::raw(message));
return;
}

let mut y = y;
y += commit_message_view_rect.height.unwrap_isize();
for file_view in file_views {
let file_view_rect = {
Expand Down
28 changes: 28 additions & 0 deletions tests/test_scm_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2726,3 +2726,31 @@ fn test_deserialize() -> eyre::Result<()> {
assert_eq!(example_contents(), deserialized);
Ok(())
}

#[test]
fn test_no_files() -> eyre::Result<()> {
let state = RecordState {
is_read_only: false,
commits: Default::default(),
files: vec![],
};
let initial = TestingScreenshot::default();
let mut input = TestingInput::new(
80,
6,
[Event::ExpandAll, initial.event(), Event::QuitAccept],
);
let recorder = Recorder::new(state, &mut input);
recorder.run()?;

insta::assert_display_snapshot!(initial, @r###"
"[File] [Edit] [Select] [View] "
" "
" There are no changes to view. "
" "
" "
" "
"###);

Ok(())
}

0 comments on commit e9993d3

Please sign in to comment.