~kennylevinsen/public-inbox

wlgreet: Change the hard coded color of headline and prompt to configurable ones. v1 APPLIED

Thank you for your work!

This patchset enables user to change the
color of the headline and prompt text via `config.toml`.

I'm new to
sourcehut and its way to contribute to upstream, so I apologize in
advance if I make any mistakes.

Tony Fettes (1):
  Add configurable color to headline and prompt

 config.toml          | 24 ++++++++++++++++++++++++
 src/config.rs        | 26 +++++++++++++++++++++++++-
 src/widgets/login.rs | 26 ++++++++------------------
 3 files changed, 57 insertions(+), 19 deletions(-)

-- 
2.30.2
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~kennylevinsen/public-inbox/patches/21732/mbox | git am -3
Learn more about email & git

[PATCH wlgreet 1/1] Add configurable color to headline and prompt Export this patch

From: Tony Fettes <tonyfettes@tonyfettes.com>

---
 config.toml          | 24 ++++++++++++++++++++++++
 src/config.rs        | 26 +++++++++++++++++++++++++-
 src/widgets/login.rs | 26 ++++++++------------------
 3 files changed, 57 insertions(+), 19 deletions(-)

diff --git a/config.toml b/config.toml
index a1f0d15..a13b9ae 100644
--- a/config.toml
+++ b/config.toml
@@ -7,3 +7,27 @@ red = 0
green = 0
blue = 0
opacity = 0.9

[headline]
red = 1.0
green = 1.0
blue = 1.0
opacity = 1.0

[prompt]
red = 1.0
green = 1.0
blue = 1.0
opacity = 1.0

[promptErr]
red = 1.0
green = 1.0
blue = 1.0
opacity = 1.0

[border]
red = 1.0
green = 1.0
blue = 1.0
opacity = 1.0
diff --git a/src/config.rs b/src/config.rs
index 583060c..4994933 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -27,6 +27,18 @@ fn default_background() -> Color {
fn default_cmd() -> String {
    "".to_string()
}
fn default_headline() -> Color {
    Color::new(1.0, 1.0, 1.0, 1.0)
}
fn default_prompt() -> Color {
    Color::new(1.0, 1.0, 1.0, 1.0)
}
fn default_prompt_err() -> Color {
    Color::new(1.0, 1.0, 1.0, 1.0)
}
fn default_border() -> Color {
    Color::new(1.0, 1.0, 1.0, 1.0)
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
@@ -37,6 +49,14 @@ pub struct Config {
    pub scale: u32,
    #[serde(default = "default_background")]
    pub background: Color,
    #[serde(default = "default_headline")]
    pub headline: Color,
    #[serde(default = "default_prompt")]
    pub prompt: Color,
    #[serde(default = "default_prompt_err")]
    pub prompt_err: Color,
    #[serde(default = "default_border")]
    pub border: Color,
    #[serde(default = "default_cmd")]
    pub command: String,
}
@@ -47,6 +67,10 @@ impl Default for Config {
            output_mode: Default::default(),
            scale: 1,
            background: Color::new(0.0, 0.0, 0.0, 0.9),
            headline: Color::new(1.0, 1.0, 1.0, 1.0),
            prompt: Color::new(1.0, 1.0, 1.0, 1.0),
            prompt_err: Color::new(1.0, 1.0, 1.0, 1.0),
            border: Color::new(1.0, 1.0, 1.0, 1.0),
            command: "".to_string(),
        }
    }
@@ -66,7 +90,7 @@ pub fn read_config() -> Config {
    opts.optopt("e", "command", "command to run", "COMMAND");
    let matches = match opts.parse(&args[1..]) {
        Ok(m) => m,
        Err(f) => panic!(f.to_string()),
        Err(f) => panic!("{}", f.to_string()),
    };
    if matches.opt_present("h") {
        print_usage(&program, opts);
diff --git a/src/widgets/login.rs b/src/widgets/login.rs
index 8fea57f..cbb6bd2 100644
--- a/src/widgets/login.rs
+++ b/src/widgets/login.rs
@@ -1,4 +1,3 @@
use crate::color::Color;
use crate::draw::{draw_box, Font, DEJAVUSANS_MONO};
use crate::widget::{DrawContext, DrawReport, KeyState, ModifiersState, Widget};

@@ -42,11 +41,9 @@ pub struct Login {
    command: String,
    mode: Option<AuthMessageType>,
    error: String,
    border: Color,
    headline_font: Font,
    prompt_font: Font,
    dirty: bool,
    reset_border: bool,
    stream: Option<UnixStream>,
}

@@ -60,9 +57,7 @@ impl Login {
            error: "".to_string(),
            headline_font: Font::new(&DEJAVUSANS_MONO, 72.0),
            prompt_font: Font::new(&DEJAVUSANS_MONO, 32.0),
            border: Color::new(1.0, 1.0, 1.0, 1.0),
            dirty: false,
            reset_border: false,
            stream: None,
        };
        l.reset();
@@ -179,19 +174,19 @@ impl Widget for Login {
        self.dirty = false;
        let mut buf = ctx.buf.subdimensions((0, 0, width, height))?;
        buf.memset(&ctx.bg);
        draw_box(&mut buf, &self.border, (width, height))?;
        draw_box(&mut buf, &ctx.config.border, (width, height))?;

        self.headline_font.auto_draw_text(
            &mut buf.offset((32, 24))?,
            &ctx.bg,
            &Color::new(1.0, 1.0, 1.0, 1.0),
            &ctx.config.headline,
            "Login",
        )?;

        let (w, _) = self.prompt_font.auto_draw_text(
            &mut buf.offset((256, 24))?,
            &ctx.bg,
            &Color::new(1.0, 1.0, 1.0, 1.0),
            &ctx.config.prompt,
            &self.question,
        )?;

@@ -200,7 +195,7 @@ impl Widget for Login {
                self.prompt_font.auto_draw_text(
                    &mut buf.subdimensions((256 + w + 16, 24, width - 416 - 32, 64))?,
                    &ctx.bg,
                    &Color::new(1.0, 1.0, 1.0, 1.0),
                    &ctx.config.prompt,
                    &format!("{}", self.answer),
                )?;
            }
@@ -212,7 +207,7 @@ impl Widget for Login {
                self.prompt_font.auto_draw_text(
                    &mut buf.subdimensions((256 + w + 16, 24, width - 416 - 32, 64))?,
                    &ctx.bg,
                    &Color::new(1.0, 1.0, 1.0, 1.0),
                    &ctx.config.prompt,
                    &stars,
                )?;
            }
@@ -223,19 +218,14 @@ impl Widget for Login {
            self.prompt_font.auto_draw_text(
                &mut buf.offset((256, 64))?,
                &ctx.bg,
                &Color::new(1.0, 1.0, 1.0, 1.0),
                &ctx.config.prompt_err,
                &self.error,
            )?;
        }

        if self.reset_border {
            self.border = Color::new(1.0, 1.0, 1.0, 1.0);
            self.reset_border = false;
        }

        Ok(DrawReport {
            width: width,
            height: height,
            width,
            height,
            damage: vec![buf.get_signed_bounds()],
            full_damage: false,
        })
-- 
2.30.2