Load title from config file
This commit is contained in:
parent
f6d01068a3
commit
da1892710f
6 changed files with 10 additions and 10 deletions
|
|
@ -1,3 +0,0 @@
|
||||||
export DEJA_VU_CONFIG=`pwd`/config
|
|
||||||
export DEJA_VU_DATA=`pwd`/data
|
|
||||||
export DEJA_VU_LOG_LEVEL=debug
|
|
||||||
|
|
@ -21,7 +21,6 @@ edition = "2021"
|
||||||
license = "GPL"
|
license = "GPL"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
|
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
{
|
{
|
||||||
|
"app_title": "Deja-vu: Clone Tool",
|
||||||
"clone_app_path": "C:/Program Files/Some Clone Tool/app.exe",
|
"clone_app_path": "C:/Program Files/Some Clone Tool/app.exe",
|
||||||
"keybindings": {
|
"keybindings": {
|
||||||
"ScanDisks": {
|
"ScanDisks": {
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Deja-vu. If not, see <https://www.gnu.org/licenses/>.
|
// along with Deja-vu. If not, see <https://www.gnu.org/licenses/>.
|
||||||
//
|
//
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
env,
|
env,
|
||||||
iter::zip,
|
iter::zip,
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ impl Component for Title {
|
||||||
fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
|
fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
|
||||||
// Title Block
|
// Title Block
|
||||||
let title_text = Span::styled(
|
let title_text = Span::styled(
|
||||||
"WizardKit: Clone Tool",
|
self.config.app_title.as_str(),
|
||||||
Style::default().fg(Color::LightCyan),
|
Style::default().fg(Color::LightCyan),
|
||||||
);
|
);
|
||||||
let title = Paragraph::new(Line::from(title_text).centered())
|
let title = Paragraph::new(Line::from(title_text).centered())
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,8 @@ pub struct AppConfig {
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Deserialize)]
|
#[derive(Clone, Debug, Default, Deserialize)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
|
#[serde(default)]
|
||||||
|
pub app_title: String,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub clone_app_path: PathBuf,
|
pub clone_app_path: PathBuf,
|
||||||
#[serde(default, flatten)]
|
#[serde(default, flatten)]
|
||||||
|
|
@ -68,12 +70,13 @@ impl Config {
|
||||||
let data_dir = get_data_dir();
|
let data_dir = get_data_dir();
|
||||||
let config_dir = get_config_dir();
|
let config_dir = get_config_dir();
|
||||||
let mut builder = config::Config::builder()
|
let mut builder = config::Config::builder()
|
||||||
.set_default("data_dir", data_dir.to_str().unwrap())?
|
.set_default("app_title", default_config.app_title.as_str())?
|
||||||
.set_default("config_dir", config_dir.to_str().unwrap())?
|
|
||||||
.set_default(
|
.set_default(
|
||||||
"clone_app_path",
|
"clone_app_path",
|
||||||
String::from("C:\\Program Files\\Some Clone Tool\\app.exe"),
|
String::from("C:\\Program Files\\Some Clone Tool\\app.exe"),
|
||||||
)?;
|
)?
|
||||||
|
.set_default("config_dir", config_dir.to_str().unwrap())?
|
||||||
|
.set_default("data_dir", data_dir.to_str().unwrap())?;
|
||||||
|
|
||||||
let config_files = [
|
let config_files = [
|
||||||
("config.json5", config::FileFormat::Json5),
|
("config.json5", config::FileFormat::Json5),
|
||||||
|
|
@ -95,7 +98,6 @@ impl Config {
|
||||||
if !found_config {
|
if !found_config {
|
||||||
error!("No configuration file found. Application may not behave as expected");
|
error!("No configuration file found. Application may not behave as expected");
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut cfg: Self = builder.build()?.try_deserialize()?;
|
let mut cfg: Self = builder.build()?.try_deserialize()?;
|
||||||
|
|
||||||
for (mode, default_bindings) in default_config.keybindings.iter() {
|
for (mode, default_bindings) in default_config.keybindings.iter() {
|
||||||
|
|
@ -140,7 +142,7 @@ pub fn get_config_dir() -> PathBuf {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn project_directory() -> Option<ProjectDirs> {
|
fn project_directory() -> Option<ProjectDirs> {
|
||||||
ProjectDirs::from("com", "WizardKit", env!("CARGO_PKG_NAME"))
|
ProjectDirs::from("com", "Deja-vu", env!("CARGO_PKG_NAME"))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Deref, DerefMut)]
|
#[derive(Clone, Debug, Default, Deref, DerefMut)]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue