pino-rs
Rust notification daemon.
git clone https://git.pi66.xyz/pino-rs
About | Files | Commits | Refs | License
0.1.1
Author: pixel2175
Date: 2025-02-18 14:59
commit: d1b6ec42
Stat
| A | Cargo.toml | 10 | +10 | -0 |
| A | README.md | 148 | +148 | -0 |
| A | src/colors.rs | 137 | +137 | -0 |
| A | src/config.rs | 73 | +73 | -0 |
| A | src/main.rs | 175 | +175 | -0 |
| A | src/screen.rs | 47 | +47 | -0 |
| A | src/ui.rs | 90 | +90 | -0 |
Diff
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644
index 0000000..fba996c
--- /dev/null
+++ b/Cargo.toml
@@ -0,0 +1,10 @@
+[package]
+name = "pino"
+version = "0.1.1"
+edition = "2021"
+
+[dependencies]
+fltk = "^1.5"
+toml = "0.5.2"
+serde = { version = "1.0", features = ["derive"] }
+argh = "0.1.13"
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..6de5816
--- /dev/null
...
Show all
Show less
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644
index 0000000..fba996c
--- /dev/null
+++ b/Cargo.toml
@@ -0,0 +1,10 @@
+[package]
+name = "pino"
+version = "0.1.1"
+edition = "2021"
+
+[dependencies]
+fltk = "^1.5"
+toml = "0.5.2"
+serde = { version = "1.0", features = ["derive"] }
+argh = "0.1.13"
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..6de5816
--- /dev/null
...
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644
index 0000000..fba996c
--- /dev/null
+++ b/Cargo.toml
@@ -0,0 +1,10 @@
+[package]
+name = "pino"
+version = "0.1.1"
+edition = "2021"
+
+[dependencies]
+fltk = "^1.5"
+toml = "0.5.2"
+serde = { version = "1.0", features = ["derive"] }
+argh = "0.1.13"
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..6de5816
--- /dev/null
+++ b/README.md
@@ -0,0 +1,148 @@
+# Pino: Pixel Notification
+
+Pino is a fully customizable notification tool rewritten in Rust. It allows you to display notifications with various options, including dynamic theming, configurable fonts, and system integration.
+
+---
+
+## Shortcuts
+
+- [Features](#features)
+- [Installation](#installation)
+- [Usage](#usage)
+- [Example: Low Battery Alert](#example-low-battery-alert)
+- [Configuration](#configuration)
+- [Dependencies](#dependencies)
+- [Hardware Usage](#hardware-usage)
+
+---
+
+## Features
+
+- **Customizable Notifications**: Set titles, messages, delay, and fonts.
+- **Dynamic Theming with Pywal**: Automatically matches the notification theme to your wallpaper.
+- **Configurable Settings**: Adjust themes, screen placement, fonts, and more via a TOML config file.
+- **Script Integration**: Automate notifications using scripts in any language.
+
+---
+
+## Installation
+
+### Arch Linux
+
+```bash
+sudo pacman -S rust
+```
+
+### Debian-based Distros
+
+```bash
+sudo apt install rustc cargo
+```
+
+Then, build the project:
+
+```bash
+cargo build --release
+```
+
+Copy the binary to `/usr/bin`:
+
+```bash
+sudo cp target/release/pino /usr/bin/
+```
+
+---
+
+## Dependencies
+
+Pino requires the following dependencies:
+
+- Rust (for building from source)
+- Pywal (optional) for dynamic theming
+
+---
+
+## Usage
+
+Pino supports the following command-line options:
+
+```bash
+Usage: pino -t <title> -m <message> [-d <delay>] [-f] [-c <config>]
+
+Options:
+ -t, --title Set the notification title content
+ -m, --message Set the notification message content
+ -d, --delay Set the delay before the program closes (in seconds)
+ -f, --font Print all the available fonts
+ -c, --config Set a custom configuration file
+ --help, help Display usage information
+```
+
+### Note:
+
+If you want to insert a new line (wrap text) in the message, use `\n` in the argument parameter.
+
+### Example: Low Battery Alert
+
+You can create a script to notify about low battery status:
+
+```bash
+pino -t "Battery Warning" -m "Low battery!\nPlease connect your charger." -d 5
+```
+
+---
+
+## Configuration
+
+The app uses a TOML configuration file located at `~/.config/pino/config.toml`. Example:
+
+```toml
+[screen]
+monitor = 0
+horizontal = "left"
+vertical = "top"
+x = 25
+y = 55
+width = 300
+height = 100
+delay = 5
+
+[frame]
+fg_color = "#1a1e24"
+font_family = "Fira Code"
+
+[border]
+weight = 4
+color = "#ffffff"
+radius = 8
+
+[title]
+color = "#c5c6c8"
+font_size = 19
+x = 4
+y = 10
+
+[message]
+color = "#626977"
+font_size = 15
+x = 10
+y = 45
+
+[pywal]
+pywal = true
+background_color = "bg"
+border_color = "color1"
+title_color = "fg"
+message_color = "color8"
+
+[optional]
+sound = false
+```
+
+---
+
+## Hardware Usage
+
+Pino is lightweight and efficient. The graphical notification window typically uses approximately **18-25MB of RAM** when active, ensuring minimal system resource consumption.
+
+
diff --git a/src/colors.rs b/src/colors.rs
new file mode 100644
index 0000000..8166414
--- /dev/null
+++ b/src/colors.rs
@@ -0,0 +1,137 @@
+use serde::Deserialize;
+use std::fs;
+use std::{env, fs::OpenOptions, io::Write, path::PathBuf, process::Command};
+
+pub fn get_config_dir() -> PathBuf {
+ if let Ok(xdg_config) = env::var("XDG_CONFIG_HOME") {
+ return PathBuf::from(xdg_config);
+ }
+ if let Ok(home) = env::var("HOME") {
+ return PathBuf::from(home).join(".config");
+ }
+ panic!("Could not determine config directory");
+}
+
+fn create_template() {
+ let config = get_config_dir()
+ .join("wal")
+ .join("templates")
+ .join("colors-pino.toml");
+
+ fs::create_dir_all(config.parent().unwrap())
+ .expect("Failed to create directories for template");
+ println!("Creating template at: {:?}", config);
+ let mut template = OpenOptions::new()
+ .write(true)
+ .create(true)
+ .truncate(true)
+ .open(&config)
+ .expect("Can't Create Template File !!!");
+
+ template
+ .write_all(
+ b"bg = \"{background}\"
+fg = \"{foreground}\"
+
+color0 = \"{color0}\"
+color1 = \"{color1}\"
+color2 = \"{color2}\"
+color3 = \"{color3}\"
+color4 = \"{color4}\"
+color5 = \"{color5}\"
+color6 = \"{color6}\"
+color7 = \"{color7}\"
+color8 = \"{color8}\"
+color9 = \"{color9}\"
+color10 = \"{color10}\"
+color11 = \"{color11}\"
+color12 = \"{color12}\"
+color13 = \"{color13}\"
+color14 = \"{color14}\"
+color15 = \"{color15}\"
+",
+ )
+ .expect("Can't Create Template File !!!");
+}
+
+#[derive(Debug, Deserialize)]
+struct Pywal {
+ bg: String,
+ fg: String,
+ color0: String,
+ color1: String,
+ color2: String,
+ color3: String,
+ color4: String,
+ color5: String,
+ color6: String,
+ color7: String,
+ color8: String,
+ color9: String,
+ color10: String,
+ color11: String,
+ color12: String,
+ color13: String,
+ color14: String,
+ color15: String,
+}
+
+fn get_color<'a>(colors: &'a Pywal, key: &str) -> &'a str {
+ match key {
+ "bg" => &colors.bg,
+ "fg" => &colors.fg,
+ "color0" => &colors.color0,
+ "color1" => &colors.color1,
+ "color2" => &colors.color2,
+ "color3" => &colors.color3,
+ "color4" => &colors.color4,
+ "color5" => &colors.color5,
+ "color6" => &colors.color6,
+ "color7" => &colors.color7,
+ "color8" => &colors.color8,
+ "color9" => &colors.color9,
+ "color10" => &colors.color10,
+ "color11" => &colors.color11,
+ "color12" => &colors.color12,
+ "color13" => &colors.color13,
+ "color14" => &colors.color14,
+ "color15" => &colors.color15,
+ _ => panic!("Invalid key!"),
+ }
+}
+
+pub fn pywal(
+ background_color: String,
+ border_color: String,
+ title_color: String,
+ message_color: String,
+) ->(String,String,String,String) {
+ let home = env::var("HOME").expect("Can't Find Home Dir");
+ let template_path = get_config_dir()
+ .join("wal")
+ .join("templates")
+ .join("colors-pino.toml");
+
+ if !template_path.exists() {
+ create_template();
+ }
+
+ Command::new("bash")
+ .arg("-c")
+ .arg("wal -R")
+ .output()
+ .expect("Can't Reload Colors");
+
+ let cache_colors = PathBuf::from(home)
+ .join(".cache")
+ .join("wal")
+ .join("colors-pino.toml");
+ let content = fs::read_to_string(&cache_colors).expect("Can't Read Colors File!!!");
+ let colors: Pywal = toml::from_str(&content).expect("Invalid TOML Format!!!");
+ return (
+ get_color(&colors, background_color.as_str()).to_string(),
+ get_color(&colors, border_color.as_str()).to_string(),
+ get_color(&colors, title_color.as_str()).to_string(),
+ get_color(&colors, message_color.as_str()).to_string(),
+ );
+}
diff --git a/src/config.rs b/src/config.rs
new file mode 100644
index 0000000..d0d3941
--- /dev/null
+++ b/src/config.rs
@@ -0,0 +1,73 @@
+use std::{path::PathBuf,fs::{create_dir_all,OpenOptions},io::Write};
+
+
+pub fn generate_config(config_path: PathBuf){
+ let config = config_path
+ .join("pino")
+ .join("config.toml");
+
+ create_dir_all(config.parent().unwrap())
+ .expect("Failed to create directories for template");
+ println!("Creating config file at: {}", config.display());
+ let mut template = OpenOptions::new()
+ .write(true)
+ .create(true)
+ .truncate(true)
+ .open(&config)
+ .expect("Can't Create Template File !!!");
+
+ template
+ .write_all(
+ b"[screen]
+# Set the monitor using index
+monitor = 0
+
+# App placement on the screen
+horizontal = \"left\"
+vertical = \"top\"
+x = 25
+y = 55
+
+# Width and height of the app
+width = 300
+height = 100
+
+# Time to display the app (in seconds)
+delay = 5
+
+[frame]
+fg_color = \"#1a1e24\"
+
+# Run \"pino -f\" to show all available fonts
+font_family = \"Fira Code\"
+
+[border]
+weight = 4
+color = \"#ffffff\"
+radius = 8
+
+[title]
+color = \"#c5c6c8\"
+font_size = 19
+x = 4
+y = 10
+
+[message]
+color = \"#626977\"
+font_size = 15
+x = 10
+y = 45
+
+[pywal]
+pywal = true
+
+# You can choose colors from colors[0-15] or use these values: \"bg\", \"fg\"
+# Check ~/.cache/wal/colors-pino.toml file
+background_color = \"bg\"
+border_color = \"color1\"
+title_color = \"fg\"
+message_color = \"color8\"
+
+")
+.expect("Can't Create Template File !!!");
+}
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..dbe78b3
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,175 @@
+use serde::Deserialize;
+use std::fs::{self};
+use argh::FromArgs;
+
+
+mod colors;
+mod config;
+mod screen;
+mod ui;
+
+
+// Get Args
+#[derive(FromArgs)]
+
+#[argh(description = "This tool lets you display notification with customizable options. you can also use a configuration file to set theme
+and everything easily (conf path = ~/.config/pino)")]
+struct Arg {
+
+ #[argh(option,short = 't', description = "set the notification title content")]
+ title:Option<String> ,
+
+ #[argh(option,short = 'm', description = "set the notification message content")]
+ message:Option<String>,
+
+
+ #[argh(option,short = 'd', description = "set the delay before program closes with secends")]
+ delay:Option<i32> ,
+
+ #[argh(switch,short = 'f', description = "print all the fonts that you can use it")]
+ font:bool ,
+
+ #[argh(option,short = 'c', description = "set a custom configuration file")]
+ config:Option<String> ,
+
+}
+
+
+
+
+
+
+
+// Read the Config File
+#[derive(Debug, Deserialize)]
+struct Config {
+ screen: Screen,
+ frame: Frame,
+ border: Border,
+ title: Title,
+ message: Message,
+ pywal: Pywal,
+}
+
+#[derive(Debug, Deserialize)]
+struct Screen {
+ monitor: u8,
+ horizontal: String,
+ vertical: String,
+ x: i8,
+ y: i8,
+ width: u16,
+ height: u16,
+ delay: i32,
+}
+#[derive(Debug, Deserialize)]
+struct Frame {
+ fg_color: String,
+ font_family: String,
+}
+#[derive(Debug, Deserialize)]
+struct Border {
+ weight: i32,
+ color: String,
+ radius: i32,
+}
+#[derive(Debug, Deserialize)]
+struct Title {
+ color: String,
+ font_size: i32,
+ x: i32,
+ y: i32,
+}
+#[derive(Debug, Deserialize)]
+struct Message {
+ color: String,
+ font_size: i32,
+ x: i32,
+ y: i32,
+}
+#[derive(Debug, Deserialize)]
+struct Pywal {
+ pywal: bool,
+ background_color: String,
+ border_color: String,
+ title_color: String,
+ message_color: String,
+}
+
+
+
+fn main() {
+ let config_folder = colors::get_config_dir();
+ let args:Arg = argh::from_env();
+
+ if args.font{
+ ui::print_fonts();
+ return ;
+ }
+
+
+let config_file = match args.config {
+ Some(path) => path,
+ None => {
+ if !config_folder.join("pino").exists() {
+ config::generate_config(config_folder.clone());
+ }
+ config_folder.join("pino").join("config.toml").to_string_lossy().into_owned()
+ }
+};
+
+ let config_content = fs::read_to_string(config_file).expect("Faild ");
+ let config: Config = toml::from_str(&config_content).expect("Faild");
+
+ // Get Colors
+ let colors = match config.pywal.pywal {
+ true => colors::pywal(
+ config.pywal.background_color.to_string(),
+ config.pywal.border_color.to_string(),
+ config.pywal.title_color.to_string(),
+ config.pywal.message_color.to_string()
+ ),
+ false => (
+ config.frame.fg_color,
+ config.border.color,
+ config.title.color,
+ config.message.color,
+ ),
+
+ };
+
+ // Get Screen Placment
+ let screen = screen::get_size(
+ config.screen.monitor.into(),
+ config.screen.vertical.as_str(),
+ config.screen.horizontal.as_str(),
+ config.screen.x.into(),
+ config.screen.y.into(),
+ config.screen.width.into(),
+ config.screen.height.into(),
+ );
+
+ //UI
+ ui::ui(
+ screen,config.frame.font_family,
+ (
+ config.border.weight,
+ config.border.radius,
+ ),
+ (
+ config.title.x,
+ config.title.y,
+ config.title.font_size,
+ ),
+ (
+ config.message.x,
+ config.message.y,
+ config.message.font_size,
+ ),colors
+ ,(
+ args.title.unwrap_or("Title".to_string()),
+ args.message.unwrap_or("you didn't set the title or message".to_string()),
+ args.delay.unwrap_or(config.screen.delay)
+ )
+ );
+}
diff --git a/src/screen.rs b/src/screen.rs
new file mode 100644
index 0000000..c47efcb
--- /dev/null
+++ b/src/screen.rs
@@ -0,0 +1,47 @@
+use fltk::app;
+
+pub fn get_size(
+ monitor: usize,
+ v: &str,
+ h: &str,
+ ax: i32,
+ ay: i32,
+ aw: i32,
+ ah: i32,
+) -> (i32, i32, i32, i32) {
+ let mut screens = vec![];
+
+ for screen in 0..app::screen_count() {
+ screens.push(app::screen_xywh(screen));
+ }
+
+ if h.to_lowercase() == "left" {
+ if v.to_lowercase() == "top" {
+ return (screens[monitor].0 + ax, ay + screens[monitor].1, aw, ah);
+ } else if v.to_lowercase() == "bottom" {
+ return (
+ screens[monitor].0 + ax,
+ screens[monitor].1 + screens[monitor].3 - ah - ay,
+ aw,
+ ah,
+ );
+ }
+ } else if h.to_lowercase() == "right" {
+ if v.to_lowercase() == "top" {
+ return (
+ screens[monitor].0 + screens[monitor].2 - aw - ax,
+ screens[monitor].1 + ay,
+ aw,
+ ah,
+ );
+ } else if v.to_lowercase() == "bottom" {
+ return (
+ screens[monitor].0 + screens[monitor].2 - aw - ax,
+ screens[monitor].1 + screens[monitor].3 - ah - ay,
+ aw,
+ ah,
+ );
+ }
+ }
+ (0, 0, 100, 100)
+}
diff --git a/src/ui.rs b/src/ui.rs
new file mode 100644
index 0000000..d313d63
--- /dev/null
+++ b/src/ui.rs
@@ -0,0 +1,90 @@
+use fltk::{
+ app::{self, font_size, get_font_names},
+ draw::{self, draw_text2},
+ enums::{Align, Color, Event, Font},
+ prelude::{WidgetBase, WidgetExt, WindowExt},
+ window,
+};
+
+use draw::{draw_rounded_rectf, set_draw_color, set_font};
+
+use fltk::draw::measure;
+
+fn draw_wrapped_text(text: &str, x: i32, mut y: i32) {
+ for line in text.split("\\n") {
+ let (_, height) = measure(line, false);
+ draw_text2(line, x.into(), y.into(), 0, 0, Align::Left);
+ y += height;
+ }
+}
+
+pub fn print_fonts() {
+ for font in get_font_names() {
+ println!("{}", font);
+ }
+}
+
+pub fn ui(
+ screen_info: (i32, i32, i32, i32),
+ font_family: String,
+ border: (i32, i32),
+ title: (i32,i32,i32),
+ message: (i32,i32,i32),
+ colors: (String, String, String, String),
+ args: (String, String, i32),
+) {
+ let app = app::App::default();
+ let mut wind = window::Window::new(
+ screen_info.0,
+ screen_info.1,
+ screen_info.2,
+ screen_info.3,
+ "Pino",
+ );
+ wind.set_color(Color::from_hex_str(&colors.1.as_str()).expect("Can't set border color!!!"));
+ wind.set_override();
+
+ wind.draw(move |w| {
+ set_draw_color(Color::from_hex_str(&colors.0).expect(""));
+ draw_rounded_rectf(
+ border.0 - 1,
+ border.0 - 1,
+ w.width() - (border.0 - 1) * 2,
+ w.height() - (border.0 - 1) * 2,
+ border.1,
+ );
+
+ set_draw_color(Color::from_hex_str(&colors.2.as_str()).expect("ppp"));
+ set_font(Font::by_name(font_family.as_str()), title.2.into());
+ draw_wrapped_text(
+ args.0.as_str(),
+ title.0 + border.0 + 4,
+ title.1 + border.0 + font_size() -4
+ );
+
+ set_draw_color(Color::from_hex_str(&colors.3.as_str()).expect("ppp"));
+ set_font(Font::by_name(font_family.as_str()), message.2.into());
+ draw_wrapped_text(
+ args.1.as_str(),
+ message.0 + border.0 + 4,
+ message.1 + border.0 + font_size() -4,
+ );
+ });
+
+ wind.handle(|_, event| {
+ if event == Event::Push {
+ app::quit(); // This will close the window automatically
+ true
+ } else {
+ false
+ }
+ });
+
+ wind.show();
+
+ app::add_timeout3(args.2.into(), move |_| {
+ wind.hide();
+ app::quit();
+ });
+ app.run().unwrap();
+}