22
22
Dict ,
23
23
Iterable ,
24
24
List ,
25
+ Literal ,
25
26
Mapping ,
26
27
NamedTuple ,
27
28
Optional ,
29
+ Protocol ,
28
30
TextIO ,
29
31
Tuple ,
30
32
Type ,
31
33
Union ,
32
34
cast ,
35
+ runtime_checkable ,
33
36
)
34
37
35
38
from pip ._vendor .rich ._null_file import NULL_FILE
36
39
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
-
46
40
from . import errors , themes
47
41
from ._emoji_replace import _emoji_replace
48
42
from ._export_format import CONSOLE_HTML_FORMAT , CONSOLE_SVG_FORMAT
@@ -739,6 +733,14 @@ def __init__(
739
733
if no_color is not None
740
734
else self ._environ .get ("NO_COLOR" , "" ) != ""
741
735
)
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
+
742
744
self .is_interactive = (
743
745
(self .is_terminal and not self .is_dumb_terminal )
744
746
if force_interactive is None
@@ -751,7 +753,7 @@ def __init__(
751
753
)
752
754
self ._record_buffer : List [Segment ] = []
753
755
self ._render_hooks : List [RenderHook ] = []
754
- self ._live : Optional [ " Live" ] = None
756
+ self ._live_stack : List [ Live ] = []
755
757
self ._is_alt_screen = False
756
758
757
759
def __repr__ (self ) -> str :
@@ -823,24 +825,26 @@ def _exit_buffer(self) -> None:
823
825
self ._buffer_index -= 1
824
826
self ._check_buffer ()
825
827
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) .
828
830
829
831
Args:
830
832
live (Live): Live instance using this Console.
831
833
834
+ Returns:
835
+ Boolean that indicates if the live is the topmost of the stack.
836
+
832
837
Raises:
833
838
errors.LiveError: If this Console has a Live context currently active.
834
839
"""
835
840
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
839
843
840
844
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). """
842
846
with self ._lock :
843
- self ._live = None
847
+ self ._live_stack . pop ()
844
848
845
849
def push_render_hook (self , hook : RenderHook ) -> None :
846
850
"""Add a new render hook to the stack.
@@ -992,12 +996,13 @@ def is_dumb_terminal(self) -> bool:
992
996
@property
993
997
def options (self ) -> ConsoleOptions :
994
998
"""Get default console options."""
999
+ size = self .size
995
1000
return ConsoleOptions (
996
- max_height = self . size .height ,
997
- size = self . size ,
1001
+ max_height = size .height ,
1002
+ size = size ,
998
1003
legacy_windows = self .legacy_windows ,
999
1004
min_width = 1 ,
1000
- max_width = self .width ,
1005
+ max_width = size .width ,
1001
1006
encoding = self .encoding ,
1002
1007
is_terminal = self .is_terminal ,
1003
1008
)
0 commit comments