Remove --c-overlay option

It no longer serves any purpose.
This commit is contained in:
Teoh Han Hui 2024-07-25 04:10:31 +08:00
parent fe7ed923ea
commit cbe176ff4e
No known key found for this signature in database
GPG key ID: D43E2BABAF97DCAE
5 changed files with 55 additions and 67 deletions

View file

@ -1,3 +1,4 @@
use std::fmt::Write as _;
use std::path::Path;
use std::{env, fs};
@ -67,12 +68,14 @@ pub enum Distro {
.to_owned();
for (variant, AsciiDistro { pattern, .. }) in &variants {
buf.push_str(&format!(
write!(
buf,
r###"
// {pattern})
{variant},
"###,
));
)
.unwrap();
}
buf.push_str(
@ -134,13 +137,15 @@ impl Distro {
let condition = conds.join(" || ");
buf.push_str(&format!(
write!(
buf,
r###"
if {condition} {{
return Some(Self::{variant});
}}
"###
));
)
.unwrap();
}
buf.push_str(
@ -155,13 +160,15 @@ impl Distro {
let quotes = "#".repeat(80);
for (variant, AsciiDistro { art, .. }) in &variants {
buf.push_str(&format!(
write!(
buf,
r###"
Self::{variant} => r{quotes}"
{art}
"{quotes},
"###,
));
)
.unwrap();
}
buf.push_str(

View file

@ -57,7 +57,6 @@ fn main() -> Result<()> {
let distro = options.distro.as_ref();
let backend = options.backend.unwrap_or(Backend::Neofetch);
let use_overlay = options.overlay;
if options.test_print {
let (asc, _) = get_distro_ascii(distro, backend).context("failed to get distro ascii")?;
@ -66,27 +65,15 @@ fn main() -> Result<()> {
}
let config = if options.config {
create_config(
&options.config_file,
distro,
backend,
use_overlay,
debug_mode,
)
.context("failed to create config")?
create_config(&options.config_file, distro, backend, debug_mode)
.context("failed to create config")?
} else if let Some(config) =
load_config(&options.config_file).context("failed to load config")?
{
config
} else {
create_config(
&options.config_file,
distro,
backend,
use_overlay,
debug_mode,
)
.context("failed to create config")?
create_config(&options.config_file, distro, backend, debug_mode)
.context("failed to create config")?
};
let color_mode = options.mode.unwrap_or(config.mode);
@ -134,7 +121,7 @@ fn main() -> Result<()> {
} else if let Some(lightness) = options.lightness {
color_profile.with_lightness(AssignLightness::Replace(lightness))
} else {
color_profile.with_lightness_adaptive(config.lightness(), theme, use_overlay)
color_profile.with_lightness_adaptive(config.lightness(), theme)
};
debug!(?color_profile, "lightened color profile");
@ -205,7 +192,6 @@ pub fn create_config(
path: &PathBuf,
distro: Option<&String>,
backend: Backend,
use_overlay: bool,
debug_mode: bool,
) -> Result<Config> {
// Detect terminal environment (doesn't work for all terminal emulators,
@ -536,7 +522,7 @@ pub fn create_config(
let default_lightness = Config::default_lightness(theme);
let preset_default_colored = default_color_profile
.with_lightness_adaptive(default_lightness, theme, use_overlay)
.with_lightness_adaptive(default_lightness, theme)
.color_text(
"preset",
color_mode,
@ -589,7 +575,7 @@ pub fn create_config(
&mut option_counter,
"Selected flag",
&color_profile
.with_lightness_adaptive(default_lightness, theme, use_overlay)
.with_lightness_adaptive(default_lightness, theme)
.color_text(
preset.as_ref(),
color_mode,
@ -667,7 +653,6 @@ pub fn create_config(
Lightness::new(r)
.expect("generated lightness should not be invalid"),
theme,
use_overlay,
),
color_mode,
theme,
@ -736,7 +721,7 @@ pub fn create_config(
let lightness = select_lightness().context("failed to select lightness")?;
debug!(?lightness, "selected lightness");
let color_profile = color_profile.with_lightness_adaptive(lightness, theme, use_overlay);
let color_profile = color_profile.with_lightness_adaptive(lightness, theme);
update_title(
&mut title,
&mut option_counter,

View file

@ -22,7 +22,6 @@ pub struct Options {
pub args: Option<Vec<String>>,
pub scale: Option<f32>,
pub lightness: Option<Lightness>,
pub overlay: bool,
pub june: bool,
pub debug: bool,
pub distro: Option<String>,
@ -122,9 +121,6 @@ BACKEND={{{backends}}}",
.help("Set lightness value of the colors")
.argument("LIGHTNESS")
.optional();
let overlay = long("c-overlay")
.help("Use experimental overlay color adjusting instead of HSL lightness")
.switch();
let june = long("june").help("Show pride month easter egg").switch();
let debug = long("debug").help("Debug mode").switch();
let distro = long("distro")
@ -160,7 +156,6 @@ BACKEND={{{backends}}}",
args,
scale,
lightness,
overlay,
june,
debug,
distro,

View file

@ -639,16 +639,7 @@ impl ColorProfile {
/// Creates a new color profile, with the colors set to the specified
/// [`Okhsl`] lightness value, adapted to the terminal theme.
pub fn with_lightness_adaptive(
&self,
lightness: Lightness,
theme: TerminalTheme,
use_overlay: bool,
) -> Self {
if use_overlay {
todo!()
}
pub fn with_lightness_adaptive(&self, lightness: Lightness, theme: TerminalTheme) -> Self {
match theme {
TerminalTheme::Dark => self.with_lightness(AssignLightness::ClampMin(lightness)),
TerminalTheme::Light => self.with_lightness(AssignLightness::ClampMax(lightness)),

View file

@ -25,7 +25,6 @@ const TEXT_ASCII: &str = r"
const NOTICE: &str = "Press enter to continue";
#[allow(clippy::too_many_lines)]
pub fn start_animation(color_mode: AnsiMode) -> Result<()> {
let key_pressed = Arc::new(AtomicBool::new(false));
@ -52,26 +51,30 @@ pub fn start_animation(color_mode: AnsiMode) -> Result<()> {
let text = &TEXT_ASCII[1..TEXT_ASCII.len() - 1];
let text_lines: Vec<&str> = text.lines().collect();
let text_height: usize = text_lines.len();
let text_width: usize = text_lines[0].len();
let (text_width, text_height) = {
let text_height = text_lines.len();
let text_height = u8::try_from(text_height).expect("`text_height` should fit in `u8`");
let text_width = text_lines[0].len();
let text_width = u8::try_from(text_width).expect("`text_width` should fit in `u8`");
(text_width, text_height)
};
let speed = 2;
const SPEED: u8 = 2;
let frame_delay = Duration::from_secs_f32(1.0 / 25.0);
let mut frame: usize = 0;
let (w, h) = terminal_size()
.map(|(Width(w), Height(h))| (usize::from(w), usize::from(h)))
.context("failed to get terminal size")?;
const BLOCKS: usize = 9;
let block_width: usize = w / BLOCKS;
let (Width(w), Height(h)) = terminal_size().context("failed to get terminal size")?;
const BLOCKS: u8 = 9;
let block_width = w / u16::from(BLOCKS);
let text_start_y = (h / 2) - (text_height / 2);
let text_end_y = text_start_y + text_height;
let text_start_x = (w / 2) - (text_width / 2);
let text_end_x = text_start_x + text_width;
let text_start_y = (h / 2) - u16::from(text_height / 2);
let text_end_y = text_start_y + u16::from(text_height);
let text_start_x = (w / 2) - u16::from(text_width / 2);
let text_end_x = text_start_x + u16::from(text_width);
let notice_start_x = w - NOTICE.len() - 1;
let notice_start_x =
w - u16::from(u8::try_from(NOTICE.len()).expect("`NOTICE` length should fit in `u8`")) - 1;
let notice_end_x = w - 1;
let notice_y = h - 1;
@ -92,26 +95,33 @@ pub fn start_animation(color_mode: AnsiMode) -> Result<()> {
// Loop over the height
for y in 0..h {
// Print the starting color
buf += &colors[((frame + y) / block_width) % colors.len()]
buf += &colors[((frame + usize::from(y)) / usize::from(block_width)) % colors.len()]
.to_ansi_string(color_mode, ForegroundBackground::Background);
buf += &fg.to_ansi_string(color_mode, ForegroundBackground::Foreground);
// Loop over the width
for x in 0..w {
let idx = frame + x + y + (2.0 * (y as f64 + 0.5 * frame as f64).sin()) as usize;
let idx = frame
+ usize::from(x)
+ usize::from(y)
+ (2.0 * (y as f64 + 0.5 * frame as f64).sin()) as usize;
let y_text = text_start_y <= y && y < text_end_y;
let border = 1 + usize::from(!(y == text_start_y || y == text_end_y - 1));
let border = 1 + if y == text_start_y || y == text_end_y - 1 {
0
} else {
1
};
// If it's a switching point
if idx % block_width == 0
if idx % usize::from(block_width) == 0
|| x == text_start_x - border
|| x == text_end_x + border
|| x == notice_start_x - 1
|| x == notice_end_x + 1
{
// Print the color at the current frame
let c = colors[(idx / block_width) % colors.len()];
let c = colors[(idx / usize::from(block_width)) % colors.len()];
if (y_text && (text_start_x - border <= x) && (x < text_end_x + border))
|| (y == notice_y && notice_start_x - 1 <= x && x < notice_end_x + 1)
{
@ -128,13 +138,13 @@ pub fn start_animation(color_mode: AnsiMode) -> Result<()> {
// If text should be printed, print text
if y_text && text_start_x <= x && x < text_end_x {
buf.push(
text_lines[y - text_start_y]
text_lines[usize::from(y - text_start_y)]
.chars()
.nth(x - text_start_x)
.nth(usize::from(x - text_start_x))
.unwrap(),
);
} else if y == notice_y && notice_start_x <= x && x < notice_end_x {
buf.push(NOTICE.chars().nth(x - notice_start_x).unwrap());
buf.push(NOTICE.chars().nth(usize::from(x - notice_start_x)).unwrap());
} else {
buf.push(' ');
}
@ -159,7 +169,7 @@ pub fn start_animation(color_mode: AnsiMode) -> Result<()> {
clear_screen(None, color_mode, false).context("failed to clear screen")?;
draw_frame(frame)?;
frame += speed;
frame += usize::from(SPEED);
thread::sleep(frame_delay);
// TODO: handle Ctrl+C so that we can clear the screen; but we don't have a nice