terminal.py (7816:b5003ac75977) terminal.py (8947:217fbc57df05)
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

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

88termcap = ColorStrings(cap_string)
89no_termcap = ColorStrings(null_cap_string)
90
91if sys.stdout.isatty():
92 tty_termcap = termcap
93else:
94 tty_termcap = no_termcap
95
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

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

88termcap = ColorStrings(cap_string)
89no_termcap = ColorStrings(null_cap_string)
90
91if sys.stdout.isatty():
92 tty_termcap = termcap
93else:
94 tty_termcap = no_termcap
95
96def get_termcap(use_colors = None):
97 if use_colors:
98 return termcap
99 elif use_colors is None:
100 # option unspecified; default behavior is to use colors iff isatty
101 return tty_termcap
102 else:
103 return no_termcap
104
96def test_termcap(obj):
97 for c_name in color_names:
98 c_str = getattr(obj, c_name)
99 print c_str + c_name + obj.Normal
100 for attr_name in capability_names:
101 if attr_name == 'Normal':
102 continue
103 attr_str = getattr(obj, attr_name)
104 print attr_str + c_str + attr_name + " " + c_name + obj.Normal
105 print obj.Bold + obj.Underline + \
106 c_name + "Bold Underline " + c + obj.Normal
107
108if __name__ == '__main__':
109 print "=== termcap enabled ==="
110 test_termcap(termcap)
111 print termcap.Normal
112 print "=== termcap disabled ==="
113 test_termcap(no_termcap)
105def test_termcap(obj):
106 for c_name in color_names:
107 c_str = getattr(obj, c_name)
108 print c_str + c_name + obj.Normal
109 for attr_name in capability_names:
110 if attr_name == 'Normal':
111 continue
112 attr_str = getattr(obj, attr_name)
113 print attr_str + c_str + attr_name + " " + c_name + obj.Normal
114 print obj.Bold + obj.Underline + \
115 c_name + "Bold Underline " + c + obj.Normal
116
117if __name__ == '__main__':
118 print "=== termcap enabled ==="
119 test_termcap(termcap)
120 print termcap.Normal
121 print "=== termcap disabled ==="
122 test_termcap(no_termcap)