fonts: limit missing glyph notification to once per hour

refs: https://github.com/wez/wezterm/issues/2188
This commit is contained in:
Wez Furlong committed 2022-07-14 07:26:04 -07:00
1 parent 49ab340a92
commit 49e3fd4c9e
1 file changed
+14 -2
+14 -2
View File
@@ -15,7 +15,7 @@ use std::ops::Range;
use std::rc::{Rc, Weak};
use std::sync::mpsc::{channel, Sender};
use std::sync::{Arc, Mutex};
use std::time::Duration;
use std::time::{Duration, Instant};
use termwiz::cell::Presentation;
use thiserror::Error;
use wezterm_bidi::Direction;
@@ -48,6 +48,10 @@ pub fn alloc_font_id() -> LoadedFontId {
FONT_ID.fetch_add(1, ::std::sync::atomic::Ordering::Relaxed)
}
lazy_static::lazy_static! {
static ref LAST_WARNING: Mutex<Option<Instant>> = Mutex::new(None);
}
pub struct LoadedFont {
rasterizers: RefCell<HashMap<FallbackIdx, Box<dyn FontRasterizer>>>,
handles: RefCell<Vec<ParsedFont>>,
@@ -392,7 +396,15 @@ impl FallbackResolveInfo {
.map(|c| std::char::from_u32(c).unwrap_or(' '))
.collect::<String>();
if self.config.warn_about_missing_glyphs {
let show_warning = self.config.warn_about_missing_glyphs
&& LAST_WARNING
.lock()
.unwrap()
.map(|instant| instant.elapsed() > Duration::from_secs(60 * 60))
.unwrap_or(true);
if show_warning {
LAST_WARNING.lock().unwrap().replace(Instant::now());
let url = "https://wezfurlong.org/wezterm/config/fonts.html";
log::warn!(
"No fonts contain glyphs for these codepoints: {}.\n\