Skip to content

Commit c7244dd

Browse files
authored
Merge pull request #106 from hacknus/implement_egui_logger
implement egui_logger
2 parents 90c0069 + 3c7d786 commit c7244dd

File tree

8 files changed

+394
-394
lines changed

8 files changed

+394
-394
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ All notable changes to the `Serial Monitor` crate will be documented in this fil
66

77
### Added:
88

9-
* Up to 4 Sentences highlightments using regex
10-
* Groups settings in the side bar by category into collapsing menu.
9+
* removed the custom implementation of `Print` and `ScrollArea` and implemented the `log` crate and `egui_logger`
10+
* Up to 4 Sentences highlightings using regex (thanks [@simon0356](https://github.com/simon0356))
11+
* Groups settings in the side bar by category into collapsing menu. (thanks [@simon0356](https://github.com/simon0356))
1112

1213
## 0.3.0 - 14.10.2024 - Automatic Reconnection
1314

Cargo.lock

Lines changed: 69 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ egui_extras = { version = "0.29.0", features = ["serde"] }
1515
egui_plot = "0.29.0"
1616
egui-phosphor = { git = "https://github.com/hacknus/egui-phosphor" }
1717
egui-theme-switch = { version = "0.2.0", default-features = true }
18+
egui_logger = "0.6.1"
1819
hex = "0.4"
1920
image = { version = "0.25", default-features = false, features = ["png"] }
2021
itertools-num = "0.1"
@@ -27,6 +28,7 @@ rfd = "0.15.0"
2728
safe-transmute = "0.11"
2829
serde = { version = "1.0", features = ["derive"] }
2930
serialport = { git = "https://github.com/serialport/serialport-rs", features = ["serde"] }
31+
log = "0.4.22"
3032

3133
[package.metadata.bundle]
3234
name = "Serial Monitor"

src/color_picker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ fn color_slider_1d(ui: &mut Ui, value: &mut f32, color_at: impl Fn(f32) -> Color
165165
mesh.colored_vertex(pos2(x, rect.top()), color);
166166
mesh.colored_vertex(pos2(x, rect.bottom()), color);
167167
if i < N {
168-
mesh.add_triangle((2 * i + 0) as u32, (2 * i + 1) as u32, (2 * i + 2) as u32);
168+
mesh.add_triangle((2 * i) as u32, (2 * i + 1) as u32, (2 * i + 2) as u32);
169169
mesh.add_triangle((2 * i + 1) as u32, (2 * i + 2) as u32, (2 * i + 3) as u32);
170170
}
171171
}

src/custom_highlighter.rs

Lines changed: 62 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,115 @@
1-
2-
3-
use eframe::egui::{FontFamily, FontId};
41
use eframe::egui::{self, text::LayoutJob, Color32, TextFormat};
5-
2+
use eframe::egui::{FontFamily, FontId};
63

74
extern crate regex;
85
use regex::Regex;
96
use regex::RegexSet;
107
const DEFAULT_FONT_ID: FontId = FontId::new(14.0, FontFamily::Monospace);
118

12-
13-
#[derive(Debug)]
14-
#[derive(Clone, Copy)]
15-
pub struct HighLightElement
16-
{
17-
pos_start:usize,
18-
pos_end:usize,
19-
token_idx:usize
9+
#[derive(Debug, Clone, Copy)]
10+
pub struct HighLightElement {
11+
pos_start: usize,
12+
pos_end: usize,
13+
token_idx: usize,
2014
}
21-
impl HighLightElement{
22-
pub fn new(pos_start: usize, pos_end:usize,token_idx:usize) -> Self{
23-
Self{
15+
impl HighLightElement {
16+
pub fn new(pos_start: usize, pos_end: usize, token_idx: usize) -> Self {
17+
Self {
2418
pos_start,
2519
pos_end,
26-
token_idx
20+
token_idx,
2721
}
2822
}
2923
}
3024
pub fn highlight_impl(
3125
_ctx: &egui::Context,
3226
text: &str,
3327
tokens: Vec<String>,
34-
default_color:Color32
28+
default_color: Color32,
3529
) -> Option<LayoutJob> {
3630
// Extremely simple syntax highlighter for when we compile without syntect
3731

38-
3932
let mut my_tokens = tokens.clone();
40-
for token in my_tokens.clone()
41-
{
42-
if token.len() < 1
43-
{
33+
for token in my_tokens.clone() {
34+
if token.is_empty() {
4435
let index = my_tokens.iter().position(|x| *x == token).unwrap();
4536
my_tokens.remove(index);
4637
}
4738
}
4839

4940
let content_string = String::from(text);
5041
// let _ = file.read_to_string(&mut isi);
51-
let mut regexs:Vec<Regex> = Vec::new();
42+
let mut regexs: Vec<Regex> = Vec::new();
5243
for sentence in my_tokens.clone() {
53-
match Regex::new(&sentence){
44+
match Regex::new(&sentence) {
5445
Ok(re) => {
5546
regexs.push(re);
56-
},
57-
Err(_err) =>{
58-
59-
},
47+
}
48+
Err(_err) => {}
6049
};
6150
}
6251

63-
let mut highlight_list : Vec<HighLightElement> = Vec::<HighLightElement>::new();
64-
match RegexSet::new(my_tokens.clone()){
52+
let mut highlight_list: Vec<HighLightElement> = Vec::<HighLightElement>::new();
53+
match RegexSet::new(my_tokens.clone()) {
6554
Ok(set) => {
6655
for idx in set.matches(&content_string).into_iter() {
6756
for caps in regexs[idx].captures_iter(&content_string) {
6857
highlight_list.push(HighLightElement::new(
69-
caps.get(0).unwrap().start(),
58+
caps.get(0).unwrap().start(),
7059
caps.get(0).unwrap().end(),
71-
idx));
60+
idx,
61+
));
7262
}
7363
}
74-
},
75-
Err(_err) => {
76-
7764
}
65+
Err(_err) => {}
7866
};
7967

8068
highlight_list.sort_by_key(|item| (item.pos_start, item.pos_end));
8169

82-
8370
let mut job = LayoutJob::default();
84-
let mut previous = HighLightElement::new(0,0, 0);
85-
for matches in highlight_list
86-
{
87-
if previous.pos_end >= matches.pos_start
88-
{
89-
continue
71+
let mut previous = HighLightElement::new(0, 0, 0);
72+
for matches in highlight_list {
73+
if previous.pos_end >= matches.pos_start {
74+
continue;
9075
}
91-
job.append(&text[previous.pos_end..(matches.pos_start)], 0.0, TextFormat::simple(DEFAULT_FONT_ID, default_color));
92-
if matches.token_idx == 0
93-
{
94-
job.append(&text[matches.pos_start..matches.pos_end], 0.0, TextFormat::simple(DEFAULT_FONT_ID, Color32::from_rgb(255, 100, 100)));
95-
}else if matches.token_idx == 1
96-
{
97-
job.append(&text[matches.pos_start..matches.pos_end], 0.0, TextFormat::simple(DEFAULT_FONT_ID, Color32::from_rgb(225, 159, 0)));
98-
99-
}else if matches.token_idx == 2
100-
{
101-
job.append(&text[matches.pos_start..matches.pos_end], 0.0, TextFormat::simple(DEFAULT_FONT_ID, Color32::from_rgb(87, 165, 171)));
102-
}else if matches.token_idx == 3
103-
{
104-
job.append(&text[matches.pos_start..matches.pos_end], 0.0, TextFormat::simple(DEFAULT_FONT_ID, Color32::from_rgb(109, 147, 226)));
76+
job.append(
77+
&text[previous.pos_end..(matches.pos_start)],
78+
0.0,
79+
TextFormat::simple(DEFAULT_FONT_ID, default_color),
80+
);
81+
if matches.token_idx == 0 {
82+
job.append(
83+
&text[matches.pos_start..matches.pos_end],
84+
0.0,
85+
TextFormat::simple(DEFAULT_FONT_ID, Color32::from_rgb(255, 100, 100)),
86+
);
87+
} else if matches.token_idx == 1 {
88+
job.append(
89+
&text[matches.pos_start..matches.pos_end],
90+
0.0,
91+
TextFormat::simple(DEFAULT_FONT_ID, Color32::from_rgb(225, 159, 0)),
92+
);
93+
} else if matches.token_idx == 2 {
94+
job.append(
95+
&text[matches.pos_start..matches.pos_end],
96+
0.0,
97+
TextFormat::simple(DEFAULT_FONT_ID, Color32::from_rgb(87, 165, 171)),
98+
);
99+
} else if matches.token_idx == 3 {
100+
job.append(
101+
&text[matches.pos_start..matches.pos_end],
102+
0.0,
103+
TextFormat::simple(DEFAULT_FONT_ID, Color32::from_rgb(109, 147, 226)),
104+
);
105105
}
106-
previous = matches.clone();
106+
previous = matches;
107107
}
108-
job.append(&text[previous.pos_end..], 0.0, TextFormat::simple(DEFAULT_FONT_ID, default_color));
109-
108+
job.append(
109+
&text[previous.pos_end..],
110+
0.0,
111+
TextFormat::simple(DEFAULT_FONT_ID, default_color),
112+
);
110113

111114
Some(job)
112115
}
113-

0 commit comments

Comments
 (0)