Refactored UI strings into cental location
This commit is contained in:
1 parent
8755fec633
commit
8c6dec9062
14 files changed
+605
-251
No files matched your search
Generated
+1
-1
@@ -2059,7 +2059,7 @@ checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "logreadlite"
|
name = "logreadlite"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aho-corasick",
|
"aho-corasick",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "logreadlite"
|
name = "logreadlite"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
+4
-3
@@ -12,6 +12,7 @@ use ignore::{WalkBuilder, WalkState};
|
|||||||
|
|
||||||
use crate::job::{Notify, Token};
|
use crate::job::{Notify, Token};
|
||||||
use crate::passes::SearchQuery;
|
use crate::passes::SearchQuery;
|
||||||
|
use crate::strings as tr;
|
||||||
|
|
||||||
pub const MAX_PER_FILE: usize = 10_000;
|
pub const MAX_PER_FILE: usize = 10_000;
|
||||||
pub const MAX_TOTAL: usize = 1_000_000;
|
pub const MAX_TOTAL: usize = 1_000_000;
|
||||||
@@ -89,15 +90,15 @@ pub fn spawn(opts: GrepOptions, token: Token, notify: Notify) -> Result<Arc<Grep
|
|||||||
.case_insensitive(!opts.query.case_sensitive)
|
.case_insensitive(!opts.query.case_sensitive)
|
||||||
.line_terminator(Some(b'\n'))
|
.line_terminator(Some(b'\n'))
|
||||||
.build(&source)
|
.build(&source)
|
||||||
.context("invalid pattern")?;
|
.context(tr::INVALID_PATTERN)?;
|
||||||
let display_re = regex::RegexBuilder::new(&source).case_insensitive(!opts.query.case_sensitive).build()?;
|
let display_re = regex::RegexBuilder::new(&source).case_insensitive(!opts.query.case_sensitive).build()?;
|
||||||
|
|
||||||
let mut ob = OverrideBuilder::new(&opts.folder);
|
let mut ob = OverrideBuilder::new(&opts.folder);
|
||||||
for g in globs(&opts.include) {
|
for g in globs(&opts.include) {
|
||||||
ob.add(g).with_context(|| format!("bad include glob {g}"))?;
|
ob.add(g).with_context(|| tr::bad_include_glob(g))?;
|
||||||
}
|
}
|
||||||
for g in globs(&opts.exclude) {
|
for g in globs(&opts.exclude) {
|
||||||
ob.add(&format!("!{g}")).with_context(|| format!("bad exclude glob {g}"))?;
|
ob.add(&format!("!{g}")).with_context(|| tr::bad_exclude_glob(g))?;
|
||||||
}
|
}
|
||||||
let overrides = ob.build()?;
|
let overrides = ob.build()?;
|
||||||
|
|
||||||
|
|||||||
@@ -13,4 +13,5 @@ pub mod rowmap;
|
|||||||
pub mod rules;
|
pub mod rules;
|
||||||
pub mod settings;
|
pub mod settings;
|
||||||
pub mod source;
|
pub mod source;
|
||||||
|
pub mod strings;
|
||||||
pub mod ui;
|
pub mod ui;
|
||||||
+6
-2
@@ -6,11 +6,15 @@ fn main() -> eframe::Result {
|
|||||||
let args: Vec<PathBuf> = std::env::args_os().skip(1).map(PathBuf::from).collect();
|
let args: Vec<PathBuf> = std::env::args_os().skip(1).map(PathBuf::from).collect();
|
||||||
let options = eframe::NativeOptions {
|
let options = eframe::NativeOptions {
|
||||||
viewport: egui::ViewportBuilder::default()
|
viewport: egui::ViewportBuilder::default()
|
||||||
.with_title("logreadlite")
|
.with_title(logreadlite::strings::APP_NAME)
|
||||||
.with_inner_size([1200.0, 800.0])
|
.with_inner_size([1200.0, 800.0])
|
||||||
.with_min_inner_size([480.0, 320.0])
|
.with_min_inner_size([480.0, 320.0])
|
||||||
.with_drag_and_drop(true),
|
.with_drag_and_drop(true),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
eframe::run_native("logreadlite", options, Box::new(move |cc| Ok(Box::new(logreadlite::ui::App::new(cc, args)))))
|
eframe::run_native(
|
||||||
|
logreadlite::strings::APP_NAME,
|
||||||
|
options,
|
||||||
|
Box::new(move |cc| Ok(Box::new(logreadlite::ui::App::new(cc, args)))),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
+5
-4
@@ -5,6 +5,7 @@ use regex::bytes::{Regex, RegexBuilder, RegexSet, RegexSetBuilder};
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::pattern::PatternDef;
|
use crate::pattern::PatternDef;
|
||||||
|
use crate::strings as tr;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||||
#[serde(rename_all = "lowercase")]
|
#[serde(rename_all = "lowercase")]
|
||||||
@@ -86,7 +87,7 @@ impl Rule {
|
|||||||
|
|
||||||
pub fn validate(&self) -> Result<(), String> {
|
pub fn validate(&self) -> Result<(), String> {
|
||||||
if self.pattern.is_empty() {
|
if self.pattern.is_empty() {
|
||||||
return Err("empty pattern".into());
|
return Err(tr::EMPTY_PATTERN.into());
|
||||||
}
|
}
|
||||||
if self.regex {
|
if self.regex {
|
||||||
RegexBuilder::new(&self.regex_source()).build().map(|_| ()).map_err(|e| e.to_string())
|
RegexBuilder::new(&self.regex_source()).build().map(|_| ()).map_err(|e| e.to_string())
|
||||||
@@ -232,20 +233,20 @@ impl RulesFile {
|
|||||||
pub fn parse(text: &str) -> anyhow::Result<(Self, Vec<String>)> {
|
pub fn parse(text: &str) -> anyhow::Result<(Self, Vec<String>)> {
|
||||||
let mut file: RulesFile = toml::from_str(text)?;
|
let mut file: RulesFile = toml::from_str(text)?;
|
||||||
if file.version > RULES_FILE_VERSION {
|
if file.version > RULES_FILE_VERSION {
|
||||||
anyhow::bail!("rule file version {} is newer than this app supports ({RULES_FILE_VERSION})", file.version);
|
anyhow::bail!(tr::rule_file_too_new(file.version, RULES_FILE_VERSION));
|
||||||
}
|
}
|
||||||
let mut errors = Vec::new();
|
let mut errors = Vec::new();
|
||||||
file.rules.retain(|r| match r.validate() {
|
file.rules.retain(|r| match r.validate() {
|
||||||
Ok(()) => true,
|
Ok(()) => true,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
errors.push(format!("{:?} rule `{}`: {e}", r.kind, r.pattern));
|
errors.push(tr::invalid_rule(r.kind, &r.pattern, e));
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if let Some(p) = &file.pattern
|
if let Some(p) = &file.pattern
|
||||||
&& let Err(e) = p.compile()
|
&& let Err(e) = p.compile()
|
||||||
{
|
{
|
||||||
errors.push(format!("entry-start pattern `{}`: {e}", p.regex));
|
errors.push(tr::invalid_entry_pattern(&p.regex, e));
|
||||||
file.pattern = None;
|
file.pattern = None;
|
||||||
}
|
}
|
||||||
Ok((file, errors))
|
Ok((file, errors))
|
||||||
|
|||||||
+3
-2
@@ -7,6 +7,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
|
|
||||||
use crate::pattern::PatternDef;
|
use crate::pattern::PatternDef;
|
||||||
use crate::rules::{RULES_FILE_EXT, Rule, RulesFile, default_highlights};
|
use crate::rules::{RULES_FILE_EXT, Rule, RulesFile, default_highlights};
|
||||||
|
use crate::strings as tr;
|
||||||
|
|
||||||
const MAX_RECENT: usize = 15;
|
const MAX_RECENT: usize = 15;
|
||||||
|
|
||||||
@@ -160,7 +161,7 @@ pub fn ruleset_path(name: &str) -> Option<PathBuf> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn save_ruleset(name: &str, file: &RulesFile) -> anyhow::Result<()> {
|
pub fn save_ruleset(name: &str, file: &RulesFile) -> anyhow::Result<()> {
|
||||||
let path = ruleset_path(name).ok_or_else(|| anyhow::anyhow!("no config folder"))?;
|
let path = ruleset_path(name).ok_or_else(|| anyhow::anyhow!(tr::NO_CONFIG_FOLDER))?;
|
||||||
if let Some(dir) = path.parent() {
|
if let Some(dir) = path.parent() {
|
||||||
std::fs::create_dir_all(dir)?;
|
std::fs::create_dir_all(dir)?;
|
||||||
}
|
}
|
||||||
@@ -169,7 +170,7 @@ pub fn save_ruleset(name: &str, file: &RulesFile) -> anyhow::Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_ruleset(name: &str) -> anyhow::Result<(RulesFile, Vec<String>)> {
|
pub fn load_ruleset(name: &str) -> anyhow::Result<(RulesFile, Vec<String>)> {
|
||||||
let path = ruleset_path(name).ok_or_else(|| anyhow::anyhow!("no config folder"))?;
|
let path = ruleset_path(name).ok_or_else(|| anyhow::anyhow!(tr::NO_CONFIG_FOLDER))?;
|
||||||
RulesFile::parse(&std::fs::read_to_string(path)?)
|
RulesFile::parse(&std::fs::read_to_string(path)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-4
@@ -7,6 +7,7 @@
|
|||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
|
use crate::strings as tr;
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use memmap2::Mmap;
|
use memmap2::Mmap;
|
||||||
|
|
||||||
@@ -30,10 +31,10 @@ pub struct MmapSource {
|
|||||||
|
|
||||||
impl MmapSource {
|
impl MmapSource {
|
||||||
pub fn open(path: &Path) -> Result<Self> {
|
pub fn open(path: &Path) -> Result<Self> {
|
||||||
let file = File::open(path).with_context(|| format!("cannot open {}", path.display()))?;
|
let file = File::open(path).with_context(|| tr::cannot_open(path))?;
|
||||||
let meta = file.metadata().with_context(|| format!("cannot read metadata of {}", path.display()))?;
|
let meta = file.metadata().with_context(|| tr::cannot_read_metadata(path))?;
|
||||||
if meta.is_dir() {
|
if meta.is_dir() {
|
||||||
anyhow::bail!("{} is a folder, not a file", path.display());
|
anyhow::bail!(tr::is_a_folder(path));
|
||||||
}
|
}
|
||||||
let map = if meta.len() == 0 {
|
let map = if meta.len() == 0 {
|
||||||
None
|
None
|
||||||
@@ -41,7 +42,7 @@ impl MmapSource {
|
|||||||
// SAFETY: the map is read-only. If another process truncates the file
|
// SAFETY: the map is read-only. If another process truncates the file
|
||||||
// while it is mapped, reads past the new end fault; the viewer checks
|
// while it is mapped, reads past the new end fault; the viewer checks
|
||||||
// the file size before each pass and on focus, and remaps on shrink.
|
// the file size before each pass and on focus, and remaps on shrink.
|
||||||
Some(unsafe { Mmap::map(&file) }.with_context(|| format!("cannot map {}", path.display()))?)
|
Some(unsafe { Mmap::map(&file) }.with_context(|| tr::cannot_map(path))?)
|
||||||
};
|
};
|
||||||
Ok(Self { path: path.to_path_buf(), map })
|
Ok(Self { path: path.to_path_buf(), map })
|
||||||
}
|
}
|
||||||
|
|||||||
+373
@@ -0,0 +1,373 @@
|
|||||||
|
//! Every user-visible text in one place.
|
||||||
|
//!
|
||||||
|
//! 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.
|
||||||
|
//!
|
||||||
|
//! Not here: widget ids, settings keys, debug-script commands and env vars.
|
||||||
|
|
||||||
|
use std::fmt::Display;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
pub const APP_NAME: &str = "logreadlite";
|
||||||
|
pub const APP_TAGLINE: &str = "A fast viewer for large log files.";
|
||||||
|
|
||||||
|
// ----- common -----
|
||||||
|
|
||||||
|
pub const CANCEL: &str = "Cancel";
|
||||||
|
pub const CLOSE: &str = "Close";
|
||||||
|
pub const COPY: &str = "📋 Copy";
|
||||||
|
pub const COPY_LINE: &str = "Copy line";
|
||||||
|
pub const EXPORT_DOTS: &str = "Export…";
|
||||||
|
pub const IMPORT: &str = "Import";
|
||||||
|
pub const CUSTOM: &str = "Custom";
|
||||||
|
pub const NONE_PAREN: &str = "(none)";
|
||||||
|
pub const RULE_FILE_FILTER: &str = "Log rules";
|
||||||
|
|
||||||
|
pub const REGEX_ICON: &str = ".*";
|
||||||
|
pub const REGEX_TIP: &str = "Regex";
|
||||||
|
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 fn arrow(open: bool) -> &'static str {
|
||||||
|
if open { ARROW_OPEN } else { ARROW_CLOSED }
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----- app shell: menus, tabs, start screen -----
|
||||||
|
|
||||||
|
pub const MENU_FILE: &str = "File";
|
||||||
|
pub const MENU_OPEN: &str = "Open… (Ctrl+O)";
|
||||||
|
pub const MENU_FIND_IN_FILES: &str = "Find in files… (Ctrl+Shift+F)";
|
||||||
|
pub const MENU_RECENT: &str = "Recent files";
|
||||||
|
pub const MENU_IMPORT_RULES: &str = "Import rules…";
|
||||||
|
pub const MENU_EXPORT_RULES: &str = "Export rules…";
|
||||||
|
pub const MENU_RELOAD: &str = "Reload file";
|
||||||
|
pub const MENU_CLOSE_TAB: &str = "Close tab (Ctrl+W)";
|
||||||
|
pub const MENU_QUIT: &str = "Quit";
|
||||||
|
pub const MENU_VIEW: &str = "View";
|
||||||
|
pub const MENU_SHOW_GUTTER: &str = "Show gutter";
|
||||||
|
pub const MENU_GUTTER_LINE_NUMBERS: &str = "Gutter shows line numbers";
|
||||||
|
pub const MENU_FONT_SIZE: &str = "Font size";
|
||||||
|
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 SHORTCUTS_TITLE: &str = "Keyboard shortcuts";
|
||||||
|
pub const SHORTCUTS: &[(&str, &str)] = &[
|
||||||
|
("Ctrl/Cmd+O", "Open file"),
|
||||||
|
("Ctrl/Cmd+Shift+F", "Find in files"),
|
||||||
|
("Ctrl/Cmd+W", "Close tab"),
|
||||||
|
("Ctrl/Cmd+Tab", "Next tab"),
|
||||||
|
("Ctrl/Cmd+F", "Search"),
|
||||||
|
("Enter / F3", "Next match"),
|
||||||
|
("Shift+Enter / Shift+F3", "Previous match"),
|
||||||
|
("Ctrl/Cmd+G", "Go to line"),
|
||||||
|
("Alt+Z", "Toggle line wrap"),
|
||||||
|
("Up / Down", "Select entry"),
|
||||||
|
("Space / Right", "Expand entry"),
|
||||||
|
("Left", "Collapse entry"),
|
||||||
|
("Shift+Click / Shift+Up / Down", "Select a range of entries"),
|
||||||
|
("Ctrl/Cmd+C", "Copy selected entries"),
|
||||||
|
("PageUp / PageDown", "Scroll a page"),
|
||||||
|
("Home / End", "Start / end of file"),
|
||||||
|
];
|
||||||
|
|
||||||
|
pub const ABOUT_TITLE: &str = "About";
|
||||||
|
pub fn about_version(v: &str) -> String {
|
||||||
|
format!("Version {v}")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const START_HINT: &str = "Open a log file (Ctrl+O), drop files or a folder here, or pick a recent file.";
|
||||||
|
pub const START_OPEN: &str = "Open file…";
|
||||||
|
|
||||||
|
pub const DROP_RULES_NEEDS_LOG: &str = "Open a log file first, then drop the rule file on it";
|
||||||
|
pub fn cannot_save_settings(e: impl Display) -> String {
|
||||||
|
format!("Cannot save settings: {e:#}")
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----- log tab: toolbar -----
|
||||||
|
|
||||||
|
pub const TB_ENTRY_START: &str = "✏ 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_WRAP_TIP: &str = "Line wrap (Alt+Z)";
|
||||||
|
pub const TB_HIGHLIGHTS: &str = "🎨 Highlights";
|
||||||
|
|
||||||
|
pub const FILE_GONE: &str = "The file was deleted or moved. Showing the last version.";
|
||||||
|
|
||||||
|
// ----- log tab: search -----
|
||||||
|
|
||||||
|
pub const SEARCH_HINT: &str = "Search (Ctrl+F)";
|
||||||
|
pub const SEARCH_PREV_ICON: &str = "⏶";
|
||||||
|
pub const SEARCH_PREV_TIP: &str = "Previous match (Shift+Enter, Shift+F3)";
|
||||||
|
pub const SEARCH_NEXT_ICON: &str = "⏷";
|
||||||
|
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";
|
||||||
|
pub const INVALID_REGEX: &str = "invalid regex";
|
||||||
|
pub const SEARCH_CAPPED: &str = " (too many matches, capped at 1M)";
|
||||||
|
|
||||||
|
pub fn match_pos(pos: &str, total: &str) -> String {
|
||||||
|
format!("match {pos} of {total}")
|
||||||
|
}
|
||||||
|
pub fn match_count(total: &str) -> String {
|
||||||
|
format!("{total} matches")
|
||||||
|
}
|
||||||
|
pub fn searching_pct(p: f32) -> String {
|
||||||
|
format!(" (searching {:.0}%)", p * 100.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----- log tab: filter bar -----
|
||||||
|
|
||||||
|
pub const FILTER_LABEL: &str = "Filter:";
|
||||||
|
pub const FILTER_NOT: &str = "not";
|
||||||
|
pub const FILTER_ONLY: &str = "only";
|
||||||
|
pub const FILTER_KIND_TIP: &str = "Switch between Exclude and Only";
|
||||||
|
pub const FILTER_HINT: &str = "keyword";
|
||||||
|
pub const FILTER_ADD_EXCLUDE: &str = "− Exclude";
|
||||||
|
pub const FILTER_ADD_EXCLUDE_TIP: &str = "Hide entries containing this";
|
||||||
|
pub const FILTER_ADD_ONLY: &str = "+ Only";
|
||||||
|
pub const FILTER_ADD_ONLY_TIP: &str = "Show only entries containing this";
|
||||||
|
|
||||||
|
// ----- log tab: status bar -----
|
||||||
|
|
||||||
|
pub const ENCODING_UTF8: &str = "UTF-8";
|
||||||
|
pub const FILE_GREW: &str = "file grew on disk";
|
||||||
|
pub const RELOAD: &str = "Reload";
|
||||||
|
|
||||||
|
pub fn indexing_pct(p: f32) -> String {
|
||||||
|
format!("indexing {:.0}%", p * 100.0)
|
||||||
|
}
|
||||||
|
pub fn entries_of(visible: &str, total: &str) -> String {
|
||||||
|
format!("{visible} of {total} entries")
|
||||||
|
}
|
||||||
|
pub fn entries(total: &str) -> String {
|
||||||
|
format!("{total} entries")
|
||||||
|
}
|
||||||
|
pub fn filtering_pct(p: f32) -> String {
|
||||||
|
format!(" (filtering {:.0}%)", p * 100.0)
|
||||||
|
}
|
||||||
|
pub fn lines(n: &str) -> String {
|
||||||
|
format!(" · {n} lines")
|
||||||
|
}
|
||||||
|
pub fn indexed_in(secs: f32) -> String {
|
||||||
|
format!(" · indexed in {secs:.2} s")
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----- log tab: view -----
|
||||||
|
|
||||||
|
pub const VIEW_INDEXING: &str = "Indexing…";
|
||||||
|
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 fn more_lines_badge(n: u32) -> String {
|
||||||
|
format!(" +{n} lines ")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const CTX_COPY_ENTRY: &str = "Copy entry";
|
||||||
|
pub const CTX_SHOW_FULL: &str = "Show full entry";
|
||||||
|
pub const CTX_COLLAPSE: &str = "Collapse";
|
||||||
|
pub const CTX_EXPAND: &str = "Expand";
|
||||||
|
pub const CTX_FILTER_LIKE: &str = "Filter out entries like this";
|
||||||
|
pub const CTX_HIGHLIGHT_LIKE: &str = "Highlight entries like this";
|
||||||
|
pub fn ctx_copy_selected(n: &str) -> String {
|
||||||
|
format!("Copy {n} selected entries")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn entry_title(n: u32) -> String {
|
||||||
|
format!("Entry {n}")
|
||||||
|
}
|
||||||
|
pub fn bytes(n: &str) -> String {
|
||||||
|
format!("{n} bytes")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const GOTO_TITLE: &str = "Go to line";
|
||||||
|
pub const GOTO_HINT: &str = "line number";
|
||||||
|
pub const GOTO_GO: &str = "Go";
|
||||||
|
pub const GOTO_NOT_READY: &str = "indexing not finished yet";
|
||||||
|
pub fn goto_out_of_range(total: impl Display) -> String {
|
||||||
|
format!("line must be 1–{total}")
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----- entry-start pattern panel -----
|
||||||
|
|
||||||
|
pub const PATTERN_TITLE: &str = "Entry start pattern";
|
||||||
|
pub const PATTERN_HELP: &str = "A line that matches starts a new entry; other lines continue the entry above.";
|
||||||
|
pub const PATTERN_PRESET: &str = "Preset";
|
||||||
|
pub const PATTERN_REMEMBER_PATH: &str = "Remember for this file";
|
||||||
|
pub const PATTERN_REMEMBER_GLOB: &str = "Also for files named";
|
||||||
|
pub const PATTERN_APPLY: &str = "Apply";
|
||||||
|
pub const PATTERN_REDETECT: &str = "Re-detect";
|
||||||
|
pub const PATTERN_PREVIEW: &str = "Preview";
|
||||||
|
pub fn pattern_sample_score(starts: usize, lines: usize, score: f32) -> String {
|
||||||
|
format!("{starts} entries in sample of {lines} lines · score {score:.2}")
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----- highlight rules panel -----
|
||||||
|
|
||||||
|
pub const RULES_TITLE: &str = "Highlight rules";
|
||||||
|
pub const RULES_HELP: &str = "First matching row rule tints the entry; all match rules color their text.";
|
||||||
|
pub const SCOPE_ROW: &str = "row";
|
||||||
|
pub const SCOPE_MATCH: &str = "match";
|
||||||
|
pub const RULES_ADD: &str = "+ Add rule";
|
||||||
|
pub const RULES_FILES: &str = "Rule files";
|
||||||
|
pub const RULES_IMPORT_DOTS: &str = "Import…";
|
||||||
|
pub const RULES_SAVE_GLOBAL: &str = "Save as global default";
|
||||||
|
pub const RULES_SAVE_GLOBAL_TIP: &str = "Rules for newly opened files";
|
||||||
|
pub const RULES_SAVED_GLOBAL: &str = "Saved rules as the global default";
|
||||||
|
pub const RULES_SAVE_FOR_GLOB: &str = "Save for files matching";
|
||||||
|
pub const RULESETS_TITLE: &str = "Named rule sets";
|
||||||
|
pub const RULESETS_NONE: &str = "(none saved)";
|
||||||
|
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";
|
||||||
|
|
||||||
|
pub fn swatch_label(name: &str) -> String {
|
||||||
|
format!("■ {name}")
|
||||||
|
}
|
||||||
|
pub fn rules_saved_for(glob: &str) -> String {
|
||||||
|
format!("Saved rules for {glob}")
|
||||||
|
}
|
||||||
|
pub fn ruleset_loaded(name: &str, skipped: usize) -> String {
|
||||||
|
if skipped == 0 {
|
||||||
|
format!("Loaded rule set {name}")
|
||||||
|
} else {
|
||||||
|
format!("Loaded rule set {name} ({skipped} invalid rules skipped)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn ruleset_load_failed(name: &str, e: impl Display) -> String {
|
||||||
|
format!("Cannot load {name}: {e:#}")
|
||||||
|
}
|
||||||
|
pub fn ruleset_saved(name: &str) -> String {
|
||||||
|
format!("Saved rule set {name}")
|
||||||
|
}
|
||||||
|
pub fn cannot_save(e: impl Display) -> String {
|
||||||
|
format!("Cannot save: {e:#}")
|
||||||
|
}
|
||||||
|
pub fn cannot_read(path: &Path, e: impl Display) -> String {
|
||||||
|
format!("Cannot read {}: {e:#}", path.display())
|
||||||
|
}
|
||||||
|
pub fn cannot_write(path: &Path, e: impl Display) -> String {
|
||||||
|
format!("Cannot write {}: {e:#}", path.display())
|
||||||
|
}
|
||||||
|
pub fn not_a_rule_file(e: impl Display) -> String {
|
||||||
|
format!("Not a rule file: {e:#}")
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----- import / export rule dialogs -----
|
||||||
|
|
||||||
|
pub const IMPORT_TITLE: &str = "Import rules";
|
||||||
|
pub const IMPORT_MERGE: &str = "Merge (skip duplicates)";
|
||||||
|
pub const IMPORT_REPLACE: &str = "Replace";
|
||||||
|
pub const IMPORT_TO_TAB: &str = "Apply to this tab";
|
||||||
|
pub const IMPORT_TO_GLOBAL: &str = "Save as global default";
|
||||||
|
pub fn import_summary(path: &Path, n: usize) -> String {
|
||||||
|
format!("{} — {n} rules", path.display())
|
||||||
|
}
|
||||||
|
pub fn import_invalid(n: usize) -> String {
|
||||||
|
format!("{n} invalid rules will be skipped:")
|
||||||
|
}
|
||||||
|
pub fn import_use_pattern(name: &str) -> String {
|
||||||
|
format!("Use entry-start pattern “{name}”")
|
||||||
|
}
|
||||||
|
pub fn imported(n: usize) -> String {
|
||||||
|
format!("Imported {n} rules")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const EXPORT_TITLE: &str = "Export rules";
|
||||||
|
pub const EXPORT_ALL: &str = "Everything";
|
||||||
|
pub const EXPORT_FILTERS: &str = "Filters";
|
||||||
|
pub const EXPORT_HIGHLIGHTS: &str = "Highlights";
|
||||||
|
pub const EXPORT_SELECTED: &str = "Selected";
|
||||||
|
pub const EXPORT_SAVE: &str = "Save…";
|
||||||
|
pub fn export_include_pattern(name: &str) -> String {
|
||||||
|
format!("Include entry-start pattern “{name}”")
|
||||||
|
}
|
||||||
|
pub fn exported(n: usize, path: &Path) -> String {
|
||||||
|
format!("Exported {n} rules to {}", path.display())
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----- find in files -----
|
||||||
|
|
||||||
|
pub const GREP_TITLE: &str = "Find in files";
|
||||||
|
pub fn grep_title_in(folder: &str) -> String {
|
||||||
|
format!("Find in {folder}")
|
||||||
|
}
|
||||||
|
pub const GREP_FOLDER: &str = "Folder";
|
||||||
|
pub const GREP_BROWSE: &str = "Browse…";
|
||||||
|
pub const GREP_PATTERN: &str = "Pattern";
|
||||||
|
pub const GREP_PATTERN_HINT: &str = "text or regex";
|
||||||
|
pub const GREP_INCLUDE: &str = "Include";
|
||||||
|
pub const GREP_EXCLUDE: &str = "Exclude";
|
||||||
|
pub const GREP_EXCLUDE_HINT: &str = "*.gz;old/**";
|
||||||
|
pub const GREP_RECURSIVE: &str = "Recursive";
|
||||||
|
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_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";
|
||||||
|
pub const GREP_HELP: &str = "Pick a folder and a pattern, then press Search. Double-click a hit to open it.";
|
||||||
|
pub const GREP_OPEN: &str = "Open in viewer";
|
||||||
|
pub const GREP_NEED_PATTERN: &str = "Enter a pattern";
|
||||||
|
pub fn grep_not_a_folder(path: &Path) -> String {
|
||||||
|
format!("{} is not a folder", path.display())
|
||||||
|
}
|
||||||
|
pub fn grep_summary(matches: &str, files: &str, searched: &str, running: bool) -> String {
|
||||||
|
let tail = if running { " (searching…)" } else { "" };
|
||||||
|
format!("{matches} matches in {files} of {searched} files{tail}")
|
||||||
|
}
|
||||||
|
pub fn grep_errors(n: usize) -> String {
|
||||||
|
format!("{n} errors")
|
||||||
|
}
|
||||||
|
pub fn grep_file_row(arrow: &str, path: &str, hits: &str, truncated: bool, size: &str) -> String {
|
||||||
|
let plus = if truncated { "+" } else { "" };
|
||||||
|
format!("{arrow} {path} ({hits} matches{plus}, {size})")
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----- errors from the non-UI modules -----
|
||||||
|
|
||||||
|
pub fn cannot_open(path: &Path) -> String {
|
||||||
|
format!("cannot open {}", path.display())
|
||||||
|
}
|
||||||
|
pub fn cannot_read_metadata(path: &Path) -> String {
|
||||||
|
format!("cannot read metadata of {}", path.display())
|
||||||
|
}
|
||||||
|
pub fn is_a_folder(path: &Path) -> String {
|
||||||
|
format!("{} is a folder, not a file", path.display())
|
||||||
|
}
|
||||||
|
pub fn cannot_map(path: &Path) -> String {
|
||||||
|
format!("cannot map {}", path.display())
|
||||||
|
}
|
||||||
|
pub const INVALID_PATTERN: &str = "invalid pattern";
|
||||||
|
pub const EMPTY_PATTERN: &str = "empty pattern";
|
||||||
|
pub const NO_CONFIG_FOLDER: &str = "no config folder";
|
||||||
|
pub fn bad_include_glob(g: &str) -> String {
|
||||||
|
format!("bad include glob {g}")
|
||||||
|
}
|
||||||
|
pub fn bad_exclude_glob(g: &str) -> String {
|
||||||
|
format!("bad exclude glob {g}")
|
||||||
|
}
|
||||||
|
pub fn rule_file_too_new(found: impl Display, supported: impl Display) -> String {
|
||||||
|
format!("rule file version {found} is newer than this app supports ({supported})")
|
||||||
|
}
|
||||||
|
pub fn invalid_rule(kind: impl std::fmt::Debug, pattern: &str, e: impl Display) -> String {
|
||||||
|
format!("{kind:?} rule `{pattern}`: {e:#}")
|
||||||
|
}
|
||||||
|
pub fn invalid_entry_pattern(regex: &str, e: impl Display) -> String {
|
||||||
|
format!("entry-start pattern `{regex}`: {e:#}")
|
||||||
|
}
|
||||||
+48
-42
@@ -11,6 +11,7 @@ use egui::{Key, RichText, TextFormat, Ui};
|
|||||||
use crate::grep::{self, GrepOptions, GrepShared};
|
use crate::grep::{self, GrepOptions, GrepShared};
|
||||||
use crate::job::{Generation, Notify};
|
use crate::job::{Generation, Notify};
|
||||||
use crate::passes::SearchQuery;
|
use crate::passes::SearchQuery;
|
||||||
|
use crate::strings as tr;
|
||||||
use crate::ui::log_tab::{fmt_num, fmt_size};
|
use crate::ui::log_tab::{fmt_num, fmt_size};
|
||||||
use crate::ui::palette;
|
use crate::ui::palette;
|
||||||
|
|
||||||
@@ -62,8 +63,8 @@ impl GrepTab {
|
|||||||
|
|
||||||
pub fn title(&self) -> String {
|
pub fn title(&self) -> String {
|
||||||
match self.opts.folder.file_name() {
|
match self.opts.folder.file_name() {
|
||||||
Some(n) => format!("Find in {}", n.to_string_lossy()),
|
Some(n) => tr::grep_title_in(&n.to_string_lossy()),
|
||||||
None => "Find in files".into(),
|
None => tr::GREP_TITLE.into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,11 +81,11 @@ impl GrepTab {
|
|||||||
self.selected = None;
|
self.selected = None;
|
||||||
self.rows_key = (usize::MAX, 0);
|
self.rows_key = (usize::MAX, 0);
|
||||||
if self.opts.query.text.is_empty() {
|
if self.opts.query.text.is_empty() {
|
||||||
self.error = Some("Enter a pattern".into());
|
self.error = Some(tr::GREP_NEED_PATTERN.into());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if !self.opts.folder.is_dir() {
|
if !self.opts.folder.is_dir() {
|
||||||
self.error = Some(format!("{} is not a folder", self.opts.folder.display()));
|
self.error = Some(tr::grep_not_a_folder(&self.opts.folder));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
match grep::spawn(self.opts.clone(), self.generation.bump(), self.notify.clone()) {
|
match grep::spawn(self.opts.clone(), self.generation.bump(), self.notify.clone()) {
|
||||||
@@ -125,10 +126,10 @@ impl GrepTab {
|
|||||||
fn inputs(&mut self, ui: &mut Ui, _actions: &mut [GrepAction]) {
|
fn inputs(&mut self, ui: &mut Ui, _actions: &mut [GrepAction]) {
|
||||||
let mut go = false;
|
let mut go = false;
|
||||||
egui::Grid::new("grep_grid").num_columns(2).spacing([8.0, 4.0]).show(ui, |ui| {
|
egui::Grid::new("grep_grid").num_columns(2).spacing([8.0, 4.0]).show(ui, |ui| {
|
||||||
ui.label("Folder");
|
ui.label(tr::GREP_FOLDER);
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.add(egui::TextEdit::singleline(&mut self.folder_text).desired_width(420.0));
|
ui.add(egui::TextEdit::singleline(&mut self.folder_text).desired_width(420.0));
|
||||||
if ui.button("Browse…").clicked()
|
if ui.button(tr::GREP_BROWSE).clicked()
|
||||||
&& let Some(d) = rfd::FileDialog::new().pick_folder()
|
&& let Some(d) = rfd::FileDialog::new().pick_folder()
|
||||||
{
|
{
|
||||||
self.folder_text = d.display().to_string();
|
self.folder_text = d.display().to_string();
|
||||||
@@ -136,46 +137,52 @@ impl GrepTab {
|
|||||||
});
|
});
|
||||||
ui.end_row();
|
ui.end_row();
|
||||||
|
|
||||||
ui.label("Pattern");
|
ui.label(tr::GREP_PATTERN);
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
let r = ui.add(
|
let r = ui.add(
|
||||||
egui::TextEdit::singleline(&mut self.opts.query.text)
|
egui::TextEdit::singleline(&mut self.opts.query.text)
|
||||||
.desired_width(320.0)
|
.desired_width(320.0)
|
||||||
.hint_text("text or regex"),
|
.hint_text(tr::GREP_PATTERN_HINT),
|
||||||
);
|
);
|
||||||
go |= r.lost_focus() && ui.input(|i| i.key_pressed(Key::Enter));
|
go |= r.lost_focus() && ui.input(|i| i.key_pressed(Key::Enter));
|
||||||
ui.toggle_value(&mut self.opts.query.regex, ".*").on_hover_text("Regex");
|
ui.toggle_value(&mut self.opts.query.regex, tr::REGEX_ICON).on_hover_text(tr::REGEX_TIP);
|
||||||
ui.toggle_value(&mut self.opts.query.case_sensitive, "Aa").on_hover_text("Case sensitive");
|
ui.toggle_value(&mut self.opts.query.case_sensitive, tr::CASE_ICON).on_hover_text(tr::CASE_TIP);
|
||||||
ui.toggle_value(&mut self.opts.query.whole_word, "\\b").on_hover_text("Whole word");
|
ui.toggle_value(&mut self.opts.query.whole_word, tr::WORD_ICON).on_hover_text(tr::WORD_TIP);
|
||||||
});
|
});
|
||||||
ui.end_row();
|
ui.end_row();
|
||||||
|
|
||||||
ui.label("Include");
|
ui.label(tr::GREP_INCLUDE);
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.add(egui::TextEdit::singleline(&mut self.opts.include).desired_width(180.0));
|
ui.add(egui::TextEdit::singleline(&mut self.opts.include).desired_width(180.0));
|
||||||
ui.label("Exclude");
|
ui.label(tr::GREP_EXCLUDE);
|
||||||
ui.add(
|
ui.add(
|
||||||
egui::TextEdit::singleline(&mut self.opts.exclude).desired_width(140.0).hint_text("*.gz;old/**"),
|
egui::TextEdit::singleline(&mut self.opts.exclude)
|
||||||
|
.desired_width(140.0)
|
||||||
|
.hint_text(tr::GREP_EXCLUDE_HINT),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
ui.end_row();
|
ui.end_row();
|
||||||
|
|
||||||
ui.label("");
|
ui.label("");
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.checkbox(&mut self.opts.recursive, "Recursive");
|
ui.checkbox(&mut self.opts.recursive, tr::GREP_RECURSIVE);
|
||||||
ui.checkbox(&mut self.opts.respect_gitignore, "Respect .gitignore");
|
ui.checkbox(&mut self.opts.respect_gitignore, tr::GREP_GITIGNORE);
|
||||||
ui.checkbox(&mut self.opts.skip_binary, "Skip binary files");
|
ui.checkbox(&mut self.opts.skip_binary, tr::GREP_SKIP_BINARY);
|
||||||
ui.label("Max size (MB)");
|
ui.label(tr::GREP_MAX_SIZE);
|
||||||
ui.add(egui::TextEdit::singleline(&mut self.max_mb_text).desired_width(50.0).hint_text("any"));
|
ui.add(
|
||||||
|
egui::TextEdit::singleline(&mut self.max_mb_text)
|
||||||
|
.desired_width(50.0)
|
||||||
|
.hint_text(tr::GREP_MAX_SIZE_HINT),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
ui.end_row();
|
ui.end_row();
|
||||||
});
|
});
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
let running = self.shared.as_ref().is_some_and(|s| !s.is_done());
|
let running = self.shared.as_ref().is_some_and(|s| !s.is_done());
|
||||||
if ui.button("🔍 Search").clicked() || go {
|
if ui.button(tr::GREP_SEARCH).clicked() || go {
|
||||||
self.start();
|
self.start();
|
||||||
}
|
}
|
||||||
if running && ui.button("Cancel").clicked() {
|
if running && ui.button(tr::CANCEL).clicked() {
|
||||||
self.cancel();
|
self.cancel();
|
||||||
if let Some(s) = &self.shared {
|
if let Some(s) = &self.shared {
|
||||||
s.done.store(true, Ordering::Release);
|
s.done.store(true, Ordering::Release);
|
||||||
@@ -185,28 +192,27 @@ impl GrepTab {
|
|||||||
let files = s.results.lock().unwrap();
|
let files = s.results.lock().unwrap();
|
||||||
let matches: usize = files.iter().map(|f| f.hits.len()).sum();
|
let matches: usize = files.iter().map(|f| f.hits.len()).sum();
|
||||||
let searched = s.files_searched.load(Ordering::Relaxed);
|
let searched = s.files_searched.load(Ordering::Relaxed);
|
||||||
ui.label(format!(
|
ui.label(tr::grep_summary(
|
||||||
"{} matches in {} of {} files{}",
|
&fmt_num(matches as u64),
|
||||||
fmt_num(matches as u64),
|
&fmt_num(files.len() as u64),
|
||||||
fmt_num(files.len() as u64),
|
&fmt_num(searched as u64),
|
||||||
fmt_num(searched as u64),
|
running,
|
||||||
if running { " (searching…)" } else { "" }
|
|
||||||
));
|
));
|
||||||
if s.capped.load(Ordering::Relaxed) || files.iter().any(|f| f.truncated) {
|
if s.capped.load(Ordering::Relaxed) || files.iter().any(|f| f.truncated) {
|
||||||
ui.colored_label(ui.visuals().warn_fg_color, "results capped (10,000 per file, 1M total)");
|
ui.colored_label(ui.visuals().warn_fg_color, tr::GREP_CAPPED);
|
||||||
}
|
}
|
||||||
let errs = s.errors.lock().unwrap();
|
let errs = s.errors.lock().unwrap();
|
||||||
if !errs.is_empty() {
|
if !errs.is_empty() {
|
||||||
ui.colored_label(ui.visuals().warn_fg_color, format!("{} errors", errs.len()))
|
ui.colored_label(ui.visuals().warn_fg_color, tr::grep_errors(errs.len()))
|
||||||
.on_hover_text(errs.iter().take(20).cloned().collect::<Vec<_>>().join("\n"));
|
.on_hover_text(errs.iter().take(20).cloned().collect::<Vec<_>>().join("\n"));
|
||||||
}
|
}
|
||||||
drop(errs);
|
drop(errs);
|
||||||
if !files.is_empty() {
|
if !files.is_empty() {
|
||||||
if ui.button("📋 Copy").on_hover_text("Copy as path:line:text").clicked() {
|
if ui.button(tr::COPY).on_hover_text(tr::GREP_COPY_TIP).clicked() {
|
||||||
ui.ctx().copy_text(grep::export_text(&files));
|
ui.ctx().copy_text(grep::export_text(&files));
|
||||||
}
|
}
|
||||||
if ui.button("Export…").clicked()
|
if ui.button(tr::EXPORT_DOTS).clicked()
|
||||||
&& let Some(p) = rfd::FileDialog::new().set_file_name("grep-results.txt").save_file()
|
&& let Some(p) = rfd::FileDialog::new().set_file_name(tr::GREP_EXPORT_FILE).save_file()
|
||||||
{
|
{
|
||||||
let _ = std::fs::write(p, grep::export_text(&files));
|
let _ = std::fs::write(p, grep::export_text(&files));
|
||||||
}
|
}
|
||||||
@@ -220,7 +226,7 @@ impl GrepTab {
|
|||||||
|
|
||||||
fn results(&mut self, ui: &mut Ui, actions: &mut Vec<GrepAction>) {
|
fn results(&mut self, ui: &mut Ui, actions: &mut Vec<GrepAction>) {
|
||||||
let Some(shared) = self.shared.clone() else {
|
let Some(shared) = self.shared.clone() else {
|
||||||
ui.weak("Pick a folder and a pattern, then press Search. Double-click a hit to open it.");
|
ui.weak(tr::GREP_HELP);
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let files = shared.results.lock().unwrap();
|
let files = shared.results.lock().unwrap();
|
||||||
@@ -259,13 +265,13 @@ impl GrepTab {
|
|||||||
match self.rows[i] {
|
match self.rows[i] {
|
||||||
Row::File(fi) => {
|
Row::File(fi) => {
|
||||||
let f = &files[fi];
|
let f = &files[fi];
|
||||||
let arrow = if self.collapsed.contains(&fi) { "▶" } else { "▼" };
|
let arrow = tr::arrow(!self.collapsed.contains(&fi));
|
||||||
let text = format!(
|
let text = tr::grep_file_row(
|
||||||
"{arrow} {} ({} matches{}, {})",
|
arrow,
|
||||||
grep::display_path(&root, &f.path),
|
&grep::display_path(&root, &f.path),
|
||||||
fmt_num(f.hits.len() as u64),
|
&fmt_num(f.hits.len() as u64),
|
||||||
if f.truncated { "+" } else { "" },
|
f.truncated,
|
||||||
fmt_size(f.size)
|
&fmt_size(f.size),
|
||||||
);
|
);
|
||||||
let r = ui.selectable_label(selected, RichText::new(text).strong());
|
let r = ui.selectable_label(selected, RichText::new(text).strong());
|
||||||
if r.clicked() {
|
if r.clicked() {
|
||||||
@@ -301,11 +307,11 @@ impl GrepTab {
|
|||||||
open = Some((fi, hi));
|
open = Some((fi, hi));
|
||||||
}
|
}
|
||||||
r.context_menu(|ui| {
|
r.context_menu(|ui| {
|
||||||
if ui.button("Open in viewer").clicked() {
|
if ui.button(tr::GREP_OPEN).clicked() {
|
||||||
open = Some((fi, hi));
|
open = Some((fi, hi));
|
||||||
ui.close();
|
ui.close();
|
||||||
}
|
}
|
||||||
if ui.button("Copy line").clicked() {
|
if ui.button(tr::COPY_LINE).clicked() {
|
||||||
ui.ctx().copy_text(h.text.clone());
|
ui.ctx().copy_text(h.text.clone());
|
||||||
ui.close();
|
ui.close();
|
||||||
}
|
}
|
||||||
|
|||||||
+61
-62
@@ -17,6 +17,7 @@ use crate::rowmap::{RowMap, Visible};
|
|||||||
use crate::rules::{self, CompiledFilter, CompiledHighlight, Rule, RuleKind, Scope};
|
use crate::rules::{self, CompiledFilter, CompiledHighlight, Rule, RuleKind, Scope};
|
||||||
use crate::settings::Settings;
|
use crate::settings::Settings;
|
||||||
use crate::source::{ByteSource, MmapSource};
|
use crate::source::{ByteSource, MmapSource};
|
||||||
|
use crate::strings as tr;
|
||||||
use crate::ui::palette;
|
use crate::ui::palette;
|
||||||
use crate::ui::panels::{PatternEditor, RulesDialog};
|
use crate::ui::panels::{PatternEditor, RulesDialog};
|
||||||
use crate::ui::text::{self, LineSpec, MAX_LINE_SHOWN, Style};
|
use crate::ui::text::{self, LineSpec, MAX_LINE_SHOWN, Style};
|
||||||
@@ -652,10 +653,10 @@ impl LogTab {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn goto_line(&mut self, line_1: u64) -> Result<(), String> {
|
pub fn goto_line(&mut self, line_1: u64) -> Result<(), String> {
|
||||||
let Some(prefix) = &self.line_prefix else { return Err("indexing not finished yet".into()) };
|
let Some(prefix) = &self.line_prefix else { return Err(tr::GOTO_NOT_READY.into()) };
|
||||||
let total = *prefix.last().unwrap_or(&0);
|
let total = *prefix.last().unwrap_or(&0);
|
||||||
if line_1 == 0 || line_1 > total {
|
if line_1 == 0 || line_1 > total {
|
||||||
return Err(format!("line must be 1–{total}"));
|
return Err(tr::goto_out_of_range(total));
|
||||||
}
|
}
|
||||||
let line0 = line_1 - 1;
|
let line0 = line_1 - 1;
|
||||||
let entry = prefix.partition_point(|&p| p <= line0) - 1;
|
let entry = prefix.partition_point(|&p| p <= line0) - 1;
|
||||||
@@ -728,14 +729,14 @@ impl LogTab {
|
|||||||
let total = matches.len();
|
let total = matches.len();
|
||||||
let pos = self.search.current.map(|c| matches.partition_point(|m| *m < c) + 1);
|
let pos = self.search.current.map(|c| matches.partition_point(|m| *m < c) + 1);
|
||||||
let mut out = match pos {
|
let mut out = match pos {
|
||||||
Some(p) => format!("match {} of {}", fmt_num(p as u64), fmt_num(total as u64)),
|
Some(p) => tr::match_pos(&fmt_num(p as u64), &fmt_num(total as u64)),
|
||||||
None => format!("{} matches", fmt_num(total as u64)),
|
None => tr::match_count(&fmt_num(total as u64)),
|
||||||
};
|
};
|
||||||
if s.capped.load(std::sync::atomic::Ordering::Relaxed) {
|
if s.capped.load(std::sync::atomic::Ordering::Relaxed) {
|
||||||
out.push_str(" (too many matches, capped at 1M)");
|
out.push_str(tr::SEARCH_CAPPED);
|
||||||
}
|
}
|
||||||
if !s.is_done() {
|
if !s.is_done() {
|
||||||
out.push_str(&format!(" (searching {:.0}%)", s.progress() * 100.0));
|
out.push_str(&tr::searching_pct(s.progress()));
|
||||||
}
|
}
|
||||||
Some(out)
|
Some(out)
|
||||||
}
|
}
|
||||||
@@ -745,19 +746,19 @@ impl LogTab {
|
|||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
match &self.filter.shared {
|
match &self.filter.shared {
|
||||||
Some(f) => {
|
Some(f) => {
|
||||||
s.push_str(&format!("{} of {} entries", fmt_num(self.visible.len() as u64), fmt_num(idx_len)));
|
s.push_str(&tr::entries_of(&fmt_num(self.visible.len() as u64), &fmt_num(idx_len)));
|
||||||
if !f.is_done() {
|
if !f.is_done() {
|
||||||
s.push_str(&format!(" (filtering {:.0}%)", f.progress() * 100.0));
|
s.push_str(&tr::filtering_pct(f.progress()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => s.push_str(&format!("{} entries", fmt_num(idx_len))),
|
None => s.push_str(&tr::entries(&fmt_num(idx_len))),
|
||||||
}
|
}
|
||||||
if let Some(p) = &self.line_prefix {
|
if let Some(p) = &self.line_prefix {
|
||||||
s.push_str(&format!(" · {} lines", fmt_num(*p.last().unwrap_or(&0))));
|
s.push_str(&tr::lines(&fmt_num(*p.last().unwrap_or(&0))));
|
||||||
}
|
}
|
||||||
s.push_str(&format!(" · {}", fmt_size(self.file_len)));
|
s.push_str(&format!(" · {}", fmt_size(self.file_len)));
|
||||||
if let Some(t) = self.index_elapsed {
|
if let Some(t) = self.index_elapsed {
|
||||||
s.push_str(&format!(" · indexed in {:.2} s", t.as_secs_f32()));
|
s.push_str(&tr::indexed_in(t.as_secs_f32()));
|
||||||
}
|
}
|
||||||
s
|
s
|
||||||
}
|
}
|
||||||
@@ -772,7 +773,7 @@ impl LogTab {
|
|||||||
s.pop();
|
s.pop();
|
||||||
}
|
}
|
||||||
if end < r.end {
|
if end < r.end {
|
||||||
s.push_str("\n… (cut)");
|
s.push_str(tr::ENTRY_CUT);
|
||||||
}
|
}
|
||||||
s
|
s
|
||||||
}
|
}
|
||||||
@@ -930,10 +931,7 @@ impl LogTab {
|
|||||||
ui.colored_label(ui.visuals().error_fg_color, e);
|
ui.colored_label(ui.visuals().error_fg_color, e);
|
||||||
}
|
}
|
||||||
if self.file_missing {
|
if self.file_missing {
|
||||||
ui.colored_label(
|
ui.colored_label(ui.visuals().warn_fg_color, tr::FILE_GONE);
|
||||||
ui.visuals().warn_fg_color,
|
|
||||||
"The file was deleted or moved. Showing the last version.",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
self.log_view(ui, settings);
|
self.log_view(ui, settings);
|
||||||
});
|
});
|
||||||
@@ -943,7 +941,7 @@ impl LogTab {
|
|||||||
|
|
||||||
fn toolbar(&mut self, ui: &mut Ui, settings: &mut Settings, actions: &mut Vec<TabAction>) {
|
fn toolbar(&mut self, ui: &mut Ui, settings: &mut Settings, actions: &mut Vec<TabAction>) {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
if ui.button("✏ Entry start").on_hover_text("Edit the entry-start pattern").clicked() {
|
if ui.button(tr::TB_ENTRY_START).on_hover_text(tr::TB_ENTRY_START_TIP).clicked() {
|
||||||
self.pattern_editor = match self.pattern_editor {
|
self.pattern_editor = match self.pattern_editor {
|
||||||
Some(_) => None,
|
Some(_) => None,
|
||||||
None => Some(PatternEditor::new(self, settings)),
|
None => Some(PatternEditor::new(self, settings)),
|
||||||
@@ -952,17 +950,17 @@ impl LogTab {
|
|||||||
ui.label(egui::RichText::new(&self.pattern.name).strong())
|
ui.label(egui::RichText::new(&self.pattern.name).strong())
|
||||||
.on_hover_text(format!("^{}", self.pattern.regex));
|
.on_hover_text(format!("^{}", self.pattern.regex));
|
||||||
ui.separator();
|
ui.separator();
|
||||||
if ui.button("⊞ Expand all").clicked() {
|
if ui.button(tr::TB_EXPAND_ALL).clicked() {
|
||||||
self.set_expand_all(true);
|
self.set_expand_all(true);
|
||||||
}
|
}
|
||||||
if ui.button("⊟ Collapse all").clicked() {
|
if ui.button(tr::TB_COLLAPSE_ALL).clicked() {
|
||||||
self.set_expand_all(false);
|
self.set_expand_all(false);
|
||||||
}
|
}
|
||||||
let wrap = ui.toggle_value(&mut self.wrap, "↩ Wrap").on_hover_text("Line wrap (Alt+Z)");
|
let wrap = ui.toggle_value(&mut self.wrap, tr::TB_WRAP).on_hover_text(tr::TB_WRAP_TIP);
|
||||||
if wrap.changed() {
|
if wrap.changed() {
|
||||||
self.wrap_changed(settings, actions);
|
self.wrap_changed(settings, actions);
|
||||||
}
|
}
|
||||||
ui.toggle_value(&mut self.show_rules, "🎨 Highlights");
|
ui.toggle_value(&mut self.show_rules, tr::TB_HIGHLIGHTS);
|
||||||
ui.separator();
|
ui.separator();
|
||||||
self.search_box(ui);
|
self.search_box(ui);
|
||||||
});
|
});
|
||||||
@@ -978,7 +976,7 @@ impl LogTab {
|
|||||||
|
|
||||||
fn search_box(&mut self, ui: &mut Ui) {
|
fn search_box(&mut self, ui: &mut Ui) {
|
||||||
ui.label("🔍");
|
ui.label("🔍");
|
||||||
let edit = egui::TextEdit::singleline(&mut self.search.text).hint_text("Search (Ctrl+F)").desired_width(220.0);
|
let edit = egui::TextEdit::singleline(&mut self.search.text).hint_text(tr::SEARCH_HINT).desired_width(220.0);
|
||||||
let resp = ui.add(edit);
|
let resp = ui.add(edit);
|
||||||
if self.search.focus {
|
if self.search.focus {
|
||||||
resp.request_focus();
|
resp.request_focus();
|
||||||
@@ -993,30 +991,30 @@ impl LogTab {
|
|||||||
resp.request_focus();
|
resp.request_focus();
|
||||||
}
|
}
|
||||||
let mut changed = false;
|
let mut changed = false;
|
||||||
changed |= ui.toggle_value(&mut self.search.regex, ".*").on_hover_text("Regex").changed();
|
changed |= ui.toggle_value(&mut self.search.regex, tr::REGEX_ICON).on_hover_text(tr::REGEX_TIP).changed();
|
||||||
changed |= ui.toggle_value(&mut self.search.case_sensitive, "Aa").on_hover_text("Case sensitive").changed();
|
changed |=
|
||||||
changed |= ui.toggle_value(&mut self.search.whole_word, "\\b").on_hover_text("Whole word").changed();
|
ui.toggle_value(&mut self.search.case_sensitive, tr::CASE_ICON).on_hover_text(tr::CASE_TIP).changed();
|
||||||
|
changed |= ui.toggle_value(&mut self.search.whole_word, tr::WORD_ICON).on_hover_text(tr::WORD_TIP).changed();
|
||||||
if changed {
|
if changed {
|
||||||
self.search_changed();
|
self.search_changed();
|
||||||
}
|
}
|
||||||
if ui.button("⏶").on_hover_text("Previous match (Shift+Enter, Shift+F3)").clicked() {
|
if ui.button(tr::SEARCH_PREV_ICON).on_hover_text(tr::SEARCH_PREV_TIP).clicked() {
|
||||||
self.step_match(false);
|
self.step_match(false);
|
||||||
}
|
}
|
||||||
if ui.button("⏷").on_hover_text("Next match (Enter, F3)").clicked() {
|
if ui.button(tr::SEARCH_NEXT_ICON).on_hover_text(tr::SEARCH_NEXT_TIP).clicked() {
|
||||||
self.step_match(true);
|
self.step_match(true);
|
||||||
}
|
}
|
||||||
if self.filter.shared.is_some() {
|
if self.filter.shared.is_some() {
|
||||||
ui.checkbox(&mut self.search.hidden_too, "hidden too")
|
ui.checkbox(&mut self.search.hidden_too, tr::SEARCH_HIDDEN_TOO).on_hover_text(tr::SEARCH_HIDDEN_TOO_TIP);
|
||||||
.on_hover_text("Also stop at matches in entries hidden by the filter");
|
|
||||||
}
|
}
|
||||||
if let Some(e) = &self.search.error {
|
if let Some(e) = &self.search.error {
|
||||||
ui.colored_label(ui.visuals().error_fg_color, "invalid regex").on_hover_text(e);
|
ui.colored_label(ui.visuals().error_fg_color, tr::INVALID_REGEX).on_hover_text(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn filter_bar(&mut self, ui: &mut Ui) {
|
fn filter_bar(&mut self, ui: &mut Ui) {
|
||||||
ui.horizontal_wrapped(|ui| {
|
ui.horizontal_wrapped(|ui| {
|
||||||
ui.label("Filter:");
|
ui.label(tr::FILTER_LABEL);
|
||||||
let mut remove = None;
|
let mut remove = None;
|
||||||
let mut changed = false;
|
let mut changed = false;
|
||||||
for (i, r) in self.rules.iter_mut().enumerate().filter(|(_, r)| r.is_filter()) {
|
for (i, r) in self.rules.iter_mut().enumerate().filter(|(_, r)| r.is_filter()) {
|
||||||
@@ -1027,8 +1025,8 @@ impl LogTab {
|
|||||||
egui::Frame::new().fill(fill).corner_radius(4.0).inner_margin(vec2(4.0, 1.0)).show(ui, |ui| {
|
egui::Frame::new().fill(fill).corner_radius(4.0).inner_margin(vec2(4.0, 1.0)).show(ui, |ui| {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
changed |= ui.checkbox(&mut r.enabled, "").changed();
|
changed |= ui.checkbox(&mut r.enabled, "").changed();
|
||||||
let label = if r.kind == RuleKind::Exclude { "not" } else { "only" };
|
let label = if r.kind == RuleKind::Exclude { tr::FILTER_NOT } else { tr::FILTER_ONLY };
|
||||||
if ui.small_button(label).on_hover_text("Switch between Exclude and Only").clicked() {
|
if ui.small_button(label).on_hover_text(tr::FILTER_KIND_TIP).clicked() {
|
||||||
r.kind = if r.kind == RuleKind::Exclude { RuleKind::Only } else { RuleKind::Exclude };
|
r.kind = if r.kind == RuleKind::Exclude { RuleKind::Only } else { RuleKind::Exclude };
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
@@ -1036,9 +1034,9 @@ impl LogTab {
|
|||||||
let w = ui.fonts_mut(|f| f.layout_no_wrap(r.pattern.clone(), font, Color32::WHITE).size().x);
|
let w = ui.fonts_mut(|f| f.layout_no_wrap(r.pattern.clone(), font, Color32::WHITE).size().x);
|
||||||
let w = (w + 24.0).clamp(40.0, 300.0);
|
let w = (w + 24.0).clamp(40.0, 300.0);
|
||||||
changed |= ui.add(egui::TextEdit::singleline(&mut r.pattern).desired_width(w)).changed();
|
changed |= ui.add(egui::TextEdit::singleline(&mut r.pattern).desired_width(w)).changed();
|
||||||
changed |= ui.toggle_value(&mut r.regex, ".*").on_hover_text("Regex").changed();
|
changed |= ui.toggle_value(&mut r.regex, tr::REGEX_ICON).on_hover_text(tr::REGEX_TIP).changed();
|
||||||
changed |=
|
changed |=
|
||||||
ui.toggle_value(&mut r.case_sensitive, "Aa").on_hover_text("Case sensitive").changed();
|
ui.toggle_value(&mut r.case_sensitive, tr::CASE_ICON).on_hover_text(tr::CASE_TIP).changed();
|
||||||
if let Err(e) = r.validate() {
|
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, "⚠").on_hover_text(e);
|
||||||
}
|
}
|
||||||
@@ -1052,11 +1050,12 @@ impl LogTab {
|
|||||||
self.rules.remove(i);
|
self.rules.remove(i);
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
let resp =
|
let resp = ui.add(
|
||||||
ui.add(egui::TextEdit::singleline(&mut self.filter.new_text).hint_text("keyword").desired_width(140.0));
|
egui::TextEdit::singleline(&mut self.filter.new_text).hint_text(tr::FILTER_HINT).desired_width(140.0),
|
||||||
|
);
|
||||||
let enter = resp.lost_focus() && ui.input(|i| i.key_pressed(Key::Enter));
|
let enter = resp.lost_focus() && ui.input(|i| i.key_pressed(Key::Enter));
|
||||||
let add_ex = ui.button("− Exclude").on_hover_text("Hide entries containing this").clicked() || enter;
|
let add_ex = ui.button(tr::FILTER_ADD_EXCLUDE).on_hover_text(tr::FILTER_ADD_EXCLUDE_TIP).clicked() || enter;
|
||||||
let add_only = ui.button("+ Only").on_hover_text("Show only entries containing this").clicked();
|
let add_only = ui.button(tr::FILTER_ADD_ONLY).on_hover_text(tr::FILTER_ADD_ONLY_TIP).clicked();
|
||||||
if (add_ex || add_only) && !self.filter.new_text.is_empty() {
|
if (add_ex || add_only) && !self.filter.new_text.is_empty() {
|
||||||
let kind = if add_only { RuleKind::Only } else { RuleKind::Exclude };
|
let kind = if add_only { RuleKind::Only } else { RuleKind::Exclude };
|
||||||
self.rules.push(Rule::filter(kind, &std::mem::take(&mut self.filter.new_text)));
|
self.rules.push(Rule::filter(kind, &std::mem::take(&mut self.filter.new_text)));
|
||||||
@@ -1072,7 +1071,7 @@ impl LogTab {
|
|||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
if !self.index.is_done() {
|
if !self.index.is_done() {
|
||||||
let p = self.index.progress();
|
let p = self.index.progress();
|
||||||
ui.add(egui::ProgressBar::new(p).desired_width(160.0).text(format!("indexing {:.0}%", p * 100.0)));
|
ui.add(egui::ProgressBar::new(p).desired_width(160.0).text(tr::indexing_pct(p)));
|
||||||
}
|
}
|
||||||
ui.label(self.status_text());
|
ui.label(self.status_text());
|
||||||
if let Some(s) = self.search_status() {
|
if let Some(s) = self.search_status() {
|
||||||
@@ -1080,11 +1079,11 @@ impl LogTab {
|
|||||||
ui.label(s);
|
ui.label(s);
|
||||||
}
|
}
|
||||||
ui.separator();
|
ui.separator();
|
||||||
ui.label("UTF-8");
|
ui.label(tr::ENCODING_UTF8);
|
||||||
if self.file_grew {
|
if self.file_grew {
|
||||||
ui.separator();
|
ui.separator();
|
||||||
ui.colored_label(ui.visuals().warn_fg_color, "file grew on disk");
|
ui.colored_label(ui.visuals().warn_fg_color, tr::FILE_GREW);
|
||||||
if ui.small_button("Reload").clicked() {
|
if ui.small_button(tr::RELOAD).clicked() {
|
||||||
self.reload();
|
self.reload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1096,16 +1095,16 @@ impl LogTab {
|
|||||||
if let Some(entry) = self.detail {
|
if let Some(entry) = self.detail {
|
||||||
let mut open = true;
|
let mut open = true;
|
||||||
let text = self.detail_text(entry);
|
let text = self.detail_text(entry);
|
||||||
egui::Window::new(format!("Entry {}", entry + 1))
|
egui::Window::new(tr::entry_title(entry + 1))
|
||||||
.open(&mut open)
|
.open(&mut open)
|
||||||
.default_size([720.0, 420.0])
|
.default_size([720.0, 420.0])
|
||||||
.resizable(true)
|
.resizable(true)
|
||||||
.show(&ctx, |ui| {
|
.show(&ctx, |ui| {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
if ui.button("📋 Copy").clicked() {
|
if ui.button(tr::COPY).clicked() {
|
||||||
ui.ctx().copy_text(text.clone());
|
ui.ctx().copy_text(text.clone());
|
||||||
}
|
}
|
||||||
ui.label(format!("{} bytes", fmt_num(text.len() as u64)));
|
ui.label(tr::bytes(&fmt_num(text.len() as u64)));
|
||||||
});
|
});
|
||||||
egui::ScrollArea::both().auto_shrink(false).show(ui, |ui| {
|
egui::ScrollArea::both().auto_shrink(false).show(ui, |ui| {
|
||||||
let mut t = text.as_str();
|
let mut t = text.as_str();
|
||||||
@@ -1124,15 +1123,15 @@ impl LogTab {
|
|||||||
let mut close = false;
|
let mut close = false;
|
||||||
let mut go = None;
|
let mut go = None;
|
||||||
egui::Modal::new(egui::Id::unique("goto")).show(&ctx, |ui| {
|
egui::Modal::new(egui::Id::unique("goto")).show(&ctx, |ui| {
|
||||||
ui.heading("Go to line");
|
ui.heading(tr::GOTO_TITLE);
|
||||||
let r = ui.add(egui::TextEdit::singleline(text).hint_text("line number"));
|
let r = ui.add(egui::TextEdit::singleline(text).hint_text(tr::GOTO_HINT));
|
||||||
r.request_focus();
|
r.request_focus();
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
if ui.button("Go").clicked() || (r.lost_focus() && ui.input(|i| i.key_pressed(Key::Enter))) {
|
if ui.button(tr::GOTO_GO).clicked() || (r.lost_focus() && ui.input(|i| i.key_pressed(Key::Enter))) {
|
||||||
go = text.trim().replace([',', '_', ' '], "").parse::<u64>().ok();
|
go = text.trim().replace([',', '_', ' '], "").parse::<u64>().ok();
|
||||||
close = true;
|
close = true;
|
||||||
}
|
}
|
||||||
if ui.button("Cancel").clicked() || ui.input(|i| i.key_pressed(Key::Escape)) {
|
if ui.button(tr::CANCEL).clicked() || ui.input(|i| i.key_pressed(Key::Escape)) {
|
||||||
close = true;
|
close = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -1332,13 +1331,13 @@ impl LogTab {
|
|||||||
let total = self.rowmap.total_rows();
|
let total = self.rowmap.total_rows();
|
||||||
if total == 0 {
|
if total == 0 {
|
||||||
let msg = if !index.is_done() {
|
let msg = if !index.is_done() {
|
||||||
"Indexing…"
|
tr::VIEW_INDEXING
|
||||||
} else if self.filter.shared.as_ref().is_some_and(|f| !f.is_done()) {
|
} else if self.filter.shared.as_ref().is_some_and(|f| !f.is_done()) {
|
||||||
"Filtering…"
|
tr::VIEW_FILTERING
|
||||||
} else if idx.is_empty() {
|
} else if idx.is_empty() {
|
||||||
"The file is empty."
|
tr::VIEW_EMPTY
|
||||||
} else {
|
} else {
|
||||||
"No entries match the filter."
|
tr::VIEW_NO_MATCH
|
||||||
};
|
};
|
||||||
ui.painter().text(
|
ui.painter().text(
|
||||||
view.center(),
|
view.center(),
|
||||||
@@ -1488,7 +1487,7 @@ impl LogTab {
|
|||||||
painter.text(
|
painter.text(
|
||||||
tri_rect.center(),
|
tri_rect.center(),
|
||||||
egui::Align2::CENTER_CENTER,
|
egui::Align2::CENTER_CENTER,
|
||||||
if open { "▼" } else { "▶" },
|
tr::arrow(open),
|
||||||
FontId::proportional(10.0),
|
FontId::proportional(10.0),
|
||||||
color,
|
color,
|
||||||
);
|
);
|
||||||
@@ -1521,33 +1520,33 @@ impl LogTab {
|
|||||||
self.sel_start = None;
|
self.sel_start = None;
|
||||||
}
|
}
|
||||||
if multi && let Some((lo, hi)) = sel_range {
|
if multi && let Some((lo, hi)) = sel_range {
|
||||||
if ui.button(format!("Copy {} selected entries", fmt_num((hi - lo + 1) as u64))).clicked() {
|
if ui.button(tr::ctx_copy_selected(&fmt_num((hi - lo + 1) as u64))).clicked() {
|
||||||
ui.ctx().copy_text(self.selection_text(&idx));
|
ui.ctx().copy_text(self.selection_text(&idx));
|
||||||
ui.close();
|
ui.close();
|
||||||
}
|
}
|
||||||
ui.separator();
|
ui.separator();
|
||||||
}
|
}
|
||||||
if ui.button("Copy line").clicked() {
|
if ui.button(tr::COPY_LINE).clicked() {
|
||||||
ui.ctx().copy_text(String::from_utf8_lossy(&self.bytes()[ls..le]).into_owned());
|
ui.ctx().copy_text(String::from_utf8_lossy(&self.bytes()[ls..le]).into_owned());
|
||||||
ui.close();
|
ui.close();
|
||||||
}
|
}
|
||||||
if ui.button("Copy entry").clicked() {
|
if ui.button(tr::CTX_COPY_ENTRY).clicked() {
|
||||||
ui.ctx().copy_text(self.entry_text(&idx, entry, 64 << 20));
|
ui.ctx().copy_text(self.entry_text(&idx, entry, 64 << 20));
|
||||||
ui.close();
|
ui.close();
|
||||||
}
|
}
|
||||||
if ui.button("Show full entry").clicked() {
|
if ui.button(tr::CTX_SHOW_FULL).clicked() {
|
||||||
self.detail = Some(entry);
|
self.detail = Some(entry);
|
||||||
ui.close();
|
ui.close();
|
||||||
}
|
}
|
||||||
if lines > 1 {
|
if lines > 1 {
|
||||||
let label = if self.is_expanded(entry) { "Collapse" } else { "Expand" };
|
let label = if self.is_expanded(entry) { tr::CTX_COLLAPSE } else { tr::CTX_EXPAND };
|
||||||
if ui.button(label).clicked() {
|
if ui.button(label).clicked() {
|
||||||
toggle = Some(entry);
|
toggle = Some(entry);
|
||||||
ui.close();
|
ui.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ui.separator();
|
ui.separator();
|
||||||
if ui.button("Filter out entries like this").clicked() {
|
if ui.button(tr::CTX_FILTER_LIKE).clicked() {
|
||||||
let r = idx.range(entry as usize, self.file_len);
|
let r = idx.range(entry as usize, self.file_len);
|
||||||
let kw = like_this_keyword(&self.bytes()[r.start..r.end.min(r.start + 4096)], &self.pattern);
|
let kw = like_this_keyword(&self.bytes()[r.start..r.end.min(r.start + 4096)], &self.pattern);
|
||||||
if !kw.is_empty() {
|
if !kw.is_empty() {
|
||||||
@@ -1556,7 +1555,7 @@ impl LogTab {
|
|||||||
}
|
}
|
||||||
ui.close();
|
ui.close();
|
||||||
}
|
}
|
||||||
if ui.button("Highlight entries like this").clicked() {
|
if ui.button(tr::CTX_HIGHLIGHT_LIKE).clicked() {
|
||||||
let r = idx.range(entry as usize, self.file_len);
|
let r = idx.range(entry as usize, self.file_len);
|
||||||
let kw = like_this_keyword(&self.bytes()[r.start..r.end.min(r.start + 4096)], &self.pattern);
|
let kw = like_this_keyword(&self.bytes()[r.start..r.end.min(r.start + 4096)], &self.pattern);
|
||||||
if !kw.is_empty() {
|
if !kw.is_empty() {
|
||||||
|
|||||||
+31
-47
@@ -16,6 +16,7 @@ use egui::{Key, Modifiers, RichText};
|
|||||||
use crate::job::Notify;
|
use crate::job::Notify;
|
||||||
use crate::rules::RULES_FILE_EXT;
|
use crate::rules::RULES_FILE_EXT;
|
||||||
use crate::settings::Settings;
|
use crate::settings::Settings;
|
||||||
|
use crate::strings as tr;
|
||||||
use grep_tab::{GrepAction, GrepTab};
|
use grep_tab::{GrepAction, GrepTab};
|
||||||
use log_tab::{LogTab, TabAction};
|
use log_tab::{LogTab, TabAction};
|
||||||
|
|
||||||
@@ -74,7 +75,7 @@ impl App {
|
|||||||
|
|
||||||
fn save_settings(&mut self) {
|
fn save_settings(&mut self) {
|
||||||
if let Err(e) = self.settings.save() {
|
if let Err(e) = self.settings.save() {
|
||||||
self.set_status(format!("Cannot save settings: {e:#}"));
|
self.set_status(tr::cannot_save_settings(e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,7 +92,7 @@ impl App {
|
|||||||
self.set_status(s);
|
self.set_status(s);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.set_status("Open a log file first, then drop the rule file on it");
|
self.set_status(tr::DROP_RULES_NEEDS_LOG);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -143,20 +144,20 @@ impl App {
|
|||||||
|
|
||||||
fn menu(&mut self, ui: &mut egui::Ui) {
|
fn menu(&mut self, ui: &mut egui::Ui) {
|
||||||
egui::MenuBar::new().ui(ui, |ui| {
|
egui::MenuBar::new().ui(ui, |ui| {
|
||||||
ui.menu_button("File", |ui| {
|
ui.menu_button(tr::MENU_FILE, |ui| {
|
||||||
if ui.button("Open… (Ctrl+O)").clicked() {
|
if ui.button(tr::MENU_OPEN).clicked() {
|
||||||
ui.close();
|
ui.close();
|
||||||
self.open_dialog();
|
self.open_dialog();
|
||||||
}
|
}
|
||||||
if ui.button("Find in files… (Ctrl+Shift+F)").clicked() {
|
if ui.button(tr::MENU_FIND_IN_FILES).clicked() {
|
||||||
ui.close();
|
ui.close();
|
||||||
self.tabs.push(Tab::Grep(Box::new(GrepTab::new(None, self.notify.clone()))));
|
self.tabs.push(Tab::Grep(Box::new(GrepTab::new(None, self.notify.clone()))));
|
||||||
self.active = self.tabs.len() - 1;
|
self.active = self.tabs.len() - 1;
|
||||||
}
|
}
|
||||||
ui.menu_button("Recent files", |ui| {
|
ui.menu_button(tr::MENU_RECENT, |ui| {
|
||||||
let recent = self.settings.recent_files.clone();
|
let recent = self.settings.recent_files.clone();
|
||||||
if recent.is_empty() {
|
if recent.is_empty() {
|
||||||
ui.weak("(none)");
|
ui.weak(tr::NONE_PAREN);
|
||||||
}
|
}
|
||||||
for p in recent {
|
for p in recent {
|
||||||
if ui.button(p.display().to_string()).clicked() {
|
if ui.button(p.display().to_string()).clicked() {
|
||||||
@@ -167,13 +168,13 @@ impl App {
|
|||||||
});
|
});
|
||||||
ui.separator();
|
ui.separator();
|
||||||
let has_log = matches!(self.tabs.get(self.active), Some(Tab::Log(_)));
|
let has_log = matches!(self.tabs.get(self.active), Some(Tab::Log(_)));
|
||||||
if ui.add_enabled(has_log, egui::Button::new("Import rules…")).clicked() {
|
if ui.add_enabled(has_log, egui::Button::new(tr::MENU_IMPORT_RULES)).clicked() {
|
||||||
ui.close();
|
ui.close();
|
||||||
if let Some(p) = rfd::FileDialog::new().add_filter("Log rules", &["toml"]).pick_file() {
|
if let Some(p) = rfd::FileDialog::new().add_filter(tr::RULE_FILE_FILTER, &["toml"]).pick_file() {
|
||||||
self.open_path(&p);
|
self.open_path(&p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ui.add_enabled(has_log, egui::Button::new("Export rules…")).clicked() {
|
if ui.add_enabled(has_log, egui::Button::new(tr::MENU_EXPORT_RULES)).clicked() {
|
||||||
ui.close();
|
ui.close();
|
||||||
if let Some(Tab::Log(t)) = self.tabs.get_mut(self.active) {
|
if let Some(Tab::Log(t)) = self.tabs.get_mut(self.active) {
|
||||||
t.rules_dialog = Some(panels::RulesDialog::Export {
|
t.rules_dialog = Some(panels::RulesDialog::Export {
|
||||||
@@ -183,32 +184,32 @@ impl App {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ui.add_enabled(has_log, egui::Button::new("Reload file")).clicked() {
|
if ui.add_enabled(has_log, egui::Button::new(tr::MENU_RELOAD)).clicked() {
|
||||||
ui.close();
|
ui.close();
|
||||||
if let Some(Tab::Log(t)) = self.tabs.get_mut(self.active) {
|
if let Some(Tab::Log(t)) = self.tabs.get_mut(self.active) {
|
||||||
t.reload();
|
t.reload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ui.separator();
|
ui.separator();
|
||||||
if ui.add_enabled(!self.tabs.is_empty(), egui::Button::new("Close tab (Ctrl+W)")).clicked() {
|
if ui.add_enabled(!self.tabs.is_empty(), egui::Button::new(tr::MENU_CLOSE_TAB)).clicked() {
|
||||||
ui.close();
|
ui.close();
|
||||||
self.close_tab(self.active);
|
self.close_tab(self.active);
|
||||||
}
|
}
|
||||||
if ui.button("Quit").clicked() {
|
if ui.button(tr::MENU_QUIT).clicked() {
|
||||||
ui.ctx().send_viewport_cmd(egui::ViewportCommand::Close);
|
ui.ctx().send_viewport_cmd(egui::ViewportCommand::Close);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ui.menu_button("View", |ui| {
|
ui.menu_button(tr::MENU_VIEW, |ui| {
|
||||||
let mut changed = false;
|
let mut changed = false;
|
||||||
changed |= ui.checkbox(&mut self.settings.show_gutter, "Show gutter").changed();
|
changed |= ui.checkbox(&mut self.settings.show_gutter, tr::MENU_SHOW_GUTTER).changed();
|
||||||
changed |= ui
|
changed |= ui
|
||||||
.add_enabled(
|
.add_enabled(
|
||||||
self.settings.show_gutter,
|
self.settings.show_gutter,
|
||||||
egui::Checkbox::new(&mut self.settings.gutter_line_numbers, "Gutter shows line numbers"),
|
egui::Checkbox::new(&mut self.settings.gutter_line_numbers, tr::MENU_GUTTER_LINE_NUMBERS),
|
||||||
)
|
)
|
||||||
.changed();
|
.changed();
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.label("Font size");
|
ui.label(tr::MENU_FONT_SIZE);
|
||||||
if ui.add(egui::Slider::new(&mut self.settings.font_size, 9.0..=24.0).step_by(1.0)).changed() {
|
if ui.add(egui::Slider::new(&mut self.settings.font_size, 9.0..=24.0).step_by(1.0)).changed() {
|
||||||
let size = self.settings.font_size;
|
let size = self.settings.font_size;
|
||||||
ui.ctx().global_style_mut(|s| {
|
ui.ctx().global_style_mut(|s| {
|
||||||
@@ -230,12 +231,12 @@ impl App {
|
|||||||
self.save_settings();
|
self.save_settings();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ui.menu_button("Help", |ui| {
|
ui.menu_button(tr::MENU_HELP, |ui| {
|
||||||
if ui.button("Keyboard shortcuts").clicked() {
|
if ui.button(tr::MENU_SHORTCUTS).clicked() {
|
||||||
self.show_keys = true;
|
self.show_keys = true;
|
||||||
ui.close();
|
ui.close();
|
||||||
}
|
}
|
||||||
if ui.button("About").clicked() {
|
if ui.button(tr::MENU_ABOUT).clicked() {
|
||||||
self.show_about = true;
|
self.show_about = true;
|
||||||
ui.close();
|
ui.close();
|
||||||
}
|
}
|
||||||
@@ -258,7 +259,7 @@ impl App {
|
|||||||
if r.middle_clicked() {
|
if r.middle_clicked() {
|
||||||
close = Some(i);
|
close = Some(i);
|
||||||
}
|
}
|
||||||
if ui.small_button("✖").on_hover_text("Close").clicked() {
|
if ui.small_button(tr::TAB_CLOSE_ICON).on_hover_text(tr::CLOSE).clicked() {
|
||||||
close = Some(i);
|
close = Some(i);
|
||||||
}
|
}
|
||||||
ui.separator();
|
ui.separator();
|
||||||
@@ -301,36 +302,19 @@ impl App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn help_windows(&mut self, ctx: &egui::Context) {
|
fn help_windows(&mut self, ctx: &egui::Context) {
|
||||||
egui::Window::new("Keyboard shortcuts").open(&mut self.show_keys).resizable(false).show(ctx, |ui| {
|
egui::Window::new(tr::SHORTCUTS_TITLE).open(&mut self.show_keys).resizable(false).show(ctx, |ui| {
|
||||||
egui::Grid::new("keys").striped(true).show(ui, |ui| {
|
egui::Grid::new("keys").striped(true).show(ui, |ui| {
|
||||||
for (k, what) in [
|
for &(k, what) in tr::SHORTCUTS {
|
||||||
("Ctrl/Cmd+O", "Open file"),
|
|
||||||
("Ctrl/Cmd+Shift+F", "Find in files"),
|
|
||||||
("Ctrl/Cmd+W", "Close tab"),
|
|
||||||
("Ctrl/Cmd+Tab", "Next tab"),
|
|
||||||
("Ctrl/Cmd+F", "Search"),
|
|
||||||
("Enter / F3", "Next match"),
|
|
||||||
("Shift+Enter / Shift+F3", "Previous match"),
|
|
||||||
("Ctrl/Cmd+G", "Go to line"),
|
|
||||||
("Alt+Z", "Toggle line wrap"),
|
|
||||||
("Up / Down", "Select entry"),
|
|
||||||
("Space / Right", "Expand entry"),
|
|
||||||
("Left", "Collapse entry"),
|
|
||||||
("Shift+Click / Shift+Up / Down", "Select a range of entries"),
|
|
||||||
("Ctrl/Cmd+C", "Copy selected entries"),
|
|
||||||
("PageUp / PageDown", "Scroll a page"),
|
|
||||||
("Home / End", "Start / end of file"),
|
|
||||||
] {
|
|
||||||
ui.label(RichText::new(k).monospace());
|
ui.label(RichText::new(k).monospace());
|
||||||
ui.label(what);
|
ui.label(what);
|
||||||
ui.end_row();
|
ui.end_row();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
egui::Window::new("About").open(&mut self.show_about).resizable(false).show(ctx, |ui| {
|
egui::Window::new(tr::ABOUT_TITLE).open(&mut self.show_about).resizable(false).show(ctx, |ui| {
|
||||||
ui.heading("logreadlite");
|
ui.heading(tr::APP_NAME);
|
||||||
ui.label(format!("Version {}", env!("CARGO_PKG_VERSION")));
|
ui.label(tr::about_version(env!("CARGO_PKG_VERSION")));
|
||||||
ui.label("A fast viewer for large log files.");
|
ui.label(tr::APP_TAGLINE);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -365,10 +349,10 @@ impl eframe::App for App {
|
|||||||
egui::CentralPanel::default().show(ui, |ui| {
|
egui::CentralPanel::default().show(ui, |ui| {
|
||||||
ui.vertical_centered(|ui| {
|
ui.vertical_centered(|ui| {
|
||||||
ui.add_space(ui.available_height() / 3.0);
|
ui.add_space(ui.available_height() / 3.0);
|
||||||
ui.heading("logreadlite");
|
ui.heading(tr::APP_NAME);
|
||||||
ui.label("Open a log file (Ctrl+O), drop files or a folder here, or pick a recent file.");
|
ui.label(tr::START_HINT);
|
||||||
ui.add_space(8.0);
|
ui.add_space(8.0);
|
||||||
if ui.button("Open file…").clicked() {
|
if ui.button(tr::START_OPEN).clicked() {
|
||||||
tab_actions.push(TabAction::Status("__open".into()));
|
tab_actions.push(TabAction::Status("__open".into()));
|
||||||
}
|
}
|
||||||
for p in self.settings.recent_files.iter().take(8) {
|
for p in self.settings.recent_files.iter().take(8) {
|
||||||
|
|||||||
+63
-81
@@ -8,6 +8,7 @@ use egui::{RichText, Ui};
|
|||||||
use crate::pattern::{self, PatternDef, Sample, Scored};
|
use crate::pattern::{self, PatternDef, Sample, Scored};
|
||||||
use crate::rules::{self, ExportWhat, Rule, RuleKind, RulesFile, Scope};
|
use crate::rules::{self, ExportWhat, Rule, RuleKind, RulesFile, Scope};
|
||||||
use crate::settings::{self, Settings};
|
use crate::settings::{self, Settings};
|
||||||
|
use crate::strings as tr;
|
||||||
use crate::ui::log_tab::{LogTab, TabAction};
|
use crate::ui::log_tab::{LogTab, TabAction};
|
||||||
use crate::ui::palette;
|
use crate::ui::palette;
|
||||||
|
|
||||||
@@ -51,12 +52,12 @@ pub fn pattern_panel(tab: &mut LogTab, ui: &mut Ui, settings: &mut Settings) ->
|
|||||||
let mut ed = tab.pattern_editor.take()?;
|
let mut ed = tab.pattern_editor.take()?;
|
||||||
let mut close = false;
|
let mut close = false;
|
||||||
let mut action = None;
|
let mut action = None;
|
||||||
ui.heading("Entry start pattern");
|
ui.heading(tr::PATTERN_TITLE);
|
||||||
ui.label("A line that matches starts a new entry; other lines continue the entry above.");
|
ui.label(tr::PATTERN_HELP);
|
||||||
ui.add_space(4.0);
|
ui.add_space(4.0);
|
||||||
|
|
||||||
let mut choice: Option<PatternDef> = None;
|
let mut choice: Option<PatternDef> = None;
|
||||||
egui::ComboBox::from_label("Preset").selected_text(&ed.name).width(300.0).show_ui(ui, |ui| {
|
egui::ComboBox::from_label(tr::PATTERN_PRESET).selected_text(&ed.name).width(300.0).show_ui(ui, |ui| {
|
||||||
for c in &ed.candidates {
|
for c in &ed.candidates {
|
||||||
let text = format!("{} ({:.2})", c.def.name, c.score);
|
let text = format!("{} ({:.2})", c.def.name, c.score);
|
||||||
if ui.selectable_label(c.def.regex == ed.regex, text).clicked() {
|
if ui.selectable_label(c.def.regex == ed.regex, text).clicked() {
|
||||||
@@ -79,7 +80,7 @@ pub fn pattern_panel(tab: &mut LogTab, ui: &mut Ui, settings: &mut Settings) ->
|
|||||||
egui::TextEdit::singleline(&mut ed.regex).font(egui::TextStyle::Monospace).desired_width(f32::INFINITY),
|
egui::TextEdit::singleline(&mut ed.regex).font(egui::TextStyle::Monospace).desired_width(f32::INFINITY),
|
||||||
);
|
);
|
||||||
if r.changed() {
|
if r.changed() {
|
||||||
ed.name = "Custom".into();
|
ed.name = tr::CUSTOM.into();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -91,23 +92,18 @@ pub fn pattern_panel(tab: &mut LogTab, ui: &mut Ui, settings: &mut Settings) ->
|
|||||||
Ok(re) => {
|
Ok(re) => {
|
||||||
let refs: Vec<&[u8]> = ed.sample.iter().map(|l| l.as_slice()).collect();
|
let refs: Vec<&[u8]> = ed.sample.iter().map(|l| l.as_slice()).collect();
|
||||||
let starts = refs.iter().filter(|l| re.is_match(&l[..l.len().min(pattern::MATCH_PREFIX)])).count();
|
let starts = refs.iter().filter(|l| re.is_match(&l[..l.len().min(pattern::MATCH_PREFIX)])).count();
|
||||||
ui.label(format!(
|
ui.label(tr::pattern_sample_score(starts, refs.len(), pattern::score(re, &refs)));
|
||||||
"{} entries in sample of {} lines · score {:.2}",
|
|
||||||
starts,
|
|
||||||
refs.len(),
|
|
||||||
pattern::score(re, &refs)
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.separator();
|
ui.separator();
|
||||||
ui.checkbox(&mut ed.save_for_path, "Remember for this file");
|
ui.checkbox(&mut ed.save_for_path, tr::PATTERN_REMEMBER_PATH);
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.checkbox(&mut ed.save_glob, "Also for files named");
|
ui.checkbox(&mut ed.save_glob, tr::PATTERN_REMEMBER_GLOB);
|
||||||
ui.add_enabled(ed.save_glob, egui::TextEdit::singleline(&mut ed.glob).desired_width(140.0));
|
ui.add_enabled(ed.save_glob, egui::TextEdit::singleline(&mut ed.glob).desired_width(140.0));
|
||||||
});
|
});
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
if ui.add_enabled(compiled.is_ok(), egui::Button::new("Apply")).clicked() {
|
if ui.add_enabled(compiled.is_ok(), egui::Button::new(tr::PATTERN_APPLY)).clicked() {
|
||||||
let def = PatternDef { name: ed.name.clone(), regex: ed.regex.clone() };
|
let def = PatternDef { name: ed.name.clone(), regex: ed.regex.clone() };
|
||||||
if ed.save_for_path {
|
if ed.save_for_path {
|
||||||
settings.file_mut(&tab.path).pattern = Some(def.clone());
|
settings.file_mut(&tab.path).pattern = Some(def.clone());
|
||||||
@@ -119,20 +115,20 @@ pub fn pattern_panel(tab: &mut LogTab, ui: &mut Ui, settings: &mut Settings) ->
|
|||||||
action = Some(TabAction::SaveSettings);
|
action = Some(TabAction::SaveSettings);
|
||||||
close = true;
|
close = true;
|
||||||
}
|
}
|
||||||
if ui.button("Re-detect").clicked() {
|
if ui.button(tr::PATTERN_REDETECT).clicked() {
|
||||||
let refs: Vec<&[u8]> = ed.sample.iter().map(|l| l.as_slice()).collect();
|
let refs: Vec<&[u8]> = ed.sample.iter().map(|l| l.as_slice()).collect();
|
||||||
let d = pattern::detect_lines(&refs, &settings.extra_patterns);
|
let d = pattern::detect_lines(&refs, &settings.extra_patterns);
|
||||||
ed.name = d.chosen.name;
|
ed.name = d.chosen.name;
|
||||||
ed.regex = d.chosen.regex;
|
ed.regex = d.chosen.regex;
|
||||||
ed.candidates = d.scores;
|
ed.candidates = d.scores;
|
||||||
}
|
}
|
||||||
if ui.button("Close").clicked() {
|
if ui.button(tr::CLOSE).clicked() {
|
||||||
close = true;
|
close = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ui.separator();
|
ui.separator();
|
||||||
ui.label(RichText::new("Preview").strong());
|
ui.label(RichText::new(tr::PATTERN_PREVIEW).strong());
|
||||||
egui::ScrollArea::both().auto_shrink(false).show(ui, |ui| {
|
egui::ScrollArea::both().auto_shrink(false).show(ui, |ui| {
|
||||||
let Ok(re) = &compiled else { return };
|
let Ok(re) = &compiled else { return };
|
||||||
let dim = ui.visuals().weak_text_color();
|
let dim = ui.visuals().weak_text_color();
|
||||||
@@ -167,10 +163,10 @@ fn color_picker(ui: &mut Ui, id: impl egui::AsIdSalt, color: &mut Option<String>
|
|||||||
let swatch = palette::swatch(¤t);
|
let swatch = palette::swatch(¤t);
|
||||||
egui::ComboBox::from_id_salt(id)
|
egui::ComboBox::from_id_salt(id)
|
||||||
.width(80.0)
|
.width(80.0)
|
||||||
.selected_text(RichText::new("■ ".to_string() + ¤t).color(swatch))
|
.selected_text(RichText::new(tr::swatch_label(¤t)).color(swatch))
|
||||||
.show_ui(ui, |ui| {
|
.show_ui(ui, |ui| {
|
||||||
for name in palette::NAMES {
|
for name in palette::NAMES {
|
||||||
let label = RichText::new(format!("■ {name}")).color(palette::swatch(name));
|
let label = RichText::new(tr::swatch_label(name)).color(palette::swatch(name));
|
||||||
if ui.selectable_label(current == *name, label).clicked() {
|
if ui.selectable_label(current == *name, label).clicked() {
|
||||||
*color = Some(name.to_string());
|
*color = Some(name.to_string());
|
||||||
changed = true;
|
changed = true;
|
||||||
@@ -179,7 +175,7 @@ fn color_picker(ui: &mut Ui, id: impl egui::AsIdSalt, color: &mut Option<String>
|
|||||||
ui.separator();
|
ui.separator();
|
||||||
let mut c = palette::parse_hex(¤t).unwrap_or(swatch);
|
let mut c = palette::parse_hex(¤t).unwrap_or(swatch);
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.label("Custom");
|
ui.label(tr::CUSTOM);
|
||||||
if ui.color_edit_button_srgba(&mut c).changed() {
|
if ui.color_edit_button_srgba(&mut c).changed() {
|
||||||
*color = Some(palette::to_hex(c));
|
*color = Some(palette::to_hex(c));
|
||||||
changed = true;
|
changed = true;
|
||||||
@@ -191,8 +187,8 @@ fn color_picker(ui: &mut Ui, id: impl egui::AsIdSalt, color: &mut Option<String>
|
|||||||
|
|
||||||
pub fn rules_panel(tab: &mut LogTab, ui: &mut Ui, settings: &mut Settings) -> Vec<TabAction> {
|
pub fn rules_panel(tab: &mut LogTab, ui: &mut Ui, settings: &mut Settings) -> Vec<TabAction> {
|
||||||
let mut actions = Vec::new();
|
let mut actions = Vec::new();
|
||||||
ui.heading("Highlight rules");
|
ui.heading(tr::RULES_TITLE);
|
||||||
ui.label("First matching row rule tints the entry; all match rules color their text.");
|
ui.label(tr::RULES_HELP);
|
||||||
let mut changed = false;
|
let mut changed = false;
|
||||||
let hl: Vec<usize> = (0..tab.rules.len()).filter(|&i| tab.rules[i].kind == RuleKind::Highlight).collect();
|
let hl: Vec<usize> = (0..tab.rules.len()).filter(|&i| tab.rules[i].kind == RuleKind::Highlight).collect();
|
||||||
let mut swap: Option<(usize, usize)> = None;
|
let mut swap: Option<(usize, usize)> = None;
|
||||||
@@ -203,8 +199,8 @@ pub fn rules_panel(tab: &mut LogTab, ui: &mut Ui, settings: &mut Settings) -> Ve
|
|||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
changed |= ui.checkbox(&mut r.enabled, "").changed();
|
changed |= ui.checkbox(&mut r.enabled, "").changed();
|
||||||
changed |= ui.add(egui::TextEdit::singleline(&mut r.pattern).desired_width(110.0)).changed();
|
changed |= ui.add(egui::TextEdit::singleline(&mut r.pattern).desired_width(110.0)).changed();
|
||||||
changed |= ui.toggle_value(&mut r.regex, ".*").on_hover_text("Regex").changed();
|
changed |= ui.toggle_value(&mut r.regex, tr::REGEX_ICON).on_hover_text(tr::REGEX_TIP).changed();
|
||||||
changed |= ui.toggle_value(&mut r.case_sensitive, "Aa").on_hover_text("Case sensitive").changed();
|
changed |= ui.toggle_value(&mut r.case_sensitive, tr::CASE_ICON).on_hover_text(tr::CASE_TIP).changed();
|
||||||
});
|
});
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.add_space(24.0);
|
ui.add_space(24.0);
|
||||||
@@ -212,10 +208,10 @@ pub fn rules_panel(tab: &mut LogTab, ui: &mut Ui, settings: &mut Settings) -> Ve
|
|||||||
let mut scope = r.scope.unwrap_or_default();
|
let mut scope = r.scope.unwrap_or_default();
|
||||||
egui::ComboBox::from_id_salt(("hlscope", i))
|
egui::ComboBox::from_id_salt(("hlscope", i))
|
||||||
.width(70.0)
|
.width(70.0)
|
||||||
.selected_text(if scope == Scope::Row { "row" } else { "match" })
|
.selected_text(if scope == Scope::Row { tr::SCOPE_ROW } else { tr::SCOPE_MATCH })
|
||||||
.show_ui(ui, |ui| {
|
.show_ui(ui, |ui| {
|
||||||
changed |= ui.selectable_value(&mut scope, Scope::Row, "row").changed();
|
changed |= ui.selectable_value(&mut scope, Scope::Row, tr::SCOPE_ROW).changed();
|
||||||
changed |= ui.selectable_value(&mut scope, Scope::Match, "match").changed();
|
changed |= ui.selectable_value(&mut scope, Scope::Match, tr::SCOPE_MATCH).changed();
|
||||||
});
|
});
|
||||||
r.scope = Some(scope);
|
r.scope = Some(scope);
|
||||||
if k > 0 && ui.small_button("⏶").clicked() {
|
if k > 0 && ui.small_button("⏶").clicked() {
|
||||||
@@ -242,7 +238,7 @@ pub fn rules_panel(tab: &mut LogTab, ui: &mut Ui, settings: &mut Settings) -> Ve
|
|||||||
tab.rules.remove(i);
|
tab.rules.remove(i);
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
if ui.button("+ Add rule").clicked() {
|
if ui.button(tr::RULES_ADD).clicked() {
|
||||||
tab.rules.push(Rule::highlight("keyword", "blue", Scope::Match));
|
tab.rules.push(Rule::highlight("keyword", "blue", Scope::Match));
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
@@ -251,23 +247,23 @@ pub fn rules_panel(tab: &mut LogTab, ui: &mut Ui, settings: &mut Settings) -> Ve
|
|||||||
}
|
}
|
||||||
|
|
||||||
ui.separator();
|
ui.separator();
|
||||||
ui.label(RichText::new("Rule files").strong());
|
ui.label(RichText::new(tr::RULES_FILES).strong());
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
if ui.button("Import…").clicked()
|
if ui.button(tr::RULES_IMPORT_DOTS).clicked()
|
||||||
&& let Some(p) = rfd::FileDialog::new().add_filter("Log rules", &["toml"]).pick_file()
|
&& let Some(p) = rfd::FileDialog::new().add_filter(tr::RULE_FILE_FILTER, &["toml"]).pick_file()
|
||||||
{
|
{
|
||||||
actions.extend(start_import(tab, &p));
|
actions.extend(start_import(tab, &p));
|
||||||
}
|
}
|
||||||
if ui.button("Export…").clicked() {
|
if ui.button(tr::EXPORT_DOTS).clicked() {
|
||||||
tab.rules_dialog =
|
tab.rules_dialog =
|
||||||
Some(RulesDialog::Export { what: ExportWhat::All, selected: None, include_pattern: false });
|
Some(RulesDialog::Export { what: ExportWhat::All, selected: None, include_pattern: false });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
if ui.button("Save as global default").on_hover_text("Rules for newly opened files").clicked() {
|
if ui.button(tr::RULES_SAVE_GLOBAL).on_hover_text(tr::RULES_SAVE_GLOBAL_TIP).clicked() {
|
||||||
settings.rules = tab.rules.clone();
|
settings.rules = tab.rules.clone();
|
||||||
actions.push(TabAction::SaveSettings);
|
actions.push(TabAction::SaveSettings);
|
||||||
actions.push(TabAction::Status("Saved rules as the global default".into()));
|
actions.push(TabAction::Status(tr::RULES_SAVED_GLOBAL.into()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let glob_id = ui.scope_id().with("rules_glob");
|
let glob_id = ui.scope_id().with("rules_glob");
|
||||||
@@ -276,24 +272,24 @@ pub fn rules_panel(tab: &mut LogTab, ui: &mut Ui, settings: &mut Settings) -> Ve
|
|||||||
.unwrap_or_else(|| tab.path.extension().map(|e| format!("*.{}", e.to_string_lossy())).unwrap_or_default());
|
.unwrap_or_else(|| tab.path.extension().map(|e| format!("*.{}", e.to_string_lossy())).unwrap_or_default());
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.add(egui::TextEdit::singleline(&mut glob).desired_width(100.0));
|
ui.add(egui::TextEdit::singleline(&mut glob).desired_width(100.0));
|
||||||
if ui.button("Save for files matching").clicked() && !glob.trim().is_empty() {
|
if ui.button(tr::RULES_SAVE_FOR_GLOB).clicked() && !glob.trim().is_empty() {
|
||||||
let g = glob.trim().to_string();
|
let g = glob.trim().to_string();
|
||||||
settings.glob_rules.retain(|x| x.glob != g);
|
settings.glob_rules.retain(|x| x.glob != g);
|
||||||
settings.glob_rules.push(settings::GlobRules { glob: g.clone(), rules: tab.rules.clone() });
|
settings.glob_rules.push(settings::GlobRules { glob: g.clone(), rules: tab.rules.clone() });
|
||||||
actions.push(TabAction::SaveSettings);
|
actions.push(TabAction::SaveSettings);
|
||||||
actions.push(TabAction::Status(format!("Saved rules for {g}")));
|
actions.push(TabAction::Status(tr::rules_saved_for(&g)));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ui.data_mut(|d| d.insert_temp(glob_id, glob));
|
ui.data_mut(|d| d.insert_temp(glob_id, glob));
|
||||||
|
|
||||||
ui.separator();
|
ui.separator();
|
||||||
ui.label(RichText::new("Named rule sets").strong());
|
ui.label(RichText::new(tr::RULESETS_TITLE).strong());
|
||||||
let sets = settings::list_rulesets();
|
let sets = settings::list_rulesets();
|
||||||
let name_id = ui.scope_id().with("ruleset_name");
|
let name_id = ui.scope_id().with("ruleset_name");
|
||||||
let mut name: String = ui.data(|d| d.get_temp(name_id)).unwrap_or_default();
|
let mut name: String = ui.data(|d| d.get_temp(name_id)).unwrap_or_default();
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
egui::ComboBox::from_id_salt("rulesets")
|
egui::ComboBox::from_id_salt("rulesets")
|
||||||
.selected_text(if sets.is_empty() { "(none saved)" } else { "Switch to…" })
|
.selected_text(if sets.is_empty() { tr::RULESETS_NONE } else { tr::RULESETS_SWITCH })
|
||||||
.show_ui(ui, |ui| {
|
.show_ui(ui, |ui| {
|
||||||
for s in &sets {
|
for s in &sets {
|
||||||
if ui.selectable_label(false, s).clicked() {
|
if ui.selectable_label(false, s).clicked() {
|
||||||
@@ -303,25 +299,21 @@ pub fn rules_panel(tab: &mut LogTab, ui: &mut Ui, settings: &mut Settings) -> Ve
|
|||||||
if let Some(p) = file.pattern {
|
if let Some(p) = file.pattern {
|
||||||
tab.reindex(p);
|
tab.reindex(p);
|
||||||
}
|
}
|
||||||
let mut msg = format!("Loaded rule set {s}");
|
actions.push(TabAction::Status(tr::ruleset_loaded(s, errors.len())));
|
||||||
if !errors.is_empty() {
|
|
||||||
msg.push_str(&format!(" ({} invalid rules skipped)", errors.len()));
|
|
||||||
}
|
}
|
||||||
actions.push(TabAction::Status(msg));
|
Err(e) => actions.push(TabAction::Status(tr::ruleset_load_failed(s, e))),
|
||||||
}
|
|
||||||
Err(e) => actions.push(TabAction::Status(format!("Cannot load {s}: {e:#}"))),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.add(egui::TextEdit::singleline(&mut name).hint_text("name, e.g. Java service").desired_width(140.0));
|
ui.add(egui::TextEdit::singleline(&mut name).hint_text(tr::RULESETS_NAME_HINT).desired_width(140.0));
|
||||||
if ui.button("Save set").clicked() && !name.trim().is_empty() {
|
if ui.button(tr::RULESETS_SAVE).clicked() && !name.trim().is_empty() {
|
||||||
let file = RulesFile::new(tab.rules.clone(), None);
|
let file = RulesFile::new(tab.rules.clone(), None);
|
||||||
match settings::save_ruleset(name.trim(), &file) {
|
match settings::save_ruleset(name.trim(), &file) {
|
||||||
Ok(()) => actions.push(TabAction::Status(format!("Saved rule set {}", name.trim()))),
|
Ok(()) => actions.push(TabAction::Status(tr::ruleset_saved(name.trim()))),
|
||||||
Err(e) => actions.push(TabAction::Status(format!("Cannot save: {e:#}"))),
|
Err(e) => actions.push(TabAction::Status(tr::cannot_save(e))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -352,7 +344,7 @@ pub enum RulesDialog {
|
|||||||
pub fn start_import(tab: &mut LogTab, path: &Path) -> Option<TabAction> {
|
pub fn start_import(tab: &mut LogTab, path: &Path) -> Option<TabAction> {
|
||||||
let text = match std::fs::read_to_string(path) {
|
let text = match std::fs::read_to_string(path) {
|
||||||
Ok(t) => t,
|
Ok(t) => t,
|
||||||
Err(e) => return Some(TabAction::Status(format!("Cannot read {}: {e}", path.display()))),
|
Err(e) => return Some(TabAction::Status(tr::cannot_read(path, e))),
|
||||||
};
|
};
|
||||||
match RulesFile::parse(&text) {
|
match RulesFile::parse(&text) {
|
||||||
Ok((file, errors)) => {
|
Ok((file, errors)) => {
|
||||||
@@ -367,7 +359,7 @@ pub fn start_import(tab: &mut LogTab, path: &Path) -> Option<TabAction> {
|
|||||||
});
|
});
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
Err(e) => Some(TabAction::Status(format!("Not a rule file: {e:#}"))),
|
Err(e) => Some(TabAction::Status(tr::not_a_rule_file(e))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -379,13 +371,10 @@ pub fn rules_dialog(tab: &mut LogTab, ctx: &egui::Context, settings: &mut Settin
|
|||||||
ui.set_width(460.0);
|
ui.set_width(460.0);
|
||||||
match &mut dlg {
|
match &mut dlg {
|
||||||
RulesDialog::Import { path, file, errors, replace, global, apply_pattern } => {
|
RulesDialog::Import { path, file, errors, replace, global, apply_pattern } => {
|
||||||
ui.heading("Import rules");
|
ui.heading(tr::IMPORT_TITLE);
|
||||||
ui.label(format!("{} — {} rules", path.display(), file.rules.len()));
|
ui.label(tr::import_summary(path, file.rules.len()));
|
||||||
if !errors.is_empty() {
|
if !errors.is_empty() {
|
||||||
ui.colored_label(
|
ui.colored_label(ui.visuals().warn_fg_color, tr::import_invalid(errors.len()));
|
||||||
ui.visuals().warn_fg_color,
|
|
||||||
format!("{} invalid rules will be skipped:", errors.len()),
|
|
||||||
);
|
|
||||||
egui::ScrollArea::vertical().max_height(100.0).show(ui, |ui| {
|
egui::ScrollArea::vertical().max_height(100.0).show(ui, |ui| {
|
||||||
for e in errors.iter() {
|
for e in errors.iter() {
|
||||||
ui.label(RichText::new(e).small());
|
ui.label(RichText::new(e).small());
|
||||||
@@ -393,21 +382,18 @@ pub fn rules_dialog(tab: &mut LogTab, ctx: &egui::Context, settings: &mut Settin
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.radio_value(replace, false, "Merge (skip duplicates)");
|
ui.radio_value(replace, false, tr::IMPORT_MERGE);
|
||||||
ui.radio_value(replace, true, "Replace");
|
ui.radio_value(replace, true, tr::IMPORT_REPLACE);
|
||||||
});
|
});
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.radio_value(global, false, "Apply to this tab");
|
ui.radio_value(global, false, tr::IMPORT_TO_TAB);
|
||||||
ui.radio_value(global, true, "Save as global default");
|
ui.radio_value(global, true, tr::IMPORT_TO_GLOBAL);
|
||||||
});
|
});
|
||||||
if let Some(p) = &file.pattern {
|
if let Some(p) = &file.pattern {
|
||||||
ui.add_enabled(
|
ui.add_enabled(!*global, egui::Checkbox::new(apply_pattern, tr::import_use_pattern(&p.name)));
|
||||||
!*global,
|
|
||||||
egui::Checkbox::new(apply_pattern, format!("Use entry-start pattern “{}”", p.name)),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
if ui.button("Import").clicked() {
|
if ui.button(tr::IMPORT).clicked() {
|
||||||
let target = if *global { settings.rules.clone() } else { tab.rules.clone() };
|
let target = if *global { settings.rules.clone() } else { tab.rules.clone() };
|
||||||
let new = if *replace {
|
let new = if *replace {
|
||||||
file.rules.clone()
|
file.rules.clone()
|
||||||
@@ -425,16 +411,16 @@ pub fn rules_dialog(tab: &mut LogTab, ctx: &egui::Context, settings: &mut Settin
|
|||||||
tab.reindex(p);
|
tab.reindex(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
actions.push(TabAction::Status(format!("Imported {} rules", file.rules.len())));
|
actions.push(TabAction::Status(tr::imported(file.rules.len())));
|
||||||
close = true;
|
close = true;
|
||||||
}
|
}
|
||||||
if ui.button("Cancel").clicked() {
|
if ui.button(tr::CANCEL).clicked() {
|
||||||
close = true;
|
close = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
RulesDialog::Export { what, selected, include_pattern } => {
|
RulesDialog::Export { what, selected, include_pattern } => {
|
||||||
ui.heading("Export rules");
|
ui.heading(tr::EXPORT_TITLE);
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
let mut pick = |ui: &mut Ui, w: ExportWhat, label: &str| {
|
let mut pick = |ui: &mut Ui, w: ExportWhat, label: &str| {
|
||||||
if ui.radio(selected.is_none() && *what == w, label).clicked() {
|
if ui.radio(selected.is_none() && *what == w, label).clicked() {
|
||||||
@@ -442,10 +428,10 @@ pub fn rules_dialog(tab: &mut LogTab, ctx: &egui::Context, settings: &mut Settin
|
|||||||
*selected = None;
|
*selected = None;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
pick(ui, ExportWhat::All, "Everything");
|
pick(ui, ExportWhat::All, tr::EXPORT_ALL);
|
||||||
pick(ui, ExportWhat::FiltersOnly, "Filters");
|
pick(ui, ExportWhat::FiltersOnly, tr::EXPORT_FILTERS);
|
||||||
pick(ui, ExportWhat::HighlightsOnly, "Highlights");
|
pick(ui, ExportWhat::HighlightsOnly, tr::EXPORT_HIGHLIGHTS);
|
||||||
if ui.radio(selected.is_some(), "Selected").clicked() && selected.is_none() {
|
if ui.radio(selected.is_some(), tr::EXPORT_SELECTED).clicked() && selected.is_none() {
|
||||||
*selected = Some(vec![true; tab.rules.len()]);
|
*selected = Some(vec![true; tab.rules.len()]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -457,9 +443,9 @@ pub fn rules_dialog(tab: &mut LogTab, ctx: &egui::Context, settings: &mut Settin
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
ui.checkbox(include_pattern, format!("Include entry-start pattern “{}”", tab.pattern.name));
|
ui.checkbox(include_pattern, tr::export_include_pattern(&tab.pattern.name));
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
if ui.button("Save…").clicked() {
|
if ui.button(tr::EXPORT_SAVE).clicked() {
|
||||||
let pattern = include_pattern.then(|| tab.pattern.clone());
|
let pattern = include_pattern.then(|| tab.pattern.clone());
|
||||||
let file = match selected {
|
let file = match selected {
|
||||||
Some(sel) => RulesFile::new(
|
Some(sel) => RulesFile::new(
|
||||||
@@ -470,21 +456,17 @@ pub fn rules_dialog(tab: &mut LogTab, ctx: &egui::Context, settings: &mut Settin
|
|||||||
};
|
};
|
||||||
if let Some(p) = rfd::FileDialog::new()
|
if let Some(p) = rfd::FileDialog::new()
|
||||||
.set_file_name(format!("rules.{}", rules::RULES_FILE_EXT))
|
.set_file_name(format!("rules.{}", rules::RULES_FILE_EXT))
|
||||||
.add_filter("Log rules", &["toml"])
|
.add_filter(tr::RULE_FILE_FILTER, &["toml"])
|
||||||
.save_file()
|
.save_file()
|
||||||
{
|
{
|
||||||
match std::fs::write(&p, file.to_toml()) {
|
match std::fs::write(&p, file.to_toml()) {
|
||||||
Ok(()) => actions.push(TabAction::Status(format!(
|
Ok(()) => actions.push(TabAction::Status(tr::exported(file.rules.len(), &p))),
|
||||||
"Exported {} rules to {}",
|
Err(e) => actions.push(TabAction::Status(tr::cannot_write(&p, e))),
|
||||||
file.rules.len(),
|
|
||||||
p.display()
|
|
||||||
))),
|
|
||||||
Err(e) => actions.push(TabAction::Status(format!("Cannot write {}: {e}", p.display()))),
|
|
||||||
}
|
}
|
||||||
close = true;
|
close = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ui.button("Cancel").clicked() {
|
if ui.button(tr::CANCEL).clicked() {
|
||||||
close = true;
|
close = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
+3
-2
@@ -5,6 +5,7 @@ use egui::{Color32, FontId, Stroke, TextFormat};
|
|||||||
|
|
||||||
use crate::passes::Match;
|
use crate::passes::Match;
|
||||||
use crate::rules::{CompiledHighlight, Scope};
|
use crate::rules::{CompiledHighlight, Scope};
|
||||||
|
use crate::strings as tr;
|
||||||
use crate::ui::palette;
|
use crate::ui::palette;
|
||||||
|
|
||||||
/// Lines longer than this are cut for display; the detail pane shows them in full.
|
/// Lines longer than this are cut for display; the detail pane shows them in full.
|
||||||
@@ -144,12 +145,12 @@ pub fn build_job(spec: &LineSpec<'_>, hl: &[CompiledHighlight], style: &Style) -
|
|||||||
|
|
||||||
let muted = TextFormat { italics: true, ..TextFormat::simple(style.font.clone(), style.dim) };
|
let muted = TextFormat { italics: true, ..TextFormat::simple(style.font.clone(), style.dim) };
|
||||||
if spec.truncated {
|
if spec.truncated {
|
||||||
job.append(" … line cut at 64 KB, right-click → Show full entry", 0.0, muted.clone());
|
job.append(tr::LINE_CUT, 0.0, muted.clone());
|
||||||
}
|
}
|
||||||
if let Some(n) = spec.badge {
|
if let Some(n) = spec.badge {
|
||||||
let mut f = muted;
|
let mut f = muted;
|
||||||
f.background = if style.dark { Color32::from_gray(0x33) } else { Color32::from_gray(0xe6) };
|
f.background = if style.dark { Color32::from_gray(0x33) } else { Color32::from_gray(0xe6) };
|
||||||
job.append(&format!(" +{n} lines "), 12.0, f);
|
job.append(&tr::more_lines_badge(n), 12.0, f);
|
||||||
}
|
}
|
||||||
if job.text.is_empty() {
|
if job.text.is_empty() {
|
||||||
job.append(" ", 0.0, base);
|
job.append(" ", 0.0, base);
|
||||||
|
|||||||
Reference in new issue
Block a user