From 6ea2858495f9e4352b12ea0f64fb38dc32d04c1a Mon Sep 17 00:00:00 2001 From: LordMZTE Date: Sun, 31 Oct 2021 23:28:52 +0100 Subject: [PATCH] add custom prompt --- prompt/.gitignore | 2 ++ prompt/Cargo.toml | 11 +++++++++ prompt/src/main.rs | 20 +++++++++++++++++ prompt/src/theme.rs | 55 +++++++++++++++++++++++++++++++++++++++++++++ rustfmt.toml | 12 ++++++++++ 5 files changed, 100 insertions(+) create mode 100644 prompt/.gitignore create mode 100644 prompt/Cargo.toml create mode 100644 prompt/src/main.rs create mode 100644 prompt/src/theme.rs create mode 100644 rustfmt.toml diff --git a/prompt/.gitignore b/prompt/.gitignore new file mode 100644 index 0000000..2c96eb1 --- /dev/null +++ b/prompt/.gitignore @@ -0,0 +1,2 @@ +target/ +Cargo.lock diff --git a/prompt/Cargo.toml b/prompt/Cargo.toml new file mode 100644 index 0000000..c6b4b3f --- /dev/null +++ b/prompt/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "prompt" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies.powerline] +git = "https://github.com/Gajus84/powerline-rust.git" +default-features = false +features = ["bare-shell", "libgit"] diff --git a/prompt/src/main.rs b/prompt/src/main.rs new file mode 100644 index 0000000..94dcb19 --- /dev/null +++ b/prompt/src/main.rs @@ -0,0 +1,20 @@ +use powerline::{Powerline, modules::{Cmd, Cwd, ExitCode, Git, ReadOnly}}; + +use crate::theme::Theme; + +mod theme; + +fn main() { + let mut main_prompt = Powerline::new(); + + main_prompt.add_module(Cwd::::new(40, 5, false)); + main_prompt.add_module(Git::::new()); + + let mut aux_prompt = Powerline::new(); + + aux_prompt.add_module(ExitCode::::new()); + aux_prompt.add_module(ReadOnly::::new()); + aux_prompt.add_module(Cmd::::new()); + + println!("{}\n{}", main_prompt, aux_prompt); +} diff --git a/prompt/src/theme.rs b/prompt/src/theme.rs new file mode 100644 index 0000000..319ce15 --- /dev/null +++ b/prompt/src/theme.rs @@ -0,0 +1,55 @@ +use powerline::{modules::{CmdScheme, CwdScheme, ExitCodeScheme, GitScheme, ReadOnlyScheme}, terminal::Color}; + +// convenience alias +const fn c(color: u8) -> Color { + Color(color) +} + +pub struct Theme; + +impl CmdScheme for Theme { + const CMD_PASSED_FG: Color = c(4); + const CMD_PASSED_BG: Color = c(2); + const CMD_FAILED_BG: Color = c(1); + const CMD_FAILED_FG: Color = c(7); +} + +impl CwdScheme for Theme { + const CWD_FG: Color = c(0); + const PATH_FG: Color = c(0); + const PATH_BG: Color = c(3); + const HOME_FG: Color = c(0); + const HOME_BG: Color = c(5); + const SEPARATOR_FG: Color = c(4); +} + +impl GitScheme for Theme { + const GIT_AHEAD_BG: Color = c(2); + const GIT_AHEAD_FG: Color = c(0); + const GIT_BEHIND_BG: Color = c(4); + const GIT_BEHIND_FG: Color = c(0); + const GIT_STAGED_BG: Color = c(6); + const GIT_STAGED_FG: Color = c(0); + const GIT_NOTSTAGED_BG: Color = c(4); + const GIT_NOTSTAGED_FG: Color = c(0); + const GIT_UNTRACKED_BG: Color = c(69); + const GIT_UNTRACKED_FG: Color = c(0); + const GIT_CONFLICTED_BG: Color = c(1); + const GIT_CONFLICTED_FG: Color = c(0); + const GIT_REPO_CLEAN_BG: Color = c(4); + const GIT_REPO_CLEAN_FG: Color = c(0); + const GIT_REPO_DIRTY_BG: Color = c(250); + const GIT_REPO_DIRTY_FG: Color = c(0); + const GIT_REPO_ERROR_BG: Color = c(196); + const GIT_REPO_ERROR_FG: Color = c(0); +} + +impl ExitCodeScheme for Theme { + const EXIT_CODE_BG: Color = c(4); + const EXIT_CODE_FG: Color = c(0); +} + +impl ReadOnlyScheme for Theme { + const READONLY_FG: Color = c(1); + const READONLY_BG: Color = c(0); +} diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..1059111 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,12 @@ +unstable_features = true +binop_separator = "Back" +format_code_in_doc_comments = true +format_macro_matchers = true +format_strings = true +imports_layout = "HorizontalVertical" +match_block_trailing_comma = true +merge_imports = true +normalize_comments = true +use_field_init_shorthand = true +use_try_shorthand = true +wrap_comments = true