terminal.py (12882:dd87d7f2f3e5) terminal.py (13788:becab13ee708)
1# Copyright (c) 2011 Advanced Micro Devices, Inc.
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met: redistributions of source code must retain the above copyright
7# notice, this list of conditions and the following disclaimer;
8# redistributions in binary form must reproduce the above copyright

--- 92 unchanged lines hidden (view full) ---

101 elif use_colors is None:
102 # option unspecified; default behavior is to use colors iff isatty
103 return tty_termcap
104 else:
105 return no_termcap
106
107def terminal_size():
108 '''Return the (width, heigth) of the terminal screen.'''
1# Copyright (c) 2011 Advanced Micro Devices, Inc.
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met: redistributions of source code must retain the above copyright
7# notice, this list of conditions and the following disclaimer;
8# redistributions in binary form must reproduce the above copyright

--- 92 unchanged lines hidden (view full) ---

101 elif use_colors is None:
102 # option unspecified; default behavior is to use colors iff isatty
103 return tty_termcap
104 else:
105 return no_termcap
106
107def terminal_size():
108 '''Return the (width, heigth) of the terminal screen.'''
109 h, w, hp, wp = struct.unpack('HHHH',
110 fcntl.ioctl(0, termios.TIOCGWINSZ,
111 struct.pack('HHHH', 0, 0, 0, 0)))
112 return w, h
109 try:
110 h, w, hp, wp = struct.unpack('HHHH',
111 fcntl.ioctl(0, termios.TIOCGWINSZ,
112 struct.pack('HHHH', 0, 0, 0, 0)))
113 return w, h
114 except IOError:
115 # It's possible that in sandboxed environments the above ioctl is not
116 # allowed (e.g., some jenkins setups)
117 return 80, 24
113
118
119
114def separator(char=default_separator, color=None):
115 '''
116 Return a separator of the given character that is the length of the full
117 width of the terminal screen.
118 '''
119 (w, h) = terminal_size()
120 if color:
121 return color + char*w + termcap.Normal

--- 44 unchanged lines hidden ---
120def separator(char=default_separator, color=None):
121 '''
122 Return a separator of the given character that is the length of the full
123 width of the terminal screen.
124 '''
125 (w, h) = terminal_size()
126 if color:
127 return color + char*w + termcap.Normal

--- 44 unchanged lines hidden ---