From 3e499d675a2ef9b526c9eaf34b82cae62b863977 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Wed, 2 Aug 2023 08:56:26 -0500 Subject: [PATCH] CLI: Re-use highlight cancellation flag for HTML highlights The `html` highlight function created its own cancellation flag which conflicts with the Ctrl-c handler set up in the CLI's `main` block for `tree-sitter highlight`. We can re-use the cancellation flag from that block to avoid a panic that happens when using `tree-sitter highlight -H ` thread 'main' panicked at 'Error setting Ctrl-C handler: MultipleHandlers', cli/src/util.rs:31:6 This change also aligns the parameters that `highlight::ansi` and `highlight::html` take. --- cli/src/highlight.rs | 5 ++--- cli/src/main.rs | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/src/highlight.rs b/cli/src/highlight.rs index e16a705c..35f7583e 100644 --- a/cli/src/highlight.rs +++ b/cli/src/highlight.rs @@ -1,4 +1,3 @@ -use super::util; use ansi_term::Color; use anyhow::Result; use lazy_static::lazy_static; @@ -385,16 +384,16 @@ pub fn html( config: &HighlightConfiguration, quiet: bool, print_time: bool, + cancellation_flag: Option<&AtomicUsize>, ) -> Result<()> { use std::io::Write; let stdout = io::stdout(); let mut stdout = stdout.lock(); let time = Instant::now(); - let cancellation_flag = util::cancel_on_signal(); let mut highlighter = Highlighter::new(); - let events = highlighter.highlight(config, source, Some(&cancellation_flag), |string| { + let events = highlighter.highlight(config, source, cancellation_flag, |string| { loader.highlight_config_for_injection_string(string) })?; diff --git a/cli/src/main.rs b/cli/src/main.rs index 1912762d..fe250e68 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -609,6 +609,7 @@ fn run() -> Result<()> { highlight_config, quiet, time, + Some(&cancellation_flag), )?; } else { highlight::ansi(