Skip to content

Commit 71b113c

Browse files
author
Stephan Dilly
committed
show version in help popup
1 parent 145bc90 commit 71b113c

File tree

3 files changed

+71
-14
lines changed

3 files changed

+71
-14
lines changed

src/components/help.rs

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@ use super::{
22
visibility_blocking, CommandBlocking, CommandInfo, Component,
33
DrawableComponent, EventUpdate,
44
};
5-
use crate::{keys, strings, ui};
5+
use crate::{keys, strings, ui, version::Version};
66
use asyncgit::hash;
77
use crossterm::event::Event;
88
use itertools::Itertools;
99
use std::{borrow::Cow, cmp, convert::TryFrom};
1010
use strings::commands;
1111
use tui::{
1212
backend::Backend,
13-
layout::{Alignment, Rect},
13+
layout::{Alignment, Constraint, Direction, Layout, Rect},
1414
style::{Color, Style},
1515
widgets::{Block, Borders, Paragraph, Text, Widget},
1616
Frame,
1717
};
1818

19+
///
1920
#[derive(Default)]
2021
pub struct HelpComponent {
2122
cmds: Vec<CommandInfo>,
@@ -37,20 +38,40 @@ impl DrawableComponent for HelpComponent {
3738
0
3839
};
3940

41+
let area =
42+
ui::centered_rect_absolute(65, height, f.size());
43+
4044
ui::Clear::new(
41-
Paragraph::new(txt.iter())
42-
.block(
43-
Block::default()
44-
.title(strings::HELP_TITLE)
45-
.borders(Borders::ALL),
46-
)
47-
.scroll(scroll)
48-
.alignment(Alignment::Left),
45+
Block::default()
46+
.title(strings::HELP_TITLE)
47+
.borders(Borders::ALL),
4948
)
50-
.render(
51-
f,
52-
ui::centered_rect_absolute(65, height, f.size()),
53-
);
49+
.render(f, area);
50+
51+
let chunks = Layout::default()
52+
.vertical_margin(1)
53+
.horizontal_margin(1)
54+
.direction(Direction::Vertical)
55+
.constraints(
56+
[Constraint::Min(1), Constraint::Length(1)]
57+
.as_ref(),
58+
)
59+
.split(area);
60+
61+
Paragraph::new(txt.iter())
62+
.scroll(scroll)
63+
.alignment(Alignment::Left)
64+
.render(f, chunks[0]);
65+
66+
Paragraph::new(
67+
vec![Text::Raw(Cow::from(format!(
68+
"gitui {}",
69+
Version::new(),
70+
)))]
71+
.iter(),
72+
)
73+
.alignment(Alignment::Right)
74+
.render(f, chunks[1]);
5475
}
5576
}
5677
}

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ mod poll;
1010
mod queue;
1111
mod strings;
1212
mod ui;
13+
mod version;
1314

1415
use crate::{app::App, poll::QueueEvent};
1516
use asyncgit::AsyncNotification;

src/version.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use std::{env, fmt};
2+
3+
///
4+
#[derive(Default)]
5+
pub struct Version {
6+
major: u32,
7+
minor: u32,
8+
patch: u32,
9+
}
10+
11+
impl Version {
12+
/// read version at compile time from env variables
13+
pub fn new() -> Self {
14+
let mut res = Self::default();
15+
let major_str = env!("CARGO_PKG_VERSION_MAJOR");
16+
if let Ok(major) = major_str.parse::<u32>() {
17+
res.major = major;
18+
}
19+
let minor_str = env!("CARGO_PKG_VERSION_MINOR");
20+
if let Ok(minor) = minor_str.parse::<u32>() {
21+
res.minor = minor;
22+
}
23+
let patch_str = env!("CARGO_PKG_VERSION_PATCH");
24+
if let Ok(patch) = patch_str.parse::<u32>() {
25+
res.patch = patch;
26+
}
27+
res
28+
}
29+
}
30+
31+
impl fmt::Display for Version {
32+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33+
write!(f, "v{}.{}.{}", self.major, self.minor, self.patch)
34+
}
35+
}

0 commit comments

Comments
 (0)