Skip to content

Commit

Permalink
Merge pull request #13 from UnsafeOats/clean_up
Browse files Browse the repository at this point in the history
cleaned up a bit and added color selection options
  • Loading branch information
shaneish authored Feb 25, 2023
2 parents 75b5771 + 3d7f9c8 commit 25cd5c8
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 214 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bhop"
version = "0.5.3"
version = "0.5.4"
edition = "2021"
authors = ["Shane Stephenson <[email protected]>"]
readme = "README.md"
Expand Down
40 changes: 0 additions & 40 deletions Makefile

This file was deleted.

148 changes: 0 additions & 148 deletions runners/add_runners.py

This file was deleted.

1 change: 0 additions & 1 deletion runners/add_runners.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
// With all these updates in place, the current build system should start configuring the new shell
// for use.
use dirs::home_dir;
use dos2unix;
use std::{
env::var,
fs::{read_to_string, OpenOptions},
Expand Down
15 changes: 15 additions & 0 deletions src/defaults/unix_defaults.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ max_history=300
# before displaying the next N shortcuts.
ls_display_block=0

# Choose the primary and secondary colors for formatting printing.
# Use true color format to select the coloring.
# Example colors are:
# blue: [51, 153, 255]
# cyan: [51, 255, 255]
# pink: [255, 51, 153]
# red: [255, 51, 51]
# green: [51, 255, 153]
# bright green: [153, 255, 51]
# yellow: [255, 255, 51]
# purple: [153, 51, 255]
# orange: [255, 153, 51]
print_color_primary=[51, 255, 255] # cyan
print_color_secondary=[51, 255, 153] # green

[editors]
# Use this section to define alternate editors for individual
# file extensions. Set the extension on the right and the command
Expand Down
15 changes: 15 additions & 0 deletions src/defaults/windows_defaults.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ max_history=300
# before displaying the next N shortcuts.
ls_display_block=0

# Choose the primary and secondary colors for formatting printing.
# Use true color format to select the colors.
# Example colors are:
# blue: [51, 153, 255]
# cyan: [51, 255, 255]
# pink: [255, 51, 153]
# red: [255, 51, 51]
# green: [51, 255, 153]
# bright green: [153, 255, 51]
# yellow: [255, 255, 51]
# purple: [153, 51, 255]
# orange: [255, 153, 51]
print_color_primary=[51, 255, 255] # cyan
print_color_secondary=[51, 255, 153] # green

[editors]
# Use this section to define alternate editors for individual
# file extensions. Set the extension on the right and the command
Expand Down
47 changes: 25 additions & 22 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub struct Settings {
pub default_editor: String,
pub max_history: usize,
pub ls_display_block: usize,
pub print_color_primary: Option<[u8; 3]>,
pub print_color_secondary: Option<[u8; 3]>,
}

#[derive(Debug)]
Expand All @@ -44,33 +46,33 @@ impl Env {
home_dir
}
};
let mut hop_config_file = PathBuf::from(&config_dir);
match var("HOP_CONFIG_FILE_NAME") {
Ok(name) => hop_config_file.push(name),
Err(_) => hop_config_file.push("bunnyhop.toml"),
let mut config_file = PathBuf::from(&config_dir);
match var("config_file_NAME") {
Ok(name) => config_file.push(name),
Err(_) => config_file.push("bunnyhop.toml"),
};
let mut database_dir = match var("HOP_DATABASE_DIRECTORY") {
let mut database_file = match var("HOP_DATABASE_DIRECTORY") {
Ok(loc) => PathBuf::from(&loc),
Err(_) => {
let mut db_dir_temp = PathBuf::from(format!("{}", &config_dir.as_path().display()));
db_dir_temp.push("db");
db_dir_temp
}
};
if !Path::new(&database_dir).exists() {
match fs::create_dir_all(&database_dir) {
if !Path::new(&database_file).exists() {
match fs::create_dir_all(&database_file) {
Ok(_) => {}
Err(e) => println!("[error] Error creating database directory: {}", e),
};
};
match var("HOP_DATABASE_FILE_NAME") {
Ok(name) => database_dir.push(name),
Err(_) => database_dir.push("bunnyhop.db"),
Ok(name) => database_file.push(name),
Err(_) => database_file.push("bunnyhop.db"),
};

Env {
config_file: hop_config_file,
database_file: database_dir,
config_file,
database_file,
}
}
}
Expand Down Expand Up @@ -356,12 +358,8 @@ impl Hopper {
Ok(())
}

fn format_lists(&self, hops: Vec<(String, String)>, filter_string: Option<String>) {
let filter_condition = if filter_string.is_some() {
filter_string.unwrap()
} else {
"".to_string()
};
fn print_formatted_maps(&self, hops: Vec<(String, String)>, filter_string: Option<String>) {
let filter_condition = filter_string.unwrap_or("".to_string());
let filtered_hops: Vec<(String, String)> = hops
.into_iter()
.filter(|(n, l)| n.contains(&filter_condition) || l.contains(&filter_condition))
Expand All @@ -371,6 +369,8 @@ impl Hopper {
.map(|(name, _)| name.len())
.max()
.unwrap_or(0);
let first_col = self.config.settings.print_color_primary.unwrap_or([51, 255, 255]);
let sec_col = self.config.settings.print_color_secondary.unwrap_or([51, 255, 153]);
let mut formatted_hops: Vec<String> = filtered_hops
.into_iter()
.map(|(name, location)| {
Expand All @@ -384,10 +384,13 @@ impl Hopper {
.map(|(ws, name, location)| {
format!(
"{}{}{} {}",
name.bold().cyan(),
name.truecolor(first_col[0], first_col[1], first_col[2])
.bold(),
ws,
"->".bright_white().bold(),
location.green().bold()
location
.truecolor(sec_col[0], sec_col[1], sec_col[2])
.bold()
)
})
.collect();
Expand All @@ -414,7 +417,7 @@ impl Hopper {
let location = query_result.read::<String, _>("location")?;
hops.push((name, location));
}
self.format_lists(hops, filter_string);
self.print_formatted_maps(hops, filter_string);
Ok(())
}

Expand Down Expand Up @@ -508,7 +511,7 @@ impl Hopper {

fn show_history(&self, filter_condition: Option<String>) -> anyhow::Result<()> {
let hops = self.retrieve_history()?;
self.format_lists(hops, filter_condition);
self.print_formatted_maps(hops, filter_condition);
Ok(())
}

Expand Down Expand Up @@ -594,7 +597,7 @@ impl Hopper {
.to_string(),
),
];
self.format_lists(loc_vec, None);
self.print_formatted_maps(loc_vec, None);
Ok(())
}
}
Expand Down
Loading

0 comments on commit 25cd5c8

Please sign in to comment.