diff --git a/Cargo.lock b/Cargo.lock index 943023e..04b7e86 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -745,6 +745,27 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "const_format" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3decb4d6965448659923544a634a0571ba44cede4e11ef15a5a317126840454" +dependencies = [ + "const_format_proc_macros", + "konst", +] + +[[package]] +name = "const_format_proc_macros" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "941b570269a642506f08cb5b688c04bfa6cfd41a26f8bcdc49db8fd00c0ab659" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + [[package]] name = "core-foundation" version = "0.9.4" @@ -1019,6 +1040,14 @@ dependencies = [ "web-sys", ] +[[package]] +name = "egui-phosphor" +version = "0.14.0" +source = "git+https://github.com/xangelix/egui-phosphor?rev=01e8c1144cac3f551ceb834b6d26ddf36ba502cd#01e8c1144cac3f551ceb834b6d26ddf36ba502cd" +dependencies = [ + "egui", +] + [[package]] name = "egui-wgpu" version = "0.37.0" @@ -1966,6 +1995,21 @@ version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc" +[[package]] +name = "konst" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "128133ed7824fcd73d6e7b17957c5eb7bacb885649bd8c69708b2331a10bcefb" +dependencies = [ + "konst_macro_rules", +] + +[[package]] +name = "konst_macro_rules" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4933f3f57a8e9d9da04db23fb153356ecaf00cbd14aee46279c33dc80925c37" + [[package]] name = "kurbo" version = "0.13.1" @@ -2063,10 +2107,12 @@ version = "0.2.0" dependencies = [ "aho-corasick", "anyhow", + "const_format", "criterion", "directories", "eframe", "egui", + "egui-phosphor", "globset", "grep-regex", "grep-searcher", @@ -3835,6 +3881,12 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254" +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + [[package]] name = "url" version = "2.5.8" diff --git a/Cargo.toml b/Cargo.toml index 5739d0d..f89f669 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,9 +6,13 @@ edition = "2024" [dependencies] aho-corasick = "1.1.5" anyhow = "1.0.104" +const_format = "0.2" directories = "6.0.0" eframe = "0.37.0" egui = "0.37.0" +# Fork branch of upstream PR #49 (egui 0.37 support), pinned. Switch back to +# the crates.io release once upstream publishes one for egui 0.37. +egui-phosphor = { git = "https://github.com/xangelix/egui-phosphor", rev = "01e8c1144cac3f551ceb834b6d26ddf36ba502cd", default-features = false, features = ["subset"] } globset = "0.4.20" grep-regex = "0.1.14" grep-searcher = "0.1.17" diff --git a/src/icons.rs b/src/icons.rs new file mode 100644 index 0000000..0c1179c --- /dev/null +++ b/src/icons.rs @@ -0,0 +1,38 @@ +//! Phosphor icons, subset at compile time to the ones the app uses. +//! +//! egui's bundled fonts cover text but not symbols; for those it falls back to +//! system fonts, which differ per platform (Windows showed empty boxes). The +//! subset font is bundled, so icons look the same everywhere. Add an icon here +//! before using it in `strings`. + +egui_phosphor::subset! { + pub mod icons { + use regular::{ + ARROW_RIGHT, + ARROW_U_DOWN_LEFT, + CARET_DOWN, + CARET_RIGHT, + CARET_UP, + CLIPBOARD, + MAGNIFYING_GLASS, + MINUS_SQUARE, + PALETTE, + PENCIL_SIMPLE, + PLUS_SQUARE, + WARNING, + X, + }; + use fill::{SQUARE}; + } +} + +pub use icons::{fill, regular}; + +/// Register the icon fonts. `regular` resolves inline in ordinary text; `fill` +/// is only used where a label selects [`fill::family`]. +pub fn install(ctx: &egui::Context) { + let mut fonts = egui::FontDefinitions::default(); + regular::add_to_fonts(&mut fonts); + fill::add_as_family(&mut fonts); + ctx.set_fonts(fonts); +} diff --git a/src/lib.rs b/src/lib.rs index 57cde29..e465baf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,6 +5,7 @@ //! `ui` module holds the egui front end. pub mod grep; +pub mod icons; pub mod index; pub mod job; pub mod passes; diff --git a/src/strings.rs b/src/strings.rs index 2f94571..0831f53 100644 --- a/src/strings.rs +++ b/src/strings.rs @@ -2,14 +2,20 @@ //! //! Fixed texts are `const`s; texts with values in them are small functions so //! the wording (and word order) lives here, not at the call site. Call sites -//! import this module as `tr`. Icons that are pure symbols (▶, ✖, `.*`, `Aa`) -//! are here too so a later translation pass sees everything. +//! import this module as `tr`. Icons that are pure symbols (carets, `.*`, `Aa`) +//! are here too so a later translation pass sees everything. Symbol glyphs come +//! from the bundled Phosphor subset in `crate::icons` (`ic`), never from +//! literal Unicode symbols, which need system fonts. //! //! Not here: widget ids, settings keys, debug-script commands and env vars. use std::fmt::Display; use std::path::Path; +use const_format::concatcp; + +use crate::icons::{fill, regular as ic}; + pub const APP_NAME: &str = "logreadlite"; pub const APP_TAGLINE: &str = "A fast viewer for large log files."; @@ -17,7 +23,7 @@ pub const APP_TAGLINE: &str = "A fast viewer for large log files."; pub const CANCEL: &str = "Cancel"; pub const CLOSE: &str = "Close"; -pub const COPY: &str = "📋 Copy"; +pub const COPY: &str = concatcp!(ic::CLIPBOARD, " Copy"); pub const COPY_LINE: &str = "Copy line"; pub const EXPORT_DOTS: &str = "Export…"; pub const IMPORT: &str = "Import"; @@ -31,8 +37,8 @@ pub const CASE_ICON: &str = "Aa"; pub const CASE_TIP: &str = "Case sensitive"; pub const WORD_ICON: &str = "\\b"; pub const WORD_TIP: &str = "Whole word"; -pub const ARROW_OPEN: &str = "▼"; -pub const ARROW_CLOSED: &str = "▶"; +pub const ARROW_OPEN: &str = ic::CARET_DOWN; +pub const ARROW_CLOSED: &str = ic::CARET_RIGHT; pub fn arrow(open: bool) -> &'static str { if open { ARROW_OPEN } else { ARROW_CLOSED } @@ -57,7 +63,10 @@ pub const MENU_HELP: &str = "Help"; pub const MENU_SHORTCUTS: &str = "Keyboard shortcuts"; pub const MENU_ABOUT: &str = "About"; -pub const TAB_CLOSE_ICON: &str = "✖"; +pub const CLOSE_ICON: &str = ic::X; +pub const WARNING_ICON: &str = ic::WARNING; +pub const MOVE_UP_ICON: &str = ic::CARET_UP; +pub const MOVE_DOWN_ICON: &str = ic::CARET_DOWN; pub const SHORTCUTS_TITLE: &str = "Keyboard shortcuts"; pub const SHORTCUTS: &[(&str, &str)] = &[ @@ -94,22 +103,23 @@ pub fn cannot_save_settings(e: impl Display) -> String { // ----- log tab: toolbar ----- -pub const TB_ENTRY_START: &str = "✏ Entry start"; +pub const TB_ENTRY_START: &str = concatcp!(ic::PENCIL_SIMPLE, " Entry start"); pub const TB_ENTRY_START_TIP: &str = "Edit the entry-start pattern"; -pub const TB_EXPAND_ALL: &str = "⊞ Expand all"; -pub const TB_COLLAPSE_ALL: &str = "⊟ Collapse all"; -pub const TB_WRAP: &str = "↩ Wrap"; +pub const TB_EXPAND_ALL: &str = concatcp!(ic::PLUS_SQUARE, " Expand all"); +pub const TB_COLLAPSE_ALL: &str = concatcp!(ic::MINUS_SQUARE, " Collapse all"); +pub const TB_WRAP: &str = concatcp!(ic::ARROW_U_DOWN_LEFT, " Wrap"); pub const TB_WRAP_TIP: &str = "Line wrap (Alt+Z)"; -pub const TB_HIGHLIGHTS: &str = "🎨 Highlights"; +pub const TB_HIGHLIGHTS: &str = concatcp!(ic::PALETTE, " Highlights"); pub const FILE_GONE: &str = "The file was deleted or moved. Showing the last version."; // ----- log tab: search ----- +pub const SEARCH_ICON: &str = ic::MAGNIFYING_GLASS; pub const SEARCH_HINT: &str = "Search (Ctrl+F)"; -pub const SEARCH_PREV_ICON: &str = "⏶"; +pub const SEARCH_PREV_ICON: &str = ic::CARET_UP; pub const SEARCH_PREV_TIP: &str = "Previous match (Shift+Enter, Shift+F3)"; -pub const SEARCH_NEXT_ICON: &str = "⏷"; +pub const SEARCH_NEXT_ICON: &str = ic::CARET_DOWN; pub const SEARCH_NEXT_TIP: &str = "Next match (Enter, F3)"; pub const SEARCH_HIDDEN_TOO: &str = "hidden too"; pub const SEARCH_HIDDEN_TOO_TIP: &str = "Also stop at matches in entries hidden by the filter"; @@ -170,7 +180,7 @@ pub const VIEW_FILTERING: &str = "Filtering…"; pub const VIEW_EMPTY: &str = "The file is empty."; pub const VIEW_NO_MATCH: &str = "No entries match the filter."; pub const ENTRY_CUT: &str = "\n… (cut)"; -pub const LINE_CUT: &str = " … line cut at 64 KB, right-click → Show full entry"; +pub const LINE_CUT: &str = concatcp!(" … line cut at 64 KB, right-click ", ic::ARROW_RIGHT, " Show full entry"); pub fn more_lines_badge(n: u32) -> String { format!(" +{n} lines ") @@ -234,8 +244,10 @@ pub const RULESETS_SWITCH: &str = "Switch to…"; pub const RULESETS_NAME_HINT: &str = "name, e.g. Java service"; pub const RULESETS_SAVE: &str = "Save set"; +/// Colour swatch plus name. Render it with [`fill::family`] so the square is +/// solid. pub fn swatch_label(name: &str) -> String { - format!("■ {name}") + format!("{} {name}", fill::SQUARE) } pub fn rules_saved_for(glob: &str) -> String { format!("Saved rules for {glob}") @@ -317,7 +329,7 @@ pub const GREP_GITIGNORE: &str = "Respect .gitignore"; pub const GREP_SKIP_BINARY: &str = "Skip binary files"; pub const GREP_MAX_SIZE: &str = "Max size (MB)"; pub const GREP_MAX_SIZE_HINT: &str = "any"; -pub const GREP_SEARCH: &str = "🔍 Search"; +pub const GREP_SEARCH: &str = concatcp!(ic::MAGNIFYING_GLASS, " Search"); pub const GREP_CAPPED: &str = "results capped (10,000 per file, 1M total)"; pub const GREP_COPY_TIP: &str = "Copy as path:line:text"; pub const GREP_EXPORT_FILE: &str = "grep-results.txt"; diff --git a/src/ui/log_tab.rs b/src/ui/log_tab.rs index a683571..a387184 100644 --- a/src/ui/log_tab.rs +++ b/src/ui/log_tab.rs @@ -975,7 +975,7 @@ impl LogTab { } fn search_box(&mut self, ui: &mut Ui) { - ui.label("🔍"); + ui.label(tr::SEARCH_ICON); let edit = egui::TextEdit::singleline(&mut self.search.text).hint_text(tr::SEARCH_HINT).desired_width(220.0); let resp = ui.add(edit); if self.search.focus { @@ -1038,9 +1038,9 @@ impl LogTab { changed |= ui.toggle_value(&mut r.case_sensitive, tr::CASE_ICON).on_hover_text(tr::CASE_TIP).changed(); if let Err(e) = r.validate() { - ui.colored_label(ui.visuals().error_fg_color, "⚠").on_hover_text(e); + ui.colored_label(ui.visuals().error_fg_color, tr::WARNING_ICON).on_hover_text(e); } - if ui.small_button("✖").clicked() { + if ui.small_button(tr::CLOSE_ICON).clicked() { remove = Some(i); } }); diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 776c5e3..3474640 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -55,6 +55,7 @@ impl App { pub fn new(cc: &eframe::CreationContext<'_>, args: Vec) -> Self { let ctx = cc.egui_ctx.clone(); let notify: Notify = Arc::new(move || ctx.request_repaint()); + crate::icons::install(&cc.egui_ctx); let settings = Settings::load(); cc.egui_ctx.global_style_mut(|s| { if let Some(f) = s.text_styles.get_mut(&egui::TextStyle::Monospace) { @@ -259,7 +260,7 @@ impl App { if r.middle_clicked() { close = Some(i); } - if ui.small_button(tr::TAB_CLOSE_ICON).on_hover_text(tr::CLOSE).clicked() { + if ui.small_button(tr::CLOSE_ICON).on_hover_text(tr::CLOSE).clicked() { close = Some(i); } ui.separator(); diff --git a/src/ui/panels.rs b/src/ui/panels.rs index a89b804..6326860 100644 --- a/src/ui/panels.rs +++ b/src/ui/panels.rs @@ -163,10 +163,12 @@ fn color_picker(ui: &mut Ui, id: impl egui::AsIdSalt, color: &mut Option let swatch = palette::swatch(¤t); egui::ComboBox::from_id_salt(id) .width(80.0) - .selected_text(RichText::new(tr::swatch_label(¤t)).color(swatch)) + .selected_text(RichText::new(tr::swatch_label(¤t)).family(crate::icons::fill::family()).color(swatch)) .show_ui(ui, |ui| { for name in palette::NAMES { - let label = RichText::new(tr::swatch_label(name)).color(palette::swatch(name)); + let label = RichText::new(tr::swatch_label(name)) + .family(crate::icons::fill::family()) + .color(palette::swatch(name)); if ui.selectable_label(current == *name, label).clicked() { *color = Some(name.to_string()); changed = true; @@ -214,17 +216,17 @@ pub fn rules_panel(tab: &mut LogTab, ui: &mut Ui, settings: &mut Settings) -> Ve changed |= ui.selectable_value(&mut scope, Scope::Match, tr::SCOPE_MATCH).changed(); }); r.scope = Some(scope); - if k > 0 && ui.small_button("⏶").clicked() { + if k > 0 && ui.small_button(tr::MOVE_UP_ICON).clicked() { swap = Some((i, hl[k - 1])); } - if k + 1 < hl.len() && ui.small_button("⏷").clicked() { + if k + 1 < hl.len() && ui.small_button(tr::MOVE_DOWN_ICON).clicked() { swap = Some((i, hl[k + 1])); } - if ui.small_button("✖").clicked() { + if ui.small_button(tr::CLOSE_ICON).clicked() { remove = Some(i); } if let Err(e) = r.validate() { - ui.colored_label(ui.visuals().error_fg_color, "⚠").on_hover_text(e); + ui.colored_label(ui.visuals().error_fg_color, tr::WARNING_ICON).on_hover_text(e); } }); ui.add_space(2.0);