@@ -1675,16 +1675,37 @@ def detect_console_encoding():
1675
1675
1676
1676
1677
1677
def get_console_size ():
1678
- """Return console size as tuple = (width, height)."""
1678
+ """Return console size as tuple = (width, height).
1679
+
1680
+ May return (None,None) in some cases.
1681
+ """
1679
1682
display_width = get_option ('display.width' )
1680
1683
display_height = get_option ('display.height' )
1681
1684
1682
- if com .in_interactive_session () and not com .in_ipnb_frontend ():
1683
- # pure terminal
1684
- terminal_width , terminal_height = get_terminal_size ()
1685
+ # Consider
1686
+ # interactive shell terminal, can detect term size
1687
+ # interactive non-shell terminal (ipnb/ipqtconsole), cannot detect term size
1688
+ # non-interactive script, should disregard term size
1689
+
1690
+ # in addition
1691
+ # width,height have default values, but setting to 'None' signals
1692
+ # should use Auto-Detection, But only in interactive shell-terminal.
1693
+ # Simple. yeah.
1694
+
1695
+ if com .in_interactive_session ():
1696
+ if com .in_ipnb_frontend ():
1697
+ # sane defaults for interactive non-shell terminal
1698
+ # match default for width,height in config_init
1699
+ terminal_width , terminal_height = 100 , 60
1700
+ else :
1701
+ # pure terminal
1702
+ terminal_width , terminal_height = get_terminal_size ()
1685
1703
else :
1686
- terminal_width , terminal_height = 100 , 60
1704
+ terminal_width , terminal_height = None , None
1687
1705
1706
+ # Note if the User sets width/Height to None (auto-detection)
1707
+ # and we're in a script (non-inter), this will return (None,None)
1708
+ # caller needs to deal.
1688
1709
return (display_width or terminal_width , display_height or terminal_height )
1689
1710
1690
1711
0 commit comments