From af449a6402799ff6a2a332b4c6aec537ce2f65a9 Mon Sep 17 00:00:00 2001 From: dvkt Date: Mon, 6 Jan 2020 10:18:27 -0800 Subject: [PATCH] show build details on About screen --- build.rs | 26 +++++++++++++++++++++++--- src/gopher.rs | 4 +++- src/help.rs | 23 +++++++++++++++++++---- src/lib.rs | 7 +++++++ 4 files changed, 52 insertions(+), 8 deletions(-) diff --git a/build.rs b/build.rs index 58a6a7e..b940f49 100644 --- a/build.rs +++ b/build.rs @@ -1,6 +1,26 @@ +use std::{env, process}; + fn main() { + println!("cargo:rustc-env=PLATFORM={}", env::var("TARGET").unwrap()); + println!("cargo:rustc-env=BUILD_DATE={}", sh("date")); println!( - "cargo:rustc-env=PLATFORM={}", - std::env::var("TARGET").unwrap() - ); + "cargo:rustc-env=GIT_REF={}", + sh("git rev-parse --short HEAD") + ) +} + +fn sh(args: &str) -> String { + let args: Vec<&str> = args.split(" ").collect(); + let cmd = args[0]; + let args: Vec<_> = args.iter().skip(1).collect(); + + if let Ok(output) = process::Command::new(cmd).args(&args).output() { + if !output.status.success() { + eprintln!("Error running {} {:?}", cmd, args); + process::exit(1); + } + String::from_utf8(output.stdout).unwrap() + } else { + String::new() + } } diff --git a/src/gopher.rs b/src/gopher.rs index fc962ea..f6603d1 100644 --- a/src/gopher.rs +++ b/src/gopher.rs @@ -1,4 +1,3 @@ -use native_tls::TlsConnector; use std::{ io::{Read, Result, Write}, net::TcpStream, @@ -8,6 +7,9 @@ use std::{ }; use termion::input::TermRead; +#[cfg(feature = "tls")] +use native_tls::TlsConnector; + mod r#type; pub use self::r#type::Type; diff --git a/src/help.rs b/src/help.rs index 343d221..5b93fb7 100644 --- a/src/help.rs +++ b/src/help.rs @@ -6,12 +6,20 @@ pub fn lookup(name: &str) -> Option { "" | "/" | "home" | "home/" => format!("{}{}", HEADER, START), "history" => history::as_raw_menu(), "bookmarks" => bookmarks::as_raw_menu(), - "about" => format!("{}{}", HEADER, ABOUT.replace("{version}", crate::VERSION)), "help/keys" => format!("{}{}", HEADER, KEYS), "help/nav" => format!("{}{}", HEADER, NAV), "help/types" => format!("{}{}", HEADER, TYPES), "help/bookmarks" => format!("{}{}", HEADER, BOOKMARKS), "help/history" => format!("{}{}", HEADER, HISTORY), + "about" => format!( + "{}{}", + HEADER, + ABOUT + .replace("{build-date}", crate::BUILD_DATE) + .replace("{git-ref}", crate::GIT_REF) + .replace("{tls-support}", crate::TLS_SUPPORT) + .replace("{version}", crate::VERSION) + ), "help" | "help/" => format!( "{}{}", HEADER, @@ -212,6 +220,12 @@ i const ABOUT: &str = " i ~ version: v{version} ~ i +1phetch's gopherhole /phetch phkt.io +hphetch's webpage URL:https://github.com/dvkt/phetch +0MIT license /MIT License gopherpedia.com +i +i ~ * ~ +i ispecial thanks to: i ikseistrup - major help with @@ -225,7 +239,8 @@ i add some \x1b[95mcolor i i ~ * ~ i -1phetch's gopherhole /phetch phkt.io -0phetch uses the MIT license /MIT License gopherpedia.com -hwebpage: github.com/dvkt/phetch URL:https://github.com/dvkt/phetch +itls: {tls-support} +iref: {git-ref} +ibuilt: {build-date} +i "; diff --git a/src/lib.rs b/src/lib.rs index d1ff943..f502d94 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,4 +13,11 @@ pub mod ui; pub const VERSION: &str = env!("CARGO_PKG_VERSION"); pub const PLATFORM: &str = env!("PLATFORM"); +pub const GIT_REF: &str = env!("GIT_REF"); +pub const BUILD_DATE: &str = env!("BUILD_DATE"); pub const BUG_URL: &str = "https://github.com/dvkt/phetch/issues/new"; + +#[cfg(feature = "tls")] +pub const TLS_SUPPORT: &str = "enabled"; +#[cfg(not(feature = "tls"))] +pub const TLS_SUPPORT: &str = "not enabled";