Pi66

pino-rs
Rust notification daemon.
git clone https://git.pi66.xyz/pino-rs

← back to log

0.1.1

author: pixel2175
date: 2025-02-18 14:59
hash: d1b6ec428fa75fc68483cb7fe7236640cede8ac2

Diffstat:

A

Cargo.toml
10 ++

A

README.md
148 +++++++++++++++++++++++++

A

src/colors.rs
137 +++++++++++++++++++++++

A

src/config.rs
73 +++++++++++++

A

src/main.rs
175 ++++++++++++++++++++++++++++++

A

src/screen.rs
47 ++++++++

A

src/ui.rs
90 +++++++++++++++
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
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();
+}