forked from extern/nushell
Merge pull request #970 from jonathandturner/starship-prompt
Starship prompt
This commit is contained in:
commit
17e8a5ce38
656
Cargo.lock
generated
656
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -87,6 +87,7 @@ rawkey = {version = "0.1.2", optional = true }
|
||||
clipboard = {version = "0.5", optional = true }
|
||||
ptree = {version = "0.2" }
|
||||
image = { version = "0.22.2", default_features = false, features = ["png_codec", "jpeg"], optional = true }
|
||||
starship = { version = "0.26.4", optional = true}
|
||||
|
||||
[features]
|
||||
default = ["textview", "sys", "ps"]
|
||||
@ -95,8 +96,8 @@ textview = ["syntect", "onig_sys", "crossterm"]
|
||||
binaryview = ["image", "crossterm"]
|
||||
sys = ["heim", "battery"]
|
||||
ps = ["heim"]
|
||||
starship-prompt = ["starship"]
|
||||
# trace = ["nom-tracable/trace"]
|
||||
all = ["raw-key", "textview", "binaryview", "sys", "ps", "clipboard"]
|
||||
|
||||
[dependencies.rusqlite]
|
||||
version = "0.20.0"
|
||||
|
19
src/cli.rs
19
src/cli.rs
@ -10,6 +10,7 @@ use crate::data::config;
|
||||
use crate::data::Value;
|
||||
pub(crate) use crate::errors::ShellError;
|
||||
use crate::fuzzysearch::{interactive_fuzzy_search, SelectionResult};
|
||||
#[cfg(not(feature = "starship-prompt"))]
|
||||
use crate::git::current_branch;
|
||||
use crate::parser::registry::Signature;
|
||||
use crate::parser::{
|
||||
@ -394,14 +395,26 @@ pub async fn cli() -> Result<(), Box<dyn Error>> {
|
||||
// Redefine Ctrl-D to same command as Ctrl-C
|
||||
rl.bind_sequence(rustyline::KeyPress::Ctrl('D'), rustyline::Cmd::Interrupt);
|
||||
|
||||
let prompt = &format!(
|
||||
"{}{}> ",
|
||||
let prompt = {
|
||||
#[cfg(feature = "starship-prompt")]
|
||||
{
|
||||
&starship::print::get_prompt(starship::context::Context::new_with_dir(
|
||||
clap::ArgMatches::default(),
|
||||
cwd,
|
||||
))
|
||||
}
|
||||
#[cfg(not(feature = "starship-prompt"))]
|
||||
{
|
||||
&format!(
|
||||
"{}{}\x1b[m> ",
|
||||
cwd,
|
||||
match current_branch() {
|
||||
Some(s) => format!("({})", s),
|
||||
None => "".to_string(),
|
||||
}
|
||||
);
|
||||
)
|
||||
}
|
||||
};
|
||||
let mut initial_command = Some(String::new());
|
||||
let mut readline = Err(ReadlineError::Eof);
|
||||
while let Some(ref cmd) = initial_command {
|
||||
|
@ -1,3 +1,5 @@
|
||||
#![cfg(not(feature = "starship-prompt"))]
|
||||
|
||||
use git2::{Repository, RepositoryOpenFlags};
|
||||
use std::ffi::OsString;
|
||||
|
||||
|
@ -42,7 +42,7 @@ impl Hinter for Helper {
|
||||
|
||||
impl Highlighter for Helper {
|
||||
fn highlight_prompt<'b, 's: 'b, 'p: 'b>(&'s self, prompt: &'p str, _: bool) -> Cow<'b, str> {
|
||||
Owned("\x1b[32m".to_owned() + &prompt[0..prompt.len() - 2] + "\x1b[m> ")
|
||||
Owned("\x1b[32m".to_owned() + &prompt + "\x1b[m")
|
||||
}
|
||||
|
||||
fn highlight_hint<'h>(&self, hint: &'h str) -> Cow<'h, str> {
|
||||
|
Loading…
Reference in New Issue
Block a user