From f1ea49b75d81955faebd2e922975bcc58e8634ef Mon Sep 17 00:00:00 2001 From: Mark Andrus Roberts Date: Mon, 20 Feb 2017 12:22:26 -0800 Subject: Lazily reset `start_time` in VisualBell's `completed` method Fixes #416. Here's what I think is happening: at short `duration`s, the VisualBell's [`completed` check](https://github.com/jwilm/alacritty/blob/3ce6e1e4b2924b0d432cbb3e62b4bbef88dd38ff/src/term/mod.rs#L377) is returning `true` before we've actually had a chance to draw the "normal" background color. I thought about driving this condition off of whether or not `intensity` returns 0.0, but we may still miss a draw, I think. Perhaps the best way to tackle this is to let `completed` lazily reset the VisualBell's `start_time` (something @jwilm asked about when this feature originally landed), and to only return `true` when the VisualBell's `start_time` is `None`. This should effectively delay the final draw until after the VisualBell completes. --- src/term/mod.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/term/mod.rs b/src/term/mod.rs index 2849c6cf..786265ef 100644 --- a/src/term/mod.rs +++ b/src/term/mod.rs @@ -372,9 +372,14 @@ impl VisualBell { } /// Check whether or not the visual bell has completed "ringing". - pub fn completed(&self) -> bool { + pub fn completed(&mut self) -> bool { match self.start_time { - Some(earlier) => Instant::now().duration_since(earlier) > self.duration, + Some(earlier) => { + if Instant::now().duration_since(earlier) >= self.duration { + self.start_time = None; + } + false + }, None => true } } -- cgit v1.2.3