work in progress
This commit is contained in:
+82
-31
@@ -1,63 +1,80 @@
|
||||
use std::io::{Error, Result};
|
||||
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Format {
|
||||
// reset both style and color
|
||||
reset_all: String,
|
||||
/// escape character to start a sequence
|
||||
pub escape: String,
|
||||
|
||||
// text style
|
||||
style: Styles,
|
||||
/// prefix = escape + '['
|
||||
pub prefix: String,
|
||||
|
||||
// text color
|
||||
color: Colors,
|
||||
/// reset both style and color
|
||||
pub reset_all: String,
|
||||
|
||||
/// text style
|
||||
pub style: Styles,
|
||||
|
||||
/// text color
|
||||
pub color: Colors,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Styles {
|
||||
// set style
|
||||
set: StyleCodes,
|
||||
/// set style
|
||||
pub set: StyleCodes,
|
||||
|
||||
// reset style
|
||||
reset: StyleCodes,
|
||||
/// reset style
|
||||
pub reset: StyleCodes,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct StyleCodes {
|
||||
bold: String,
|
||||
dim: String,
|
||||
italic: String,
|
||||
underline: String,
|
||||
blink: String,
|
||||
reverse: String,
|
||||
invisible: String,
|
||||
strikethrough: String,
|
||||
pub bold: String,
|
||||
pub dim: String,
|
||||
pub italic: String,
|
||||
pub underline: String,
|
||||
pub blink: String,
|
||||
pub reverse: String,
|
||||
pub invisible: String,
|
||||
pub strikethrough: String,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Colors {
|
||||
foreground: ColorCodes,
|
||||
background: ColorCodes,
|
||||
pub foreground: ColorCodes,
|
||||
pub background: ColorCodes,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ColorCodes {
|
||||
black: String,
|
||||
red: String,
|
||||
green: String,
|
||||
yellow: String,
|
||||
blue: String,
|
||||
magenta: String,
|
||||
cyan: String,
|
||||
white: String,
|
||||
default: String,
|
||||
pub black: String,
|
||||
pub red: String,
|
||||
pub green: String,
|
||||
pub yellow: String,
|
||||
pub blue: String,
|
||||
pub magenta: String,
|
||||
pub cyan: String,
|
||||
pub white: String,
|
||||
pub default: String,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
impl Format {
|
||||
const ESC: &str = "\x1B";
|
||||
const PREFIX: &str = "\x1B[";
|
||||
pub const ESC: &str = "\x1B";
|
||||
pub const PREFIX: &str = "\x1B[";
|
||||
pub const TERMINATION: &str = "m";
|
||||
pub const RESET_STYLE: &str = "\x1B[0m";
|
||||
|
||||
pub fn new() -> Format {
|
||||
Format {
|
||||
escape: String::from(Self::ESC),
|
||||
prefix: String::from(Self::PREFIX),
|
||||
reset_all: String::from("0"),
|
||||
style: Styles {
|
||||
set: StyleCodes {
|
||||
@@ -108,4 +125,38 @@ impl Format {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generate_style_sequence(
|
||||
&self,
|
||||
style: Option<&Vec<String>>,
|
||||
foreground: Option<&String>,
|
||||
background: Option<&String>,
|
||||
) -> Result<String> {
|
||||
if style.is_none() && foreground.is_none() && background.is_none() {
|
||||
return Err(Error::other("-- generate_style_sequence called without arguments"));
|
||||
}
|
||||
|
||||
// assemble sequence if called with arguments
|
||||
let mut sequence = Vec::<String>::new();
|
||||
if let Some(item) = style {
|
||||
sequence.push_str(item);
|
||||
sequence.push(';');
|
||||
}
|
||||
if let Some(item) = foreground {
|
||||
sequence.push_str(item);
|
||||
sequence.push(';');
|
||||
}
|
||||
if let Some(item) = background {
|
||||
sequence.push_str(item);
|
||||
sequence.push(';');
|
||||
}
|
||||
sequence.pop(); // remove final semicolon
|
||||
sequence.push_str(Self::TERMINATION); // terminate sequence
|
||||
|
||||
sequence
|
||||
}
|
||||
|
||||
pub fn generate_rgb_sequence(&self, ) -> String {
|
||||
|
||||
String::from("hi")
|
||||
}
|
||||
}
|
||||
|
||||
+19
-8
@@ -1,11 +1,12 @@
|
||||
mod arguments;
|
||||
mod config;
|
||||
mod stack;
|
||||
mod format;
|
||||
mod stack;
|
||||
|
||||
use arguments::*;
|
||||
use clap::Parser;
|
||||
use config::Config;
|
||||
use format::Format;
|
||||
use stack::Stack;
|
||||
use std::env::{current_dir, var};
|
||||
use std::io::{Error, Result};
|
||||
@@ -13,10 +14,14 @@ use std::path::{Path, PathBuf};
|
||||
use std::str::FromStr;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let format: Format = format::Format::new();
|
||||
let args = match Arguments::try_parse() {
|
||||
Ok(a) => a,
|
||||
Err(e) => {
|
||||
print!("echo '{}'", e);
|
||||
print!(
|
||||
"echo '{}{}m{}{}{}m'",
|
||||
format.prefix, format.color.foreground.red, e, format.prefix, format.reset_all
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
@@ -35,7 +40,14 @@ fn main() -> Result<()> {
|
||||
};
|
||||
|
||||
if res.is_err() {
|
||||
print!("echo '{}'", res.unwrap_err());
|
||||
print!(
|
||||
"echo '{}{}m{}{}{}m'",
|
||||
format.prefix,
|
||||
format.color.foreground.red,
|
||||
res.unwrap_err(),
|
||||
format.prefix,
|
||||
format.reset_all
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -95,16 +107,15 @@ fn handle_bookmark(args: &BookmarkArgs, stack: &mut Stack) -> Result<()> {
|
||||
BookmarkAction::remove(args) => remove_bookmarks(&args, &mut config)?,
|
||||
};
|
||||
} else if args.name.is_some() {
|
||||
let path = match config
|
||||
.get_bookmarks()
|
||||
.get(args.name.as_ref().unwrap())
|
||||
{
|
||||
let path = match config.get_bookmarks().get(args.name.as_ref().unwrap()) {
|
||||
Some(value) => value,
|
||||
None => return Err(Error::other("requested bookmark does not exist")),
|
||||
};
|
||||
push_path(path, stack)?;
|
||||
} else {
|
||||
return Err(Error::other("-- provide either a `subcommand` or a `bookmark name`"));
|
||||
return Err(Error::other(
|
||||
"-- provide either a `subcommand` or a `bookmark name`",
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user