mirror of
https://mzte.de/git/LordMZTE/dotfiles.git
synced 2024-06-01 15:21:01 +02:00
add fish mode to prompt
This commit is contained in:
parent
ee68e3b82f
commit
663d66a3ad
|
@ -57,7 +57,7 @@ end
|
|||
# install custom prompt to ~/.local/bin/prompt (or somewhere else in $PATH)
|
||||
functions -e fish_mode_prompt
|
||||
function fish_prompt
|
||||
prompt $status
|
||||
prompt $status $fish_bind_mode
|
||||
end
|
||||
|
||||
# ENV
|
||||
|
|
102
prompt/src/fish_mode.rs
Normal file
102
prompt/src/fish_mode.rs
Normal file
|
@ -0,0 +1,102 @@
|
|||
use std::marker::PhantomData;
|
||||
|
||||
use powerline::{modules::Module, terminal::Color, Segment};
|
||||
|
||||
pub trait FishModeScheme {
|
||||
const FISH_MODE_DEFAULT_BG: Color;
|
||||
const FISH_MODE_DEFAULT_FG: Color;
|
||||
const FISH_MODE_DEFAULT_STR: &'static str = "N";
|
||||
const FISH_MODE_INSERT_BG: Color;
|
||||
const FISH_MODE_INSERT_FG: Color;
|
||||
const FISH_MODE_INSERT_STR: &'static str = "I";
|
||||
const FISH_MODE_REPLACE_ONE_BG: Color;
|
||||
const FISH_MODE_REPLACE_ONE_FG: Color;
|
||||
const FISH_MODE_REPLACE_ONE_STR: &'static str = "R";
|
||||
const FISH_MODE_REPLACE_BG: Color;
|
||||
const FISH_MODE_REPLACE_FG: Color;
|
||||
const FISH_MODE_REPLACE_STR: &'static str = "R";
|
||||
const FISH_MODE_VISUAL_BG: Color;
|
||||
const FISH_MODE_VISUAL_FG: Color;
|
||||
const FISH_MODE_VISUAL_STR: &'static str = "V";
|
||||
const FISH_MODE_UNKNOWN_BG: Color;
|
||||
const FISH_MODE_UNKNOWN_FG: Color;
|
||||
const FISH_MODE_UNKNOWN_STR: &'static str = "?";
|
||||
}
|
||||
|
||||
pub struct FishMode<T> {
|
||||
mode: FishModeMode,
|
||||
scheme: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl<T: FishModeScheme> FishMode<T> {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
mode: std::env::args()
|
||||
.nth(2)
|
||||
.map(|s| FishModeMode::from_fish_bind_mode(&s))
|
||||
.unwrap_or(FishModeMode::Unknown),
|
||||
scheme: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: FishModeScheme> Module for FishMode<T> {
|
||||
fn append_segments(&mut self, segments: &mut Vec<Segment>) {
|
||||
let (s, bg, fg) = match self.mode {
|
||||
FishModeMode::Default => (
|
||||
T::FISH_MODE_DEFAULT_STR,
|
||||
T::FISH_MODE_DEFAULT_BG,
|
||||
T::FISH_MODE_DEFAULT_FG,
|
||||
),
|
||||
FishModeMode::Insert => (
|
||||
T::FISH_MODE_INSERT_STR,
|
||||
T::FISH_MODE_INSERT_BG,
|
||||
T::FISH_MODE_INSERT_FG,
|
||||
),
|
||||
FishModeMode::Replace => (
|
||||
T::FISH_MODE_REPLACE_STR,
|
||||
T::FISH_MODE_REPLACE_BG,
|
||||
T::FISH_MODE_REPLACE_FG,
|
||||
),
|
||||
FishModeMode::ReplaceOne => (
|
||||
T::FISH_MODE_REPLACE_ONE_STR,
|
||||
T::FISH_MODE_REPLACE_ONE_BG,
|
||||
T::FISH_MODE_REPLACE_ONE_FG,
|
||||
),
|
||||
FishModeMode::Visual => (
|
||||
T::FISH_MODE_VISUAL_STR,
|
||||
T::FISH_MODE_VISUAL_BG,
|
||||
T::FISH_MODE_VISUAL_FG,
|
||||
),
|
||||
FishModeMode::Unknown => (
|
||||
T::FISH_MODE_UNKNOWN_STR,
|
||||
T::FISH_MODE_UNKNOWN_BG,
|
||||
T::FISH_MODE_UNKNOWN_FG,
|
||||
),
|
||||
};
|
||||
|
||||
segments.push(Segment::simple(s, fg, bg));
|
||||
}
|
||||
}
|
||||
|
||||
enum FishModeMode {
|
||||
Default,
|
||||
Insert,
|
||||
ReplaceOne,
|
||||
Replace,
|
||||
Visual,
|
||||
Unknown,
|
||||
}
|
||||
|
||||
impl FishModeMode {
|
||||
fn from_fish_bind_mode(mode: &str) -> Self {
|
||||
match mode {
|
||||
"default" => Self::Default,
|
||||
"insert" => Self::Insert,
|
||||
"replace_one" => Self::ReplaceOne,
|
||||
"replace" => Self::Replace,
|
||||
"visual" => Self::Visual,
|
||||
_ => Self::Unknown,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,11 @@
|
|||
use powerline::{Powerline, modules::{Cmd, Cwd, ExitCode, Git, ReadOnly}};
|
||||
use powerline::{
|
||||
modules::{Cmd, Cwd, ExitCode, Git, ReadOnly},
|
||||
Powerline,
|
||||
};
|
||||
|
||||
use crate::theme::Theme;
|
||||
use crate::{fish_mode::FishMode, theme::Theme};
|
||||
|
||||
mod fish_mode;
|
||||
mod theme;
|
||||
|
||||
fn main() {
|
||||
|
@ -10,6 +14,7 @@ fn main() {
|
|||
prompt.add_module(ReadOnly::<Theme>::new());
|
||||
prompt.add_module(Cwd::<Theme>::new(40, 5, false));
|
||||
prompt.add_module(Git::<Theme>::new());
|
||||
prompt.add_module(FishMode::<Theme>::new());
|
||||
prompt.add_module(ExitCode::<Theme>::new());
|
||||
prompt.add_module(Cmd::<Theme>::new());
|
||||
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
use powerline::{modules::{CmdScheme, CwdScheme, ExitCodeScheme, GitScheme, ReadOnlyScheme}, terminal::Color};
|
||||
use powerline::{
|
||||
modules::{CmdScheme, CwdScheme, ExitCodeScheme, GitScheme, ReadOnlyScheme},
|
||||
terminal::Color,
|
||||
};
|
||||
|
||||
use crate::fish_mode::FishModeScheme;
|
||||
|
||||
// convenience alias
|
||||
const fn c(color: u8) -> Color {
|
||||
|
@ -53,3 +58,18 @@ impl ReadOnlyScheme for Theme {
|
|||
const READONLY_FG: Color = c(1);
|
||||
const READONLY_BG: Color = c(0);
|
||||
}
|
||||
|
||||
impl FishModeScheme for Theme {
|
||||
const FISH_MODE_DEFAULT_BG: Color = c(3);
|
||||
const FISH_MODE_DEFAULT_FG: Color = c(0);
|
||||
const FISH_MODE_INSERT_BG: Color = c(2);
|
||||
const FISH_MODE_INSERT_FG: Color = c(0);
|
||||
const FISH_MODE_REPLACE_ONE_BG: Color = c(5);
|
||||
const FISH_MODE_REPLACE_ONE_FG: Color = c(0);
|
||||
const FISH_MODE_REPLACE_BG: Color = c(4);
|
||||
const FISH_MODE_REPLACE_FG: Color = c(0);
|
||||
const FISH_MODE_VISUAL_BG: Color = c(5);
|
||||
const FISH_MODE_VISUAL_FG: Color = c(0);
|
||||
const FISH_MODE_UNKNOWN_BG: Color = c(1);
|
||||
const FISH_MODE_UNKNOWN_FG: Color = c(0);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue