Skip to content

Commit

Permalink
fix: Terminal colours on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
adamrodger committed Feb 20, 2022
1 parent 7617bb8 commit aeffc48
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions gctx/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ fn main() -> Result<()> {

/// Run the application using the command line arguments
pub fn run(opts: Opts) -> Result<()> {
set_virtual_terminal();

if let Some(name) = opts.context {
// shortcut for activate
commands::activate(&name)?;
Expand Down Expand Up @@ -71,3 +73,13 @@ pub fn run(opts: Opts) -> Result<()> {

Ok(())
}

#[cfg(windows)]
fn set_virtual_terminal() {
// ensures colours work properly on Windows, otherwise `cargo run`
// has colours but the actual compiled exe just prints ANSI codes
colored::control::set_virtual_terminal(true).unwrap();
}

#[cfg(not(windows))]
fn set_virtual_terminal() {}

0 comments on commit aeffc48

Please sign in to comment.