MCPcopy
hub / github.com/pandas-dev/pandas / get_console_size

Function get_console_size

pandas/io/formats/console.py:10–48  ·  view source on GitHub ↗

Return console size as tuple = (width, height). Returns (None,None) in non-interactive session.

()

Source from the content-addressed store, hash-verified

8
9
10def get_console_size() -> tuple[int | None, int | None]:
11 """
12 Return console size as tuple = (width, height).
13
14 Returns (None,None) in non-interactive session.
15 """
16 from pandas import get_option
17
18 display_width = get_option("display.width")
19 display_height = get_option("display.max_rows")
20
21 # Consider
22 # interactive shell terminal, can detect term size
23 # interactive non-shell terminal (ipnb/ipqtconsole), cannot detect term
24 # size non-interactive script, should disregard term size
25
26 # in addition
27 # width,height have default values, but setting to 'None' signals
28 # should use Auto-Detection, But only in interactive shell-terminal.
29 # Simple. yeah.
30
31 if in_interactive_session():
32 if in_ipython_frontend():
33 # sane defaults for interactive non-shell terminal
34 # match default for width,height in config_init
35 from pandas._config.config import get_default_val
36
37 terminal_width = get_default_val("display.width")
38 terminal_height = get_default_val("display.max_rows")
39 else:
40 # pure terminal
41 terminal_width, terminal_height = get_terminal_size()
42 else:
43 terminal_width, terminal_height = None, None
44
45 # Note if the User sets width/Height to None (auto-detection)
46 # and we're in a script (non-inter), this will return (None,None)
47 # caller needs to deal.
48 return display_width or terminal_width, display_height or terminal_height
49
50
51# ----------------------------------------------------------------------

Callers 1

format_object_summaryFunction · 0.90

Calls 4

get_optionFunction · 0.90
get_default_valFunction · 0.90
in_interactive_sessionFunction · 0.85
in_ipython_frontendFunction · 0.85

Tested by

no test coverage detected