mirror of
https://github.com/gitui-org/gitui
synced 2026-05-24 09:28:21 +00:00
show version in help popup
This commit is contained in:
parent
145bc90e4c
commit
71b113cbbb
3 changed files with 71 additions and 14 deletions
|
|
@ -2,7 +2,7 @@ use super::{
|
||||||
visibility_blocking, CommandBlocking, CommandInfo, Component,
|
visibility_blocking, CommandBlocking, CommandInfo, Component,
|
||||||
DrawableComponent, EventUpdate,
|
DrawableComponent, EventUpdate,
|
||||||
};
|
};
|
||||||
use crate::{keys, strings, ui};
|
use crate::{keys, strings, ui, version::Version};
|
||||||
use asyncgit::hash;
|
use asyncgit::hash;
|
||||||
use crossterm::event::Event;
|
use crossterm::event::Event;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
|
@ -10,12 +10,13 @@ use std::{borrow::Cow, cmp, convert::TryFrom};
|
||||||
use strings::commands;
|
use strings::commands;
|
||||||
use tui::{
|
use tui::{
|
||||||
backend::Backend,
|
backend::Backend,
|
||||||
layout::{Alignment, Rect},
|
layout::{Alignment, Constraint, Direction, Layout, Rect},
|
||||||
style::{Color, Style},
|
style::{Color, Style},
|
||||||
widgets::{Block, Borders, Paragraph, Text, Widget},
|
widgets::{Block, Borders, Paragraph, Text, Widget},
|
||||||
Frame,
|
Frame,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
///
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct HelpComponent {
|
pub struct HelpComponent {
|
||||||
cmds: Vec<CommandInfo>,
|
cmds: Vec<CommandInfo>,
|
||||||
|
|
@ -37,20 +38,40 @@ impl DrawableComponent for HelpComponent {
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let area =
|
||||||
|
ui::centered_rect_absolute(65, height, f.size());
|
||||||
|
|
||||||
ui::Clear::new(
|
ui::Clear::new(
|
||||||
Paragraph::new(txt.iter())
|
Block::default()
|
||||||
.block(
|
.title(strings::HELP_TITLE)
|
||||||
Block::default()
|
.borders(Borders::ALL),
|
||||||
.title(strings::HELP_TITLE)
|
|
||||||
.borders(Borders::ALL),
|
|
||||||
)
|
|
||||||
.scroll(scroll)
|
|
||||||
.alignment(Alignment::Left),
|
|
||||||
)
|
)
|
||||||
.render(
|
.render(f, area);
|
||||||
f,
|
|
||||||
ui::centered_rect_absolute(65, height, f.size()),
|
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 queue;
|
||||||
mod strings;
|
mod strings;
|
||||||
mod ui;
|
mod ui;
|
||||||
|
mod version;
|
||||||
|
|
||||||
use crate::{app::App, poll::QueueEvent};
|
use crate::{app::App, poll::QueueEvent};
|
||||||
use asyncgit::AsyncNotification;
|
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 a new issue