Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
feat: Make tree-sitter syntax highlighting optional
Maximilian Roos0af712890cf6
diff --git a/Cargo.toml b/Cargo.tomlindex e0837fa6c..1a495a72b 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -15,6 +15,10 @@ consolidate-commits = true[features]# Enable testing for shells that require extra installation steps (nushell, powershell, elvish, xonsh, oil)tier-2-integration-tests = []+# Enable syntax highlighting for bash commands in output (requires tree-sitter)+# This is optional to avoid C compilation issues on some platforms+default = ["syntax-highlighting"]+syntax-highlighting = ["dep:tree-sitter", "dep:tree-sitter-bash", "dep:tree-sitter-highlight"][lib]name = "worktrunk"@@ -50,9 +54,11 @@ toml = { version = "0.9", features = ["preserve_order"] }# Using 0.20.x due to linking issues in 0.25.x with le16toh/be16toh on some platforms# See: https://github.com/tree-sitter/tree-sitter/issues/4186# All three crates must use the same version series to avoid native library conflicts-tree-sitter = "0.20"-tree-sitter-bash = "0.20"-tree-sitter-highlight = "0.20"+# These are optional dependencies controlled by the "syntax-highlighting" feature.+# To build without C compilation requirements, use: cargo install worktrunk --no-default-features+tree-sitter = { version = "0.20", optional = true }+tree-sitter-bash = { version = "0.20", optional = true }+tree-sitter-highlight = { version = "0.20", optional = true }unicode-width = "0.2"[build-dependencies]diff --git a/README.md b/README.mdindex 96c2dd635..2f5c073e6 100644--- a/README.md+++ b/README.md@@ -457,3 +457,15 @@ eval "$(wt init oil)"## StatusWorktrunk is in active development. The core features are stable and ready for use. While the project is pre-1.0, the CLI interface and major features are unlikely to change significantly.++## FAQ++### Installation fails with C compilation errors++If you encounter errors related to tree-sitter or C compilation (like "error: 'for' loop initial declarations are only allowed in C99 mode" or "undefined reference to le16toh"), install without syntax highlighting:++```bash+cargo install worktrunk --no-default-features+```++This disables bash syntax highlighting in command output but keeps all core functionality. The syntax highlighting feature requires C99 compiler support and can fail on older systems or minimal Docker images.diff --git a/src/styling.rs b/src/styling.rsindex 6d7b29de4..3cc30bd43 100644--- a/src/styling.rs+++ b/src/styling.rs@@ -332,6 +332,7 @@ pub fn format_with_gutter(content: &str, left_margin: &str, max_width: Option<us/// ```ignore/// print!("{}", format_bash_with_gutter("npm install --frozen-lockfile"));/// ```+#[cfg(feature = "syntax-highlighting")]pub fn format_bash_with_gutter(content: &str, left_margin: &str) -> String {use tree_sitter_highlight::{HighlightConfiguration, HighlightEvent, Highlighter};@@ -431,6 +432,39 @@ pub fn format_bash_with_gutter(content: &str, left_margin: &str) -> String {output}+/// Format bash commands with gutter (fallback without syntax highlighting)+///+/// This version is used when the `syntax-highlighting` feature is disabled.+/// It provides the same gutter formatting without tree-sitter dependencies.+#[cfg(not(feature = "syntax-highlighting"))]+pub fn format_bash_with_gutter(content: &str, left_margin: &str) -> String {+ let gutter = Style::new().bg_color(Some(Color::Ansi(AnsiColor::Black)));+ let mut output = String::new();++ // Calculate available width for wrapping+ let term_width = get_terminal_width();+ let left_margin_width = left_margin.width();+ let available_width = term_width.saturating_sub(3 + left_margin_width);++ // Wrap lines at word boundaries+ let mut wrapped_lines = Vec::new();+ for line in content.lines() {+ let wrapped = wrap_text_at_width(line, available_width);+ wrapped_lines.extend(wrapped);+ }++ // Process each wrapped line with plain gutter (no syntax highlighting)+ for line in &wrapped_lines {+ output.push_str(&format!("{left_margin}{gutter} {gutter:#} "));+ output.push_str(line);+ // Ensure all styles are reset at end of line to prevent leaking into child process output+ output.push_str(&format!("{}", anstyle::Reset));+ output.push('\n');+ }++ output+}+// ============================================================================// Bash Syntax Highlighting// ============================================================================@@ -445,6 +479,7 @@ pub fn format_bash_with_gutter(content: &str, left_margin: &str) -> String {/// - "comment": hash-prefixed comments/// - "operator": operators like &&, ||, |, $, -, etc./// - "constant": flags (arguments starting with -)+#[cfg(feature = "syntax-highlighting")]fn bash_token_style(kind: &str) -> Option<Style> {match kind {// Commands (npm, git, cargo, echo, cd, etc.) - bold blue