From 84323d97294da6e03d1f21acd36328da33d875eb Mon Sep 17 00:00:00 2001 From: Roey Darwish Dror Date: Mon, 21 Jan 2019 20:12:56 +0200 Subject: [PATCH] Don't run Powershell in a dumb terminal (fix #110) --- src/steps/os/windows.rs | 8 ++++++-- src/terminal.rs | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/steps/os/windows.rs b/src/steps/os/windows.rs index 2a6763fe..fa5be586 100644 --- a/src/steps/os/windows.rs +++ b/src/steps/os/windows.rs @@ -1,6 +1,6 @@ use crate::error::Error; use crate::executor::{CommandExt, RunType}; -use crate::terminal::print_separator; +use crate::terminal::{is_dumb, print_separator}; use crate::utils::{self, which}; use log::error; use std::path::PathBuf; @@ -46,9 +46,13 @@ pub struct Powershell { } impl Powershell { + /// Returns a powershell instance. + /// + /// If the powershell binary is not found, or the current terminal is dumb + /// then the instance of this struct will skip all the powershell steps. pub fn new() -> Self { Powershell { - path: which("powershell"), + path: which("powershell").filter(|_| !is_dumb()), } } diff --git a/src/terminal.rs b/src/terminal.rs index 610b63a2..1b99988a 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -126,3 +126,8 @@ pub fn print_warning>(message: P) { pub fn print_result>(key: P, succeeded: bool) { TERMINAL.lock().unwrap().print_result(key, succeeded) } + +/// Tells whether the terminal is dumb. +pub fn is_dumb() -> bool { + TERMINAL.lock().unwrap().width.is_none() +}