1
0
mirror of https://xff.cz/git/u-boot/ synced 2025-09-23 19:42:08 +02:00

patman: Convert camel case in terminal.py

Convert this file to snake case and update all files which use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2022-01-29 14:14:18 -07:00
parent 252ac58996
commit 098b10fb34
8 changed files with 82 additions and 82 deletions

View File

@@ -51,7 +51,7 @@ class PrintLine:
(self.newline, self.colour, self.bright, self.text))
def CalcAsciiLen(text):
def calc_ascii_len(text):
"""Calculate the length of a string, ignoring any ANSI sequences
When displayed on a terminal, ANSI sequences don't take any space, so we
@@ -67,20 +67,20 @@ def CalcAsciiLen(text):
>>> text = col.build(Color.RED, 'abc')
>>> len(text)
14
>>> CalcAsciiLen(text)
>>> calc_ascii_len(text)
3
>>>
>>> text += 'def'
>>> CalcAsciiLen(text)
>>> calc_ascii_len(text)
6
>>> text += col.build(Color.RED, 'abc')
>>> CalcAsciiLen(text)
>>> calc_ascii_len(text)
9
"""
result = ansi_escape.sub('', text)
return len(result)
def TrimAsciiLen(text, size):
def trim_ascii_len(text, size):
"""Trim a string containing ANSI sequences to the given ASCII length
The string is trimmed with ANSI sequences being ignored for the length
@@ -90,18 +90,18 @@ def TrimAsciiLen(text, size):
>>> text = col.build(Color.RED, 'abc')
>>> len(text)
14
>>> CalcAsciiLen(TrimAsciiLen(text, 4))
>>> calc_ascii_len(trim_ascii_len(text, 4))
3
>>> CalcAsciiLen(TrimAsciiLen(text, 2))
>>> calc_ascii_len(trim_ascii_len(text, 2))
2
>>> text += 'def'
>>> CalcAsciiLen(TrimAsciiLen(text, 4))
>>> calc_ascii_len(trim_ascii_len(text, 4))
4
>>> text += col.build(Color.RED, 'ghi')
>>> CalcAsciiLen(TrimAsciiLen(text, 7))
>>> calc_ascii_len(trim_ascii_len(text, 7))
7
"""
if CalcAsciiLen(text) < size:
if calc_ascii_len(text) < size:
return text
pos = 0
out = ''
@@ -130,7 +130,7 @@ def TrimAsciiLen(text, size):
return out
def Tprint(text='', newline=True, colour=None, limit_to_line=False, bright=True):
def tprint(text='', newline=True, colour=None, limit_to_line=False, bright=True):
"""Handle a line of output to the terminal.
In test mode this is recorded in a list. Otherwise it is output to the
@@ -155,11 +155,11 @@ def Tprint(text='', newline=True, colour=None, limit_to_line=False, bright=True)
else:
if limit_to_line:
cols = shutil.get_terminal_size().columns
text = TrimAsciiLen(text, cols)
text = trim_ascii_len(text, cols)
print(text, end='', flush=True)
last_print_len = CalcAsciiLen(text)
last_print_len = calc_ascii_len(text)
def PrintClear():
def print_clear():
"""Clear a previously line that was printed with no newline"""
global last_print_len
@@ -167,15 +167,15 @@ def PrintClear():
print('\r%s\r' % (' '* last_print_len), end='', flush=True)
last_print_len = None
def SetPrintTestMode(enable=True):
def set_print_test_mode(enable=True):
"""Go into test mode, where all printing is recorded"""
global print_test_mode
print_test_mode = enable
GetPrintTestLines()
get_print_test_lines()
def GetPrintTestLines():
"""Get a list of all lines output through Tprint()
def get_print_test_lines():
"""Get a list of all lines output through tprint()
Returns:
A list of PrintLine objects
@@ -186,7 +186,7 @@ def GetPrintTestLines():
print_test_list = []
return ret
def EchoPrintTestLines():
def echo_print_test_lines():
"""Print out the text lines collected"""
for line in print_test_list:
if line.colour:
@@ -221,7 +221,7 @@ class Color(object):
except:
self._enabled = False
def Start(self, color, bright=True):
def start(self, color, bright=True):
"""Returns a start color code.
Args:
@@ -236,7 +236,7 @@ class Color(object):
return base % (color + 30)
return ''
def Stop(self):
def stop(self):
"""Returns a stop color code.
Returns: