mirror of
https://github.com/extrawurst/gitui.git
synced 2024-11-27 10:15:07 +03:00
show version in help popup
This commit is contained in:
parent
145bc90e4c
commit
71b113cbbb
@ -2,7 +2,7 @@ use super::{
|
||||
visibility_blocking, CommandBlocking, CommandInfo, Component,
|
||||
DrawableComponent, EventUpdate,
|
||||
};
|
||||
use crate::{keys, strings, ui};
|
||||
use crate::{keys, strings, ui, version::Version};
|
||||
use asyncgit::hash;
|
||||
use crossterm::event::Event;
|
||||
use itertools::Itertools;
|
||||
@ -10,12 +10,13 @@ use std::{borrow::Cow, cmp, convert::TryFrom};
|
||||
use strings::commands;
|
||||
use tui::{
|
||||
backend::Backend,
|
||||
layout::{Alignment, Rect},
|
||||
layout::{Alignment, Constraint, Direction, Layout, Rect},
|
||||
style::{Color, Style},
|
||||
widgets::{Block, Borders, Paragraph, Text, Widget},
|
||||
Frame,
|
||||
};
|
||||
|
||||
///
|
||||
#[derive(Default)]
|
||||
pub struct HelpComponent {
|
||||
cmds: Vec<CommandInfo>,
|
||||
@ -37,20 +38,40 @@ impl DrawableComponent for HelpComponent {
|
||||
0
|
||||
};
|
||||
|
||||
let area =
|
||||
ui::centered_rect_absolute(65, height, f.size());
|
||||
|
||||
ui::Clear::new(
|
||||
Paragraph::new(txt.iter())
|
||||
.block(
|
||||
Block::default()
|
||||
.title(strings::HELP_TITLE)
|
||||
.borders(Borders::ALL),
|
||||
)
|
||||
.scroll(scroll)
|
||||
.alignment(Alignment::Left),
|
||||
Block::default()
|
||||
.title(strings::HELP_TITLE)
|
||||
.borders(Borders::ALL),
|
||||
)
|
||||
.render(
|
||||
f,
|
||||
ui::centered_rect_absolute(65, height, f.size()),
|
||||
);
|
||||
.render(f, area);
|
||||
|
||||
let chunks = Layout::default()
|
||||
.vertical_margin(1)
|
||||
.horizontal_margin(1)
|
||||
.direction(Direction::Vertical)
|
||||
.constraints(
|
||||
[Constraint::Min(1), Constraint::Length(1)]
|
||||
.as_ref(),
|
||||
)
|
||||
.split(area);
|
||||
|
||||
Paragraph::new(txt.iter())
|
||||
.scroll(scroll)
|
||||
.alignment(Alignment::Left)
|
||||
.render(f, chunks[0]);
|
||||
|
||||
Paragraph::new(
|
||||
vec![Text::Raw(Cow::from(format!(
|
||||
"gitui {}",
|
||||
Version::new(),
|
||||
)))]
|
||||
.iter(),
|
||||
)
|
||||
.alignment(Alignment::Right)
|
||||
.render(f, chunks[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ mod poll;
|
||||
mod queue;
|
||||
mod strings;
|
||||
mod ui;
|
||||
mod version;
|
||||
|
||||
use crate::{app::App, poll::QueueEvent};
|
||||
use asyncgit::AsyncNotification;
|
||||
|
35
src/version.rs
Normal file
35
src/version.rs
Normal file
@ -0,0 +1,35 @@
|
||||
use std::{env, fmt};
|
||||
|
||||
///
|
||||
#[derive(Default)]
|
||||
pub struct Version {
|
||||
major: u32,
|
||||
minor: u32,
|
||||
patch: u32,
|
||||
}
|
||||
|
||||
impl Version {
|
||||
/// read version at compile time from env variables
|
||||
pub fn new() -> Self {
|
||||
let mut res = Self::default();
|
||||
let major_str = env!("CARGO_PKG_VERSION_MAJOR");
|
||||
if let Ok(major) = major_str.parse::<u32>() {
|
||||
res.major = major;
|
||||
}
|
||||
let minor_str = env!("CARGO_PKG_VERSION_MINOR");
|
||||
if let Ok(minor) = minor_str.parse::<u32>() {
|
||||
res.minor = minor;
|
||||
}
|
||||
let patch_str = env!("CARGO_PKG_VERSION_PATCH");
|
||||
if let Ok(patch) = patch_str.parse::<u32>() {
|
||||
res.patch = patch;
|
||||
}
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Version {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "v{}.{}.{}", self.major, self.minor, self.patch)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user