added support for colouring th background instead of the foreground
This commit is contained in:
parent
c138c047ed
commit
f4d7e60a07
|
|
@ -22,7 +22,14 @@ pub struct Cli {
|
|||
/// Takes priority over '--grayscale'
|
||||
#[arg(short = 'C', long)]
|
||||
pub colour: bool,
|
||||
/// Colour the background instead of the foreground
|
||||
///
|
||||
/// Requires '--colour' or '--grayscale' to be passed
|
||||
#[arg(long)]
|
||||
pub background: bool,
|
||||
/// Display ASCII art in grayscale
|
||||
///
|
||||
/// incompatible with '--color'
|
||||
#[arg(short= 'g', long)]
|
||||
pub grayscale: bool,
|
||||
/// Use braille characters instead of ASCII
|
||||
|
|
@ -67,6 +74,7 @@ impl Cli {
|
|||
pub fn debug_print(&self) {
|
||||
debug!("complex: {}", self.complex);
|
||||
debug!("colour: {}", self.colour);
|
||||
debug!("background: {}", self.background);
|
||||
debug!("grayscale: {}", self.grayscale);
|
||||
debug!("braille: {}", self.braille);
|
||||
debug!("debug: {}", self.debug);
|
||||
|
|
|
|||
12
src/main.rs
12
src/main.rs
|
|
@ -14,12 +14,6 @@ mod ascii_manipulation;
|
|||
mod output;
|
||||
mod model_rgb_ascii;
|
||||
|
||||
//todo:
|
||||
/* custom background color, print font in white
|
||||
* --formats flag
|
||||
* --version flag
|
||||
*/
|
||||
|
||||
/// This is the main function.
|
||||
///
|
||||
/// It drives the CLI module, calls the appropriate convert functions and directs output.
|
||||
|
|
@ -51,6 +45,10 @@ fn main() {
|
|||
if let Some(output) = cli.output {
|
||||
print_file(out, output);
|
||||
} else {
|
||||
print_terminal(out, cli.colour, cli.grayscale);
|
||||
if cli.background && (cli.colour || cli.grayscale) {
|
||||
print_terminal_background(out, cli.colour, cli.grayscale);
|
||||
} else {
|
||||
print_terminal(out, cli.colour, cli.grayscale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use std::io::{stdout, Write};
|
|||
use std::path::PathBuf;
|
||||
use std::process::exit;
|
||||
use crossterm::execute;
|
||||
use crossterm::style::{Color, SetForegroundColor, Print, ResetColor};
|
||||
use crossterm::style::{Color, SetForegroundColor, SetBackgroundColor, Print, ResetColor};
|
||||
use log::error;
|
||||
use crate::model_rgb_ascii::Ascii;
|
||||
|
||||
|
|
@ -13,6 +13,7 @@ use crate::model_rgb_ascii::Ascii;
|
|||
/// arguments:
|
||||
/// art: Vec<Vec<Ascii>> - vector of vectors representing the art
|
||||
/// in_colour: bool - whether to print in colour or as hard white
|
||||
/// grayscale: bool - whether to print grayscale
|
||||
pub fn print_terminal(art: Vec<Vec<Ascii>>, in_colour: bool, grayscale: bool) {
|
||||
for line in art {
|
||||
for ascii in line {
|
||||
|
|
@ -34,6 +35,36 @@ pub fn print_terminal(art: Vec<Vec<Ascii>>, in_colour: bool, grayscale: bool) {
|
|||
}
|
||||
}
|
||||
|
||||
/// This function prints ASCII art to the background of stdout.
|
||||
///
|
||||
/// arguments:
|
||||
/// art: Vec<Vec<Ascii>> - vector of vectors representing the art
|
||||
/// in_colour: bool - whether to print in colour
|
||||
/// grayscale: bool - whether to print grayscale
|
||||
pub fn print_terminal_background(art: Vec<Vec<Ascii>>, in_colour: bool, grayscale: bool) {
|
||||
for line in art {
|
||||
for ascii in line {
|
||||
if in_colour {
|
||||
let _ = execute!(stdout(),
|
||||
SetBackgroundColor(Color::Rgb {r: ascii.rgb[0], g: ascii.rgb[1], b: ascii.rgb[2]}),
|
||||
SetForegroundColor(Color::Rgb {r: 255-ascii.rgb[0], g: 255-ascii.rgb[1], b: 255-ascii.rgb[2]}),
|
||||
Print(ascii.char),
|
||||
ResetColor);
|
||||
} else if grayscale {
|
||||
let _ = execute!(stdout(),
|
||||
SetBackgroundColor(Color::Rgb {r: ascii.col_depth, g: ascii.col_depth, b: ascii.col_depth}),
|
||||
SetForegroundColor(Color::Rgb {r: 255-ascii.col_depth, g: 255-ascii.col_depth, b: 255-ascii.col_depth}),
|
||||
Print(ascii.char),
|
||||
ResetColor);
|
||||
} else {
|
||||
error!("This should be unreachable!");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
println!();
|
||||
}
|
||||
}
|
||||
|
||||
/// This function prints ASCII art to a file.
|
||||
///
|
||||
/// arguments:
|
||||
|
|
|
|||
Loading…
Reference in New Issue