22# SPDX-License-Identifier: Apache-2.0
33
44from importlib .metadata import metadata , Distribution
5- from os import get_terminal_size
5+ import os
66from textwrap import wrap
77
88
@@ -54,7 +54,7 @@ def welcome(
5454 description = metadata (module_name ).get ("summary" , "" ) # type: ignore[attr-defined]
5555
5656 logo = [" __/|__" , "/_/_/_/" , " |/ DLR" ]
57- text_width = min (max_width , get_terminal_size ().columns ) - 13
57+ text_width = min (max_width , _get_terminal_size ().columns ) - 13
5858 desc = ["\033 [1;36m" + name + "\033 [0m" , * wrap (description or "" , text_width )]
5959
6060 if len (desc ) < 3 :
@@ -63,9 +63,9 @@ def welcome(
6363 logo .insert (0 , "" )
6464 (desc if len (desc ) < len (logo ) else logo ).extend (["" ] * abs (len (desc ) - len (logo )))
6565
66- welcome_msg = []
66+ welcome_msg : list [ str ] = []
6767 for logo_part , text_part in zip (logo , desc , strict = True ):
68- welcome_msg .append (f"{ logo_part :<12} { text_part } " )
68+ welcome_msg .append (f"{ logo_part :<12} { text_part } " . rstrip () )
6969 if (leading_empty_line is None and print_to_stdout ) or leading_empty_line :
7070 welcome_msg .insert (0 , "" )
7171 if (tailing_empty_line is None and print_to_stdout ) or tailing_empty_line :
@@ -75,3 +75,11 @@ def welcome(
7575 if print_to_stdout :
7676 print (msg )
7777 return msg
78+
79+
80+ def _get_terminal_size () -> os .terminal_size :
81+ try :
82+ # this will throw an error during unit tests since no TTY is available
83+ return os .get_terminal_size ()
84+ except OSError :
85+ return os .terminal_size ((80 , 24 ))
0 commit comments