Skip to content

Commit

Permalink
Nicer looking header
Browse files Browse the repository at this point in the history
  • Loading branch information
m42e committed Mar 30, 2022
1 parent 7a4d684 commit 844bd49
Showing 1 changed file with 48 additions and 21 deletions.
69 changes: 48 additions & 21 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,53 @@ fn prepare_entries(location: &Location, grouped: bool, tx_item: SkimItemSender)
drop(tx_item);
}

fn generate_title(location: &Location) -> String {
let extra_info = |theloc: &Location| -> String {
return match theloc {
Location::Session => get_current_session_id(),
Location::Directory => get_current_dir(),
Location::Machine => get_current_host(),
_ => String::from(""),
};
}(&location);

let location_map = enum_map! {
Location::Session => "Session location history",
Location::Directory => "Directory location history",
Location::Machine => "Machine location history",
Location::Everywhere => "Everywhere",
};

let header_map = enum_map! {
Location::Session =>"
┏━━━━━━━━━━━┱─────────────┬────────┬──────────────┐
┃F1: Session┃F2: Directory│F3: Host│F4: Everywhere│ F5: Toggle group
━┛ ┗━━━━━━━━━━━━━┷━━━━━━━━┷━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━",
Location::Directory => "
┌───────────┲━━━━━━━━━━━━━┱────────┬──────────────┐
│F1: Session┃F2: Directory┃F3: Host│F4: Everywhere│ F5: Toggle group
━┷━━━━━━━━━━━┛ ┗━━━━━━━━┷━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━",

Location::Machine => "
┌───────────┬─────────────┲━━━━━━━━┱──────────────┐
│F1: Session│F2: Directory┃F3: Host┃F4: Everywhere│ F5: Toggle group
━┷━━━━━━━━━━━┷━━━━━━━━━━━━━┛ ┗━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━",

Location::Everywhere => "
┌───────────┬─────────────┬────────┲━━━━━━━━━━━━━━┓
│F1: Session│F2: Directory│F3: Host┃F4: Everywhere┃ F5: Toggle group
━┷━━━━━━━━━━━┷━━━━━━━━━━━━━┷━━━━━━━━┛ ┗━━━━━━━━━━━━━━━━━",
};

let title = format!(
"{} {}\n{}\n",
&location_map[location.clone()],
&extra_info,
&header_map[location.clone()],
);
return title.to_string();
}

fn show_history(thequery: String) -> Result<String> {
let mut location = Location::Session;
let mut grouped = true;
Expand All @@ -179,27 +226,7 @@ fn show_history(thequery: String) -> Result<String> {
location = Location::Directory;
}
loop {
let map = enum_map! {
Location::Session => "Session location history",
Location::Directory => "Directory location history",
Location::Machine => "Machine location history",
Location::Everywhere => "Everywhere",
};
let extra_info = |theloc: &Location| -> String {
return match theloc {
Location::Session => get_current_session_id(),
Location::Directory => get_current_dir(),
Location::Machine => get_current_host(),
_ => String::from(""),
};
}(&location);

let title = format!(
"{} {}\n{}\n―――――――――――――――――――――――――",
&map[location.clone()],
&extra_info,
"F1: Session, F2: Directory, F3: Host, F4: Everywhere -- F5: Toggle group"
);
let title = generate_title(&location);

let options = SkimOptionsBuilder::default()
.height(Some("100%"))
Expand Down

0 comments on commit 844bd49

Please sign in to comment.