From de0198920ac4772bab382386e72b1b081d92a595 Mon Sep 17 00:00:00 2001 From: sharkdp Date: Sun, 22 Apr 2018 16:03:47 +0200 Subject: [PATCH] Load themes from ~/.config/bat/themes --- src/main.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index f753727b..b828ec91 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,8 @@ extern crate syntect; extern crate clap; use std::collections::HashMap; -use std::io::{self, BufRead, Result, Write, ErrorKind, StdoutLock}; +use std::env; +use std::io::{self, BufRead, ErrorKind, Result, StdoutLock, Write}; use std::path::Path; use std::process; @@ -37,7 +38,11 @@ type LineChanges = HashMap; const PANEL_WIDTH: usize = 7; const GRID_COLOR: u8 = 238; -fn print_horizontal_line(handle: &mut StdoutLock, grid_char: char, term_width: usize) -> io::Result<()> { +fn print_horizontal_line( + handle: &mut StdoutLock, + grid_char: char, + term_width: usize, +) -> io::Result<()> { let bar = "─".repeat(term_width - (PANEL_WIDTH + 1)); let line = format!("{}{}{}", "─".repeat(PANEL_WIDTH), grid_char, bar); @@ -159,7 +164,14 @@ fn get_git_diff(filename: String) -> Option { } fn run(matches: &ArgMatches) -> Result<()> { - let theme_set = ThemeSet::load_from_folder("/home/shark/Informatik/rust/bat/themes").unwrap(); + let home_dir = env::home_dir().ok_or(io::Error::new( + ErrorKind::Other, + "Could not get home directory", + ))?; + + let theme_dir = home_dir.join(".config").join("bat").join("themes"); + let theme_set = ThemeSet::load_from_folder(theme_dir) + .map_err(|_| io::Error::new(ErrorKind::Other, "Could not load themes"))?; let theme = &theme_set.themes["Monokai"]; let syntax_set = SyntaxSet::load_defaults_nonewlines();