Skip to content

Commit 25cd5c8

Browse files
authored
Merge pull request #13 from UnsafeOats/clean_up
cleaned up a bit and added color selection options
2 parents 75b5771 + 3d7f9c8 commit 25cd5c8

9 files changed

+62
-214
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bhop"
3-
version = "0.5.3"
3+
version = "0.5.4"
44
edition = "2021"
55
authors = ["Shane Stephenson <[email protected]>"]
66
readme = "README.md"

Makefile

-40
This file was deleted.

runners/add_runners.py

-148
This file was deleted.

runners/add_runners.rs

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
// With all these updates in place, the current build system should start configuring the new shell
3131
// for use.
3232
use dirs::home_dir;
33-
use dos2unix;
3433
use std::{
3534
env::var,
3635
fs::{read_to_string, OpenOptions},

src/defaults/unix_defaults.toml

+15
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,21 @@ max_history=300
2121
# before displaying the next N shortcuts.
2222
ls_display_block=0
2323

24+
# Choose the primary and secondary colors for formatting printing.
25+
# Use true color format to select the coloring.
26+
# Example colors are:
27+
# blue: [51, 153, 255]
28+
# cyan: [51, 255, 255]
29+
# pink: [255, 51, 153]
30+
# red: [255, 51, 51]
31+
# green: [51, 255, 153]
32+
# bright green: [153, 255, 51]
33+
# yellow: [255, 255, 51]
34+
# purple: [153, 51, 255]
35+
# orange: [255, 153, 51]
36+
print_color_primary=[51, 255, 255] # cyan
37+
print_color_secondary=[51, 255, 153] # green
38+
2439
[editors]
2540
# Use this section to define alternate editors for individual
2641
# file extensions. Set the extension on the right and the command

src/defaults/windows_defaults.toml

+15
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@ max_history=300
2525
# before displaying the next N shortcuts.
2626
ls_display_block=0
2727

28+
# Choose the primary and secondary colors for formatting printing.
29+
# Use true color format to select the colors.
30+
# Example colors are:
31+
# blue: [51, 153, 255]
32+
# cyan: [51, 255, 255]
33+
# pink: [255, 51, 153]
34+
# red: [255, 51, 51]
35+
# green: [51, 255, 153]
36+
# bright green: [153, 255, 51]
37+
# yellow: [255, 255, 51]
38+
# purple: [153, 51, 255]
39+
# orange: [255, 153, 51]
40+
print_color_primary=[51, 255, 255] # cyan
41+
print_color_secondary=[51, 255, 153] # green
42+
2843
[editors]
2944
# Use this section to define alternate editors for individual
3045
# file extensions. Set the extension on the right and the command

src/lib.rs

+25-22
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ pub struct Settings {
2525
pub default_editor: String,
2626
pub max_history: usize,
2727
pub ls_display_block: usize,
28+
pub print_color_primary: Option<[u8; 3]>,
29+
pub print_color_secondary: Option<[u8; 3]>,
2830
}
2931

3032
#[derive(Debug)]
@@ -44,33 +46,33 @@ impl Env {
4446
home_dir
4547
}
4648
};
47-
let mut hop_config_file = PathBuf::from(&config_dir);
48-
match var("HOP_CONFIG_FILE_NAME") {
49-
Ok(name) => hop_config_file.push(name),
50-
Err(_) => hop_config_file.push("bunnyhop.toml"),
49+
let mut config_file = PathBuf::from(&config_dir);
50+
match var("config_file_NAME") {
51+
Ok(name) => config_file.push(name),
52+
Err(_) => config_file.push("bunnyhop.toml"),
5153
};
52-
let mut database_dir = match var("HOP_DATABASE_DIRECTORY") {
54+
let mut database_file = match var("HOP_DATABASE_DIRECTORY") {
5355
Ok(loc) => PathBuf::from(&loc),
5456
Err(_) => {
5557
let mut db_dir_temp = PathBuf::from(format!("{}", &config_dir.as_path().display()));
5658
db_dir_temp.push("db");
5759
db_dir_temp
5860
}
5961
};
60-
if !Path::new(&database_dir).exists() {
61-
match fs::create_dir_all(&database_dir) {
62+
if !Path::new(&database_file).exists() {
63+
match fs::create_dir_all(&database_file) {
6264
Ok(_) => {}
6365
Err(e) => println!("[error] Error creating database directory: {}", e),
6466
};
6567
};
6668
match var("HOP_DATABASE_FILE_NAME") {
67-
Ok(name) => database_dir.push(name),
68-
Err(_) => database_dir.push("bunnyhop.db"),
69+
Ok(name) => database_file.push(name),
70+
Err(_) => database_file.push("bunnyhop.db"),
6971
};
7072

7173
Env {
72-
config_file: hop_config_file,
73-
database_file: database_dir,
74+
config_file,
75+
database_file,
7476
}
7577
}
7678
}
@@ -356,12 +358,8 @@ impl Hopper {
356358
Ok(())
357359
}
358360

359-
fn format_lists(&self, hops: Vec<(String, String)>, filter_string: Option<String>) {
360-
let filter_condition = if filter_string.is_some() {
361-
filter_string.unwrap()
362-
} else {
363-
"".to_string()
364-
};
361+
fn print_formatted_maps(&self, hops: Vec<(String, String)>, filter_string: Option<String>) {
362+
let filter_condition = filter_string.unwrap_or("".to_string());
365363
let filtered_hops: Vec<(String, String)> = hops
366364
.into_iter()
367365
.filter(|(n, l)| n.contains(&filter_condition) || l.contains(&filter_condition))
@@ -371,6 +369,8 @@ impl Hopper {
371369
.map(|(name, _)| name.len())
372370
.max()
373371
.unwrap_or(0);
372+
let first_col = self.config.settings.print_color_primary.unwrap_or([51, 255, 255]);
373+
let sec_col = self.config.settings.print_color_secondary.unwrap_or([51, 255, 153]);
374374
let mut formatted_hops: Vec<String> = filtered_hops
375375
.into_iter()
376376
.map(|(name, location)| {
@@ -384,10 +384,13 @@ impl Hopper {
384384
.map(|(ws, name, location)| {
385385
format!(
386386
"{}{}{} {}",
387-
name.bold().cyan(),
387+
name.truecolor(first_col[0], first_col[1], first_col[2])
388+
.bold(),
388389
ws,
389390
"->".bright_white().bold(),
390-
location.green().bold()
391+
location
392+
.truecolor(sec_col[0], sec_col[1], sec_col[2])
393+
.bold()
391394
)
392395
})
393396
.collect();
@@ -414,7 +417,7 @@ impl Hopper {
414417
let location = query_result.read::<String, _>("location")?;
415418
hops.push((name, location));
416419
}
417-
self.format_lists(hops, filter_string);
420+
self.print_formatted_maps(hops, filter_string);
418421
Ok(())
419422
}
420423

@@ -508,7 +511,7 @@ impl Hopper {
508511

509512
fn show_history(&self, filter_condition: Option<String>) -> anyhow::Result<()> {
510513
let hops = self.retrieve_history()?;
511-
self.format_lists(hops, filter_condition);
514+
self.print_formatted_maps(hops, filter_condition);
512515
Ok(())
513516
}
514517

@@ -594,7 +597,7 @@ impl Hopper {
594597
.to_string(),
595598
),
596599
];
597-
self.format_lists(loc_vec, None);
600+
self.print_formatted_maps(loc_vec, None);
598601
Ok(())
599602
}
600603
}

0 commit comments

Comments
 (0)