Skip to content

fix(task): use terminal width instead of hardcoded 60-char limit for task display#6218

Merged
jdx merged 1 commit intomainfrom
fix/task-display-truncation
Sep 6, 2025
Merged

fix(task): use terminal width instead of hardcoded 60-char limit for task display#6218
jdx merged 1 commit intomainfrom
fix/task-display-truncation

Conversation

@jdx
Copy link
Copy Markdown
Owner

@jdx jdx commented Sep 6, 2025

Summary

  • Replace hardcoded 60-character truncation limit in Task Display implementation with terminal-width-based calculation
  • Use console::measure_text_width() to properly handle ANSI color codes
  • Fix premature truncation of task commands in CI environments and wide terminals
  • Ensure minimum 20 characters shown even with very long task names/prefixes

Changes Made

  • Import console::measure_text_width in src/task/mod.rs
  • Replace truncate_str(cmd, 60, "…") with dynamic width calculation in Task Display
  • Calculate max width as TERM_WIDTH - prefix_len - 4 with 20-char minimum
  • Fix both Display implementation AND runtime truncation logic in src/cli/run.rs
  • Add comprehensive e2e test to verify truncation behavior works correctly
  • Maintain consistent truncation behavior across all task output scenarios

Before vs After

Before: Tasks were always truncated at 60 characters regardless of terminal width

[very-long-task-name-that-exceeds-sixty-characters-to-test] $ echo "…

After: Tasks respect terminal width and show minimum 20 chars even with long prefixes

[very-long-task-name-that-exceeds-sixty-characters-to-test] $ echo "this is a v…

Test plan

  • Unit tests pass
  • Lint checks pass
  • E2e test test_task_display_truncation passes
  • Task display now respects terminal width instead of 60-char hard limit
  • ANSI color codes are properly handled in width calculations
  • Very long task names still show meaningful command text

Fixes task output truncation issue where commands were being cut off at 60 characters regardless of terminal size or color formatting. The fix ensures both display and runtime truncation use consistent, intelligent width calculations.

🤖 Generated with Claude Code

…task display

Replace hardcoded 60-character truncation limit in Task Display implementation
with terminal-width-based calculation. This fixes premature truncation of task
commands in CI environments and wide terminals.

- Use console::measure_text_width() to properly handle ANSI color codes
- Calculate max width based on TERM_WIDTH minus prefix length and buffer
- Maintains consistent truncation behavior with runtime task execution
- Fixes issue where long commands were truncated at 60 chars regardless of terminal size

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings September 6, 2025 23:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Fixes task display truncation by replacing a hardcoded 60-character limit with dynamic terminal width calculation. This prevents premature truncation of task commands in CI environments and wide terminals.

  • Import measure_text_width from console module to handle ANSI color codes properly
  • Replace hardcoded 60-character limit with dynamic calculation based on terminal width
  • Calculate max width by subtracting prefix length and buffer space from terminal width

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread src/task/mod.rs
write!(f, "{} {}", self.prefix(), truncate_str(cmd, 60, "…"))
let prefix = self.prefix();
let prefix_len = measure_text_width(&prefix);
let max_width = (*env::TERM_WIDTH).saturating_sub(prefix_len + 4); // 4 chars buffer for spacing and ellipsis
Copy link

Copilot AI Sep 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The magic number 4 should be defined as a named constant to improve code readability and maintainability. Consider defining const DISPLAY_BUFFER: usize = 4; at the module level.

Copilot uses AI. Check for mistakes.
@jdx jdx enabled auto-merge (squash) September 6, 2025 23:05
@jdx jdx merged commit 8c3ef74 into main Sep 6, 2025
19 checks passed
@jdx jdx deleted the fix/task-display-truncation branch September 6, 2025 23:10
@github-actions
Copy link
Copy Markdown

github-actions bot commented Sep 6, 2025

Hyperfine Performance

mise x -- echo

Command Mean [ms] Min [ms] Max [ms] Relative
mise-2025.9.5 x -- echo 18.4 ± 0.4 17.9 23.4 1.00 ± 0.02
mise x -- echo 18.4 ± 0.2 17.9 19.8 1.00

mise env

Command Mean [ms] Min [ms] Max [ms] Relative
mise-2025.9.5 env 17.8 ± 0.3 17.3 21.3 1.00 ± 0.03
mise env 17.7 ± 0.4 17.3 23.3 1.00

mise hook-env

Command Mean [ms] Min [ms] Max [ms] Relative
mise-2025.9.5 hook-env 17.4 ± 0.2 16.9 18.6 1.01 ± 0.02
mise hook-env 17.3 ± 0.2 17.0 18.5 1.00

mise ls

Command Mean [ms] Min [ms] Max [ms] Relative
mise-2025.9.5 ls 15.9 ± 0.3 15.4 19.0 1.00 ± 0.02
mise ls 15.8 ± 0.2 15.4 17.3 1.00

xtasks/test/perf

Command mise-2025.9.5 mise Variance
install (cached) 163ms ✅ 101ms +61%
ls (cached) 61ms 61ms +0%
bin-paths (cached) 65ms 65ms +0%
task-ls (cached) 467ms 469ms +0%

✅ Performance improvement: install cached is 61%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants