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 | diff --git a/Cargo.lock b/Cargo.lock
index 6876a98..2f8ca7b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -117,7 +117,7 @@ checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
[[package]]
name = "pino"
-version = "0.1.2"
+version = "1.1.0"
dependencies = [
"argh",
"fltk",
diff --git a/Cargo.toml b/Cargo.toml
index b3b0288..85008a2 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "pino"
-version = "0.1.2"
+version = "1.1.0"
edition = "2024"
[dependencies]
diff --git a/src/colors.rs b/src/colors.rs
index 22c1db5..97f8df4 100644
--- a/src/colors.rs
+++ b/src/colors.rs
@@ -1,6 +1,6 @@
use serde::Deserialize;
use std::fs;
-use std::{env, fs::OpenOptions, io::Write, path::PathBuf, process::Command};
+use std::{env, fs::OpenOptions, io::Write, path::PathBuf};
pub fn get_config_dir() -> PathBuf {
if let Ok(xdg_config) = env::var("XDG_CONFIG_HOME") {
@@ -125,10 +125,10 @@ pub fn pywal(
.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/main.rs b/src/main.rs
index dbe78b3..a92b23c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,8 +1,10 @@
use serde::Deserialize;
-use std::fs::{self};
+use std::{fs::{self, File}, io::Write};
use argh::FromArgs;
+use utils::is_running;
+mod utils;
mod colors;
mod config;
mod screen;
@@ -32,6 +34,9 @@ struct Arg {
#[argh(option,short = 'c', description = "set a custom configuration file")]
config:Option<String> ,
+
+ #[argh(option,short = 'v', description = "set a custom configuration file")]
+ version:Option<String> ,
}
@@ -102,74 +107,85 @@ fn main() {
let config_folder = colors::get_config_dir();
let args:Arg = argh::from_env();
+ if args.version.is_some() {
+ println!("v1.1.0");
+ return ;
+ }
+
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());
+ 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()
}
- 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()
+
+
+ let mut pino_check = File::create("/tmp/pino-check").unwrap();
+
+ writeln!(pino_check ,"{}",args.title.unwrap_or("Title".to_string())).unwrap();
+ writeln!(pino_check ,"{}",args.message.unwrap_or("you didn't set the title or message".to_string())).unwrap();
+ writeln!(pino_check ,"{}",args.delay.unwrap_or(config.screen.delay)).unwrap();
+
+
+ if !is_running("pino"){
+
+ 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)
- )
- );
+ };
+
+ // 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
+ );
+ }
}
diff --git a/src/ui.rs b/src/ui.rs
index d313d63..033b8b8 100644
--- a/src/ui.rs
+++ b/src/ui.rs
@@ -1,22 +1,18 @@
use fltk::{
- app::{self, font_size, get_font_names},
- draw::{self, draw_text2},
+ app::{self,get_font_names},
+ draw,
enums::{Align, Color, Event, Font},
- prelude::{WidgetBase, WidgetExt, WindowExt},
- window,
+ frame::Frame,
+ prelude::*,
+ window::Window,
+};
+use std::{
+ fs,
+ sync::mpsc,
+ thread,
+ time::{Duration, Instant},
};
-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() {
@@ -24,6 +20,9 @@ pub fn print_fonts() {
}
}
+
+
+
pub fn ui(
screen_info: (i32, i32, i32, i32),
font_family: String,
@@ -31,60 +30,109 @@ pub fn ui(
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(
+
+ let mut wind1 = 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,
- );
+
+ wind1.set_color(Color::from_hex_str(colors.1.as_str()).unwrap());
+
+ let mut wind2 = Window::new(
+ border.0 + border.1 / 2,
+ border.0 + border.1 / 2,
+ screen_info.2 - border.0 * 2 - border.1,
+ screen_info.3 - border.0 * 2 - border.1,
+ "Pino",
+ );
+ wind2.set_color(Color::from_hex_str(colors.0.as_str()).unwrap());
+
+ let mut title_frame = Frame::new(5 + title.0, 20 + title.1, wind2.w() - 10, wind2.h()-10, "");
+ let mut message_frame = Frame::new(5 + message.0, 20 + message.1, wind2.w() - 10, wind2.h()-10, "");
+
+ title_frame.set_align(Align::Top | Align::Left);
+ title_frame.set_label_color(Color::from_hex_str(colors.2.as_str()).unwrap());
+ title_frame.set_label_font(Font::by_name(font_family.as_str()));
+ title_frame.set_label_size(title.2);
+
+
+ message_frame.set_align(Align::Top | Align::Left);
+ message_frame.set_label_color(Color::from_hex_str(colors.3.as_str()).unwrap());
+ message_frame.set_label_font(Font::by_name(font_family.as_str()));
+ message_frame.set_label_size(message.2);
+
+
+
+ wind1.draw(move |f| {
+ draw::set_draw_color(Color::from_hex_str(colors.0.as_str()).unwrap());
+ draw::draw_rounded_rectf(border.0 - 1, border.0 -1 , f.w() - border.0 *2 +2, f.h() - border.0 * 2 +2, border.1);
});
- wind.handle(|_, event| {
+ wind1.handle(|_, event| {
if event == Event::Push {
- app::quit(); // This will close the window automatically
+ app::quit();
true
} else {
false
}
});
- wind.show();
+ let (tx, rx) = mpsc::channel::<(String, String, Option<u64>)>();
+ thread::spawn(move || {
+ let filename = "/tmp/pino-check";
+ let mut current_title = String::new();
+ let mut current_message = String::new();
+ let mut current_delay = None;
- app::add_timeout3(args.2.into(), move |_| {
- wind.hide();
- app::quit();
+ loop {
+ let content = fs::read_to_string(filename).unwrap_or_default();
+ let lines: Vec<&str> = content.lines().collect();
+ let new_title = lines.first().unwrap_or(&"").to_string();
+ let new_message = lines.get(1).unwrap_or(&"").to_string();
+ let new_delay = lines.get(2).and_then(|s| s.parse::<u64>().ok());
+ if new_title != current_title || new_message != current_message || new_delay != current_delay {
+ tx.send((new_title.clone(), new_message.clone(), new_delay)).unwrap();
+ current_title = new_title;
+ current_message = new_message;
+ current_delay = new_delay;
+ }
+
+ thread::sleep(Duration::from_millis(200));
+ }
});
- app.run().unwrap();
+
+ let mut close_timer: Option<Instant> = None;
+ let mut current_delay_secs: Option<u64> = None;
+
+ wind1.set_override();
+ wind1.show();
+
+ while app.wait() {
+ if let Ok((title, message, delay)) = rx.try_recv() {
+ if title_frame.label() != title {
+ title_frame.set_label(&title);
+ }
+ if message_frame.label() != message {
+ message_frame.set_label(&message);
+ }
+ wind2.redraw();
+
+ if delay != current_delay_secs {
+ current_delay_secs = delay;
+ close_timer = delay.map(|secs| Instant::now() + Duration::from_secs(secs));
+ }
+ }
+
+ if let Some(timer) = close_timer {
+ if Instant::now() >= timer {
+ app::quit();
+ break;
+ }
+ }
+ }
}
diff --git a/src/utils.rs b/src/utils.rs
new file mode 100644
index 0000000..85796b4
--- /dev/null
+++ b/src/utils.rs
@@ -0,0 +1,18 @@
+use std::process::{Command, Stdio};
+
+pub fn is_running(name: &str) -> bool {
+ let output = Command::new("pgrep")
+ .arg("-x")
+ .arg(name)
+ .stdout(Stdio::piped())
+ .stderr(Stdio::null())
+ .output();
+
+ match output {
+ Ok(output) if output.status.success() => {
+ let pids = String::from_utf8_lossy(&output.stdout);
+ pids.lines().count() == 2
+ },
+ _ => false
+ }
+}
|