mirror of
https://github.com/apognu/tuigreet.git
synced 2024-09-11 07:25:29 +03:00
Properly support issue content with significant ident as well as \d, \t, and \U modifiers.
This commit is contained in:
parent
2cc9fd9f97
commit
da6b1290e4
52
Cargo.lock
generated
52
Cargo.lock
generated
@ -26,7 +26,7 @@ dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
"version_check",
|
||||
"zerocopy",
|
||||
"zerocopy 0.7.35",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1034,7 +1034,7 @@ version = "0.2.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04"
|
||||
dependencies = [
|
||||
"zerocopy",
|
||||
"zerocopy 0.7.35",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1748,6 +1748,7 @@ dependencies = [
|
||||
"tracing-subscriber",
|
||||
"unic-langid",
|
||||
"unicode-width",
|
||||
"utmp-rs",
|
||||
"uzers",
|
||||
"zeroize",
|
||||
]
|
||||
@ -1815,6 +1816,30 @@ version = "0.1.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d"
|
||||
|
||||
[[package]]
|
||||
name = "utmp-raw"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9259b18bad8808ca2b0e585d8c06a6ac7b0bb11b7bf50632d05832c25e6f91f"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"zerocopy 0.6.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "utmp-rs"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a9c97e4baf720e8a40615bd084c7e18f489d8099045f4e45f8e96d6c88c9c20"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"thiserror",
|
||||
"time",
|
||||
"utmp-raw",
|
||||
"zerocopy 0.6.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uzers"
|
||||
version = "0.12.1"
|
||||
@ -2104,6 +2129,16 @@ dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy"
|
||||
version = "0.6.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "854e949ac82d619ee9a14c66a1b674ac730422372ccb759ce0c39cabcf2bf8e6"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"zerocopy-derive 0.6.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy"
|
||||
version = "0.7.35"
|
||||
@ -2111,7 +2146,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"zerocopy-derive",
|
||||
"zerocopy-derive 0.7.35",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy-derive"
|
||||
version = "0.6.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "125139de3f6b9d625c39e2efdd73d41bdac468ccd556556440e322be0e1bbd91"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.72",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -45,6 +45,7 @@ rand = "0.8.5"
|
||||
tracing-appender = "0.2.3"
|
||||
tracing-subscriber = "0.3.18"
|
||||
tracing = "0.1.40"
|
||||
utmp-rs = "0.3.0"
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
|
21
src/info.rs
21
src/info.rs
@ -7,9 +7,11 @@ use std::{
|
||||
process::Command,
|
||||
};
|
||||
|
||||
use chrono::Local;
|
||||
use ini::Ini;
|
||||
use lazy_static::lazy_static;
|
||||
use nix::sys::utsname;
|
||||
use utmp_rs::{UtmpEntry, UtmpParser};
|
||||
use uzers::os::unix::UserExt;
|
||||
|
||||
use crate::{
|
||||
@ -49,6 +51,20 @@ pub fn get_hostname() -> String {
|
||||
}
|
||||
|
||||
pub fn get_issue() -> Option<String> {
|
||||
let (date, time) = {
|
||||
let now = Local::now();
|
||||
|
||||
(now.format("%a %b %_d %Y").to_string(), now.format("%H:%M:%S").to_string())
|
||||
};
|
||||
|
||||
let count = match UtmpParser::from_path("/var/run/utmp")
|
||||
.map(|utmp| utmp.into_iter().filter(|user| matches!(user, Ok(UtmpEntry::UserProcess { .. }))).count())
|
||||
.unwrap_or(0)
|
||||
{
|
||||
n if n < 2 => format!("{n} user"),
|
||||
n => format!("{n} users"),
|
||||
};
|
||||
|
||||
let vtnr: usize = env::var("XDG_VTNR").unwrap_or_else(|_| "0".to_string()).parse().expect("unable to parse VTNR");
|
||||
let uts = utsname::uname();
|
||||
|
||||
@ -63,10 +79,13 @@ pub fn get_issue() -> Option<String> {
|
||||
.replace("\\v", uts.version().to_str().unwrap_or(""))
|
||||
.replace("\\n", uts.nodename().to_str().unwrap_or(""))
|
||||
.replace("\\m", uts.machine().to_str().unwrap_or(""))
|
||||
.replace("\\d", &date)
|
||||
.replace("\\t", &time)
|
||||
.replace("\\U", &count)
|
||||
.replace("\\x1b", "\x1b")
|
||||
.replace("\\033", "\x1b")
|
||||
.replace("\\e", "\x1b")
|
||||
.replace("\\\\", "\\"),
|
||||
.replace(r"\\", r"\"),
|
||||
),
|
||||
|
||||
_ => Some(issue),
|
||||
|
@ -110,7 +110,7 @@ pub fn get_greeting_height(greeter: &Greeter, padding: u16, fallback: u16) -> (O
|
||||
Err(_) => Text::raw(greeting),
|
||||
};
|
||||
|
||||
let paragraph = Paragraph::new(text.clone()).wrap(Wrap { trim: true });
|
||||
let paragraph = Paragraph::new(text.clone()).wrap(Wrap { trim: false });
|
||||
let height = paragraph.line_count(width - (2 * padding)) + 1;
|
||||
|
||||
(Some(paragraph), height as u16)
|
||||
@ -290,7 +290,7 @@ mod test {
|
||||
Span::styled("Hello", Style::default().fg(Color::Red)),
|
||||
Span::styled(" World", Style::reset()),
|
||||
])]))
|
||||
.wrap(Wrap { trim: true });
|
||||
.wrap(Wrap { trim: false });
|
||||
|
||||
assert_eq!(text, Some(expected));
|
||||
assert_eq!(height, 2);
|
||||
@ -308,7 +308,7 @@ mod test {
|
||||
Span::styled("Hello", Style::default().fg(Color::Red)),
|
||||
Span::styled(" World", Style::reset()),
|
||||
])]))
|
||||
.wrap(Wrap { trim: true });
|
||||
.wrap(Wrap { trim: false });
|
||||
|
||||
assert_eq!(text, Some(expected));
|
||||
assert_eq!(height, 3);
|
||||
|
Loading…
Reference in New Issue
Block a user