Skip to content

Commit 584fc33

Browse files
committed
fix color issue on Windows
1 parent 11c93b4 commit 584fc33

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919

2020
### Fixed
2121

22+
- Fixed garbled color output (raw ANSI codes) in the classic view mode on some Windows terminals. The application now explicitly enables virtual terminal processing on startup, ensuring color codes are interpreted correctly.
23+
2224
- In interactive mode, the selection highlight was changed to use reverse video, guaranteeing visibility and contrast regardless of the underlying file color.
2325

2426
- Fixed a double-input bug in interactive mode on Windows that caused erratic navigation. The TUI now correctly filters for key press events. ([Closes #21](https://github.com/bgreenwell/lstr/issues/21))

src/main.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ mod view;
1313

1414
use app::{Args, Commands};
1515
use clap::Parser;
16+
#[cfg(windows)]
17+
use colored::control;
1618
use lscolors::LsColors;
1719

1820
/// The main function and entry point of the application.
@@ -25,6 +27,12 @@ use lscolors::LsColors;
2527
/// * `Ok(())` on successful execution.
2628
/// * `Err(anyhow::Error)` if any error occurs during execution.
2729
fn main() -> anyhow::Result<()> {
30+
// On Windows, explicitly try to enable ANSI support.
31+
// This may fail on older versions of Windows, but we ignore the error
32+
// and let the `colored` crate handle it gracefully.
33+
#[cfg(windows)]
34+
let _ = control::set_virtual_terminal(true);
35+
2836
// Parse the command-line arguments into our Args struct.
2937
let args = Args::parse();
3038

0 commit comments

Comments
 (0)