Skip to content

Commit cf5fae7

Browse files
committed
Add terminal.py from firebase-ios-sdk
1 parent 969efa2 commit cf5fae7

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

scripts/lib/terminal.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright 2019 Google
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import subprocess
16+
import threading
17+
18+
19+
_lock = threading.Lock()
20+
_columns = None
21+
22+
23+
def columns():
24+
"""Returns the number of columns in the terminal's display."""
25+
26+
global _columns
27+
with _lock:
28+
if _columns is None:
29+
_columns = _find_terminal_columns()
30+
return _columns
31+
32+
33+
def _find_terminal_columns():
34+
try:
35+
result = subprocess.check_output(['tput', 'cols'])
36+
return int(result.rstrip())
37+
except subprocess.CalledProcessError:
38+
return 80

0 commit comments

Comments
 (0)