Read config from file

pull/3/head
Arijit Basu 3 years ago
parent 3572d26b95
commit c066201777
No known key found for this signature in database
GPG Key ID: 7D7BF809E7378863

2
Cargo.lock generated

@ -1166,7 +1166,7 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "xplr"
version = "0.2.0"
version = "0.2.1"
dependencies = [
"criterion",
"crossterm",

@ -1,6 +1,6 @@
[package]
name = "xplr"
version = "0.2.0" # Update app.rs
version = "0.2.1" # Update app.rs
authors = ["Arijit Basu <sayanarijit@gmail.com>"]
edition = "2018"
description = "An experimental, minimal, configurable TUI file explorer, stealing ideas from nnn and fzf."

@ -10,7 +10,7 @@ use std::collections::HashMap;
use std::collections::VecDeque;
use std::path::PathBuf;
pub const VERSION: &str = "v0.2.0"; // Update Cargo.toml
pub const VERSION: &str = "v0.2.1"; // Update Cargo.toml
pub const TEMPLATE_TABLE_ROW: &str = "TEMPLATE_TABLE_ROW";
@ -216,8 +216,7 @@ pub struct App {
}
impl App {
pub fn new(pwd: String) -> Self {
let config = Config::default();
pub fn new(config: Config, pwd: String) -> Self {
let mode = config
.modes
.get(&"default".to_string())

@ -5,6 +5,7 @@ use handlebars::{handlebars_helper, Handlebars};
use shellwords;
use std::env;
use std::fs;
use std::io;
use std::io::prelude::*;
use std::path::PathBuf;
use std::sync::mpsc;
@ -14,6 +15,7 @@ use termion::get_tty;
use tui::backend::CrosstermBackend;
use tui::Terminal;
use xplr::app;
use xplr::config::Config;
use xplr::error::Error;
use xplr::explorer;
use xplr::input::Key;
@ -38,7 +40,19 @@ fn main() -> Result<(), Error> {
let mut last_pwd = pwd.clone();
let mut app = app::App::new(pwd.clone());
let config_dir = dirs::config_dir()
.unwrap_or(PathBuf::from("."))
.join("xplr");
let config_file = config_dir.join("config.yml");
let config: Config = if config_file.exists() {
serde_yaml::from_reader(io::BufReader::new(&fs::File::open(&config_file)?))?
} else {
Config::default()
};
let mut app = app::App::new(config, pwd.clone());
let mut hb = Handlebars::new();
hb.register_helper("shellescape", Box::new(shellescape));

Loading…
Cancel
Save