2222 Dict ,
2323 Iterable ,
2424 List ,
25+ Literal ,
2526 Mapping ,
2627 NamedTuple ,
2728 Optional ,
29+ Protocol ,
2830 TextIO ,
2931 Tuple ,
3032 Type ,
3133 Union ,
3234 cast ,
35+ runtime_checkable ,
3336)
3437
3538from pip ._vendor .rich ._null_file import NULL_FILE
3639
37- if sys .version_info >= (3 , 8 ):
38- from typing import Literal , Protocol , runtime_checkable
39- else :
40- from pip ._vendor .typing_extensions import (
41- Literal ,
42- Protocol ,
43- runtime_checkable ,
44- ) # pragma: no cover
45-
4640from . import errors , themes
4741from ._emoji_replace import _emoji_replace
4842from ._export_format import CONSOLE_HTML_FORMAT , CONSOLE_SVG_FORMAT
@@ -739,6 +733,14 @@ def __init__(
739733 if no_color is not None
740734 else self ._environ .get ("NO_COLOR" , "" ) != ""
741735 )
736+ if force_interactive is None :
737+ tty_interactive = self ._environ .get ("TTY_INTERACTIVE" , None )
738+ if tty_interactive is not None :
739+ if tty_interactive == "0" :
740+ force_interactive = False
741+ elif tty_interactive == "1" :
742+ force_interactive = True
743+
742744 self .is_interactive = (
743745 (self .is_terminal and not self .is_dumb_terminal )
744746 if force_interactive is None
@@ -751,7 +753,7 @@ def __init__(
751753 )
752754 self ._record_buffer : List [Segment ] = []
753755 self ._render_hooks : List [RenderHook ] = []
754- self ._live : Optional [ " Live" ] = None
756+ self ._live_stack : List [ Live ] = []
755757 self ._is_alt_screen = False
756758
757759 def __repr__ (self ) -> str :
@@ -823,24 +825,26 @@ def _exit_buffer(self) -> None:
823825 self ._buffer_index -= 1
824826 self ._check_buffer ()
825827
826- def set_live (self , live : "Live" ) -> None :
827- """Set Live instance. Used by Live context manager.
828+ def set_live (self , live : "Live" ) -> bool :
829+ """Set Live instance. Used by Live context manager (no need to call directly) .
828830
829831 Args:
830832 live (Live): Live instance using this Console.
831833
834+ Returns:
835+ Boolean that indicates if the live is the topmost of the stack.
836+
832837 Raises:
833838 errors.LiveError: If this Console has a Live context currently active.
834839 """
835840 with self ._lock :
836- if self ._live is not None :
837- raise errors .LiveError ("Only one live display may be active at once" )
838- self ._live = live
841+ self ._live_stack .append (live )
842+ return len (self ._live_stack ) == 1
839843
840844 def clear_live (self ) -> None :
841- """Clear the Live instance."""
845+ """Clear the Live instance. Used by the Live context manager (no need to call directly). """
842846 with self ._lock :
843- self ._live = None
847+ self ._live_stack . pop ()
844848
845849 def push_render_hook (self , hook : RenderHook ) -> None :
846850 """Add a new render hook to the stack.
@@ -992,12 +996,13 @@ def is_dumb_terminal(self) -> bool:
992996 @property
993997 def options (self ) -> ConsoleOptions :
994998 """Get default console options."""
999+ size = self .size
9951000 return ConsoleOptions (
996- max_height = self . size .height ,
997- size = self . size ,
1001+ max_height = size .height ,
1002+ size = size ,
9981003 legacy_windows = self .legacy_windows ,
9991004 min_width = 1 ,
1000- max_width = self .width ,
1005+ max_width = size .width ,
10011006 encoding = self .encoding ,
10021007 is_terminal = self .is_terminal ,
10031008 )
0 commit comments