@@ -160,10 +160,6 @@ is welcome.
160160* Also set the window title from the progress model, perhaps by a different
161161 render function?
162162
163- * Better detection of when to draw progress or not. Possibly look at
164- `TERM=dumb`; possibly hook in to a standard Rust mechanism e.g.
165- <https://github.com/rust-cli/team/issues/15#issuecomment-891350115>.
166-
167163# Changelog
168164
169165## 0.0.3
@@ -198,6 +194,9 @@ Not released yet.
198194
199195* New: [View::inspect_model] gives its callback a `&mut` to the model.
200196
197+ * New: Progress bars constructed by [View::new] and [View::new_stderr] are disabled when
198+ `$TERM=dumb`.
199+
201200## 0.0.2
202201
203202Released 2022-03-07
@@ -238,6 +237,7 @@ Released 2022-03-07
238237
239238#![ warn( missing_docs) ]
240239
240+ use std:: env;
241241use std:: fmt:: Display ;
242242use std:: io:: { self , Write } ;
243243use std:: time:: { Duration , Instant } ;
@@ -370,17 +370,21 @@ impl<M: Model> View<M> {
370370 /// ownership of the model, after which the application can update
371371 /// it through [View::update].
372372 ///
373+ /// `options` can typically be `Options::default`.
374+ ///
373375 /// On Windows, this enables use of ANSI sequences for styling stdout.
374376 ///
375377 /// Even if progress bars are enabled in the [Options], they will be
376- /// disabled if stdout is not a tty, or if it does not support ANSI
377- /// sequences (on Windows).
378+ /// disabled under some conditions:
379+ /// * If stdout is not a tty,
380+ /// * On Windows, if ANSI sequences cannot be enabled.
381+ /// * If the `$TERM` environment variable is `DUMB`.
378382 ///
379383 /// This constructor arranges that output from the progress view will be
380384 /// captured by the Rust test framework and not leak to stdout, but
381385 /// detection of whether to show progress bars may not work correctly.
382386 pub fn new ( model : M , mut options : Options ) -> View < M > {
383- if atty:: isnt ( atty:: Stream :: Stdout ) || !ansi:: enable_windows_ansi ( ) {
387+ if atty:: isnt ( atty:: Stream :: Stdout ) || !ansi:: enable_windows_ansi ( ) || is_dumb_term ( ) {
384388 options. progress_enabled = false ;
385389 }
386390 View :: from_inner ( InnerView :: new (
@@ -396,7 +400,7 @@ impl<M: Model> View<M> {
396400 /// This is the same as [View::new] except that the progress bar, and
397401 /// any messages emitted through it, are sent to stderr.
398402 pub fn new_stderr ( model : M , mut options : Options ) -> View < M > {
399- if atty:: isnt ( atty:: Stream :: Stderr ) || !ansi:: enable_windows_ansi ( ) {
403+ if atty:: isnt ( atty:: Stream :: Stderr ) || !ansi:: enable_windows_ansi ( ) || is_dumb_term ( ) {
400404 options. progress_enabled = false ;
401405 }
402406 View :: from_inner ( InnerView :: new (
@@ -601,6 +605,10 @@ impl<M: Model> Drop for View<M> {
601605 }
602606}
603607
608+ fn is_dumb_term ( ) -> bool {
609+ env:: var ( "TERM" ) . map_or ( false , |s| s. eq_ignore_ascii_case ( "dumb" ) )
610+ }
611+
604612/// The real contents of a View, inside a mutex.
605613struct InnerView < M : Model > {
606614 /// Current application model.
0 commit comments