allow longer messages in log view

This commit is contained in:
Stephan Dilly 2020-05-15 18:55:18 +02:00
parent f8294dcb7b
commit a5d5b3b916
4 changed files with 16 additions and 9 deletions

View file

@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- introduced proper changelog
### Changed
- show longer commit messages in log view
- introduce propper error handling in `asyncgit` [[@MCord](https://github.com/MCord)] ([#53](https://github.com/extrawurst/gitui/issues/53))
- better error message when trying to run outside of a valid git repo ([#56](https://github.com/extrawurst/gitui/issues/56))
- improve ctrl+c handling so it is checked first and no component needs to worry of blocking it

View file

@ -20,6 +20,7 @@ pub struct CommitInfo {
pub fn get_commits_info(
repo_path: &str,
ids: &[Oid],
message_length_limit: usize,
) -> Result<Vec<CommitInfo>> {
scope_time!("get_commits_info");
@ -33,7 +34,7 @@ pub fn get_commits_info(
let res = commits
.map(|c: Commit| {
let message = get_message(&c);
let message = get_message(&c, message_length_limit);
let author = if let Some(name) = c.author().name() {
String::from(name)
} else {
@ -51,9 +52,9 @@ pub fn get_commits_info(
Ok(res)
}
fn get_message(c: &Commit) -> String {
fn get_message(c: &Commit, message_length_limit: usize) -> String {
if let Some(msg) = c.message() {
limit_str(msg, 50)
limit_str(msg, message_length_limit)
} else {
String::from("<unknown>")
}
@ -91,7 +92,8 @@ mod tests {
stage_add_file(repo_path, file_path).unwrap();
let c2 = commit(repo_path, "commit2").unwrap();
let res = get_commits_info(repo_path, &vec![c2, c1]).unwrap();
let res =
get_commits_info(repo_path, &vec![c2, c1], 50).unwrap();
assert_eq!(res.len(), 2);
assert_eq!(res[0].message.as_str(), "commit2");

View file

@ -98,7 +98,7 @@ mod tests {
let mut walk = LogWalker::new(&repo);
walk.read(&mut items, 100).unwrap();
let info = get_commits_info(repo_path, &items).unwrap();
let info = get_commits_info(repo_path, &items, 50).unwrap();
dbg!(&info);
assert_eq!(items.len(), 2);

View file

@ -54,7 +54,7 @@ pub struct Revlog {
first_open_done: bool,
scroll_state: (Instant, f32),
tags: Tags,
current_height: u16,
current_size: (u16, u16),
}
impl Revlog {
@ -69,7 +69,7 @@ impl Revlog {
first_open_done: false,
scroll_state: (Instant::now(), 0_f32),
tags: Tags::new(),
current_height: 0,
current_size: (0, 0),
}
}
@ -98,6 +98,7 @@ impl Revlog {
let commits = sync::get_commits_info(
CWD,
&self.git_log.get_slice(want_min, SLICE_SIZE).unwrap(),
self.current_size.0.into(),
);
if let Ok(commits) = commits {
@ -114,7 +115,7 @@ impl Revlog {
.max(1);
let page_offset =
usize::from(self.current_height).saturating_sub(1);
usize::from(self.current_size.1).saturating_sub(1);
self.selection = match scroll {
ScrollType::Up => {
@ -236,7 +237,10 @@ impl Revlog {
impl DrawableComponent for Revlog {
fn draw<B: Backend>(&mut self, f: &mut Frame<B>, area: Rect) {
self.current_height = area.height.saturating_sub(2);
self.current_size = (
area.width.saturating_sub(2),
area.height.saturating_sub(2),
);
let height = area.height as usize;
let selection =