Skip to content

feat: add color coding for failed and broken commands#472

Open
cbandera wants to merge 4 commits intocantino:masterfrom
cbandera:feature/351-color-by-exit-code
Open

feat: add color coding for failed and broken commands#472
cbandera wants to merge 4 commits intocantino:masterfrom
cbandera:feature/351-color-by-exit-code

Conversation

@cbandera
Copy link

Adresses #351:

  • Add support for coloring recently failed commands (non-zero exit code, default: yellow)
  • Add support for coloring broken commands (exit_factor == 0.0, default: red)
  • Update configuration to support new color settings in both light and dark modes and from config file.
  • Reduces code duplication and complexity by refactor color handling to use a unified ThemeColors struct
image

The changes maintain backward compatibility while adding visual distinction between successful, recently failed, and always-failing commands.

@cbandera cbandera force-pushed the feature/351-color-by-exit-code branch from 4561c19 to 198f1f6 Compare December 29, 2025 20:54
@cbandera
Copy link
Author

The diff has gotten somewhat polluted due to my refactoring and attempt to reduce code duplication.
The actual color fix is pretty small, I have hence split my commit in two again. Let me know if you prefer to only merge the first one.

- Add support for different colors for recently failed commands (non-zero exit code)
- Add support for different colors for broken commands (exit_factor == 0.0)
- Update configuration to support new color settings in both light and dark modes

The changes maintain backward compatibility while adding visual distinction
between successful, recently failed, and always-failing commands.
@cbandera cbandera force-pushed the feature/351-color-by-exit-code branch from 198f1f6 to ba8cccf Compare December 29, 2025 21:00
@cantino
Copy link
Owner

cantino commented Jan 14, 2026

Cool, thanks @cbandera! Do you mind running fmt and clippy on this?

@cantino
Copy link
Owner

cantino commented Jan 18, 2026

I really like this improvement, thank you! Can you please document it in the README. And, do you think we should add a flag to disable it? Maybe unnecessary, but someone will probably ask...

@cbandera
Copy link
Author

@cantino I updated the docs and added a flag for deactivation (do you agree with naming?). However during testing I have identified a few edge cases:

  • The detection of "recently failed" commands is currently based on the exit_code entry of the Command object. That object however depends on the sort mechanism used. It might be the most recent one, or the best ranked one. So it doesn't always behave as "the most recent one"
  • Additionally, I realized that when running a command twice (like cargo build) and one run fails and the second succeeds, then the second one isn't added to the database because of the History::should_add helper that avoids adding subsequent duplicates.

So given that I wonder whether I should:

  • Switch to recent_failure_factor instead of exit_code, which would color commands as yellow if they failed within the last 2 minutes and
  • Whether we should extend History::should_add to allow adding in case of differing exit codes. However I can't judge on side effects of this because I don't know the context of the comment that says: "Ignore the previous command (independent of Session ID) so that opening a new terminal window won't replay the last command in the history."

Let me know what you think and I can make the necessary changes

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