Coding style
- Rename appearance_min to appearance.
This commit is contained in:
parent
6681101b1c
commit
695c1d7f96
7 changed files with 41 additions and 42 deletions
|
|
@ -116,12 +116,12 @@ class Entry:
|
|||
def __getitem__(self, index):
|
||||
return self.results[index]
|
||||
|
||||
def appearance_min(self):
|
||||
def appearance(self):
|
||||
if self.appearance_cache is None or self.last_width != Entry.MAX_WIDTH:
|
||||
self.last_width = Entry.MAX_WIDTH
|
||||
if self.highlighted is not None:
|
||||
self.results[self.highlighted].is_highlighted = True
|
||||
row_appearance = self.widget.appearance_min()
|
||||
row_appearance = self.widget.appearance()
|
||||
path = tools.path_colored(self.path)
|
||||
padding = " " * (self.last_width - len(self.results) + 1)
|
||||
self.appearance_cache = [row_appearance[0] + padding + path]
|
||||
|
|
@ -724,7 +724,7 @@ class Screen:
|
|||
selected_widget = self._summary.get_selection()
|
||||
x, y = selected_widget.scroll_position
|
||||
widget_width, widget_height = fill3.appearance_dimensions(
|
||||
selected_widget.result.appearance_min())
|
||||
selected_widget.result.appearance())
|
||||
listing_width, listing_height = self._listing.widget.last_dimensions
|
||||
listing_width -= 1 # scrollbars
|
||||
listing_height -= 1
|
||||
|
|
|
|||
|
|
@ -589,7 +589,7 @@ class Result:
|
|||
return termstr.TermStr("+", termstr.CharStyle(
|
||||
fg_color=termstr.Color.white, bg_color=status_color, is_bold=True))
|
||||
|
||||
def appearance_min(self):
|
||||
def appearance(self):
|
||||
return [self._get_cursor() if self.is_highlighted else STATUS_TO_TERMSTR[self.status]]
|
||||
|
||||
def get_pages_dir(self):
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ def make_listing_page(url_path):
|
|||
tool_name_colored = tools.tool_name_colored(tool, path)
|
||||
header = fill3.appearance_as_html([tools.path_colored(path) + " - " + tool_name_colored,
|
||||
termstr.TermStr(" ").underline() * 100])
|
||||
body = fill3.appearance_as_html(result.appearance_min())
|
||||
body = fill3.appearance_as_html(result.appearance())
|
||||
return make_page(header + body, f"{path} - {tool_name}")
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ _DIMENSIONS = (100, 60)
|
|||
|
||||
|
||||
def _widget_to_string(widget, dimensions=_DIMENSIONS):
|
||||
appearance = (widget.appearance_min() if dimensions is None
|
||||
appearance = (widget.appearance() if dimensions is None
|
||||
else widget.appearance_for(dimensions))
|
||||
return str(fill3.join("\n", appearance))
|
||||
|
||||
|
|
|
|||
|
|
@ -31,8 +31,7 @@ class ExecutablesTestCase(unittest.TestCase):
|
|||
|
||||
|
||||
def widget_to_string(widget):
|
||||
appearance = widget.appearance_min()
|
||||
return str(fill3.join("\n", appearance))
|
||||
return str(fill3.join("\n", widget.appearance()))
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
|
|
|
|||
|
|
@ -88,8 +88,8 @@ class Row:
|
|||
return join_horizontal([column_widget.appearance_for((item_width, height))
|
||||
for column_widget, item_width in zip(self.widgets, widths)])
|
||||
|
||||
def appearance_min(self):
|
||||
appearances = [column_widget.appearance_min() for column_widget in self.widgets]
|
||||
def appearance(self):
|
||||
appearances = [column_widget.appearance() for column_widget in self.widgets]
|
||||
dimensions = [appearance_dimensions(appearance) for appearance in appearances]
|
||||
max_height = max(height for width, height in dimensions)
|
||||
return join_horizontal([appearance_resize(appearance, (width, max_height))
|
||||
|
|
@ -132,7 +132,7 @@ class Column:
|
|||
def _appearance_list(self, widgets):
|
||||
if widgets == []:
|
||||
return []
|
||||
appearances = [row_widget.appearance_min() for row_widget in widgets]
|
||||
appearances = [row_widget.appearance() for row_widget in widgets]
|
||||
dimensions = [appearance_dimensions(appearance) for appearance in appearances]
|
||||
max_width = max(width for width, height in dimensions)
|
||||
padded_appearances = [appearance_resize(appearance, (max_width, height))
|
||||
|
|
@ -146,7 +146,7 @@ class Column:
|
|||
start_y, end_y = interval
|
||||
return self._appearance_list(self.widgets[start_y:end_y])
|
||||
|
||||
def appearance_min(self):
|
||||
def appearance(self):
|
||||
return self._appearance_list(self.widgets)
|
||||
|
||||
|
||||
|
|
@ -156,7 +156,7 @@ class Filler:
|
|||
self.widget = widget
|
||||
|
||||
def appearance_for(self, dimensions):
|
||||
return appearance_resize(self.widget.appearance_min(), dimensions)
|
||||
return appearance_resize(self.widget.appearance(), dimensions)
|
||||
|
||||
|
||||
class ScrollBar:
|
||||
|
|
@ -231,7 +231,7 @@ class Portal:
|
|||
try:
|
||||
appearance = self.widget.appearance_interval((y, y+height))
|
||||
except AttributeError:
|
||||
appearance = self.widget.appearance_min()[y:y+height]
|
||||
appearance = self.widget.appearance()[y:y+height]
|
||||
self.last_dimensions = dimensions
|
||||
return appearance_resize([row[x:x+width] for row in appearance],
|
||||
dimensions, self.background_char)
|
||||
|
|
@ -270,7 +270,7 @@ class View:
|
|||
try:
|
||||
full_width, full_height = self.portal.widget.appearance_dimensions()
|
||||
except AttributeError:
|
||||
full_appearance = self.portal.widget.appearance_min()
|
||||
full_appearance = self.portal.widget.appearance()
|
||||
full_width, full_height = appearance_dimensions(full_appearance)
|
||||
if full_width == 0 or full_height == 0:
|
||||
return self.portal.appearance_for(dimensions)
|
||||
|
|
@ -311,11 +311,11 @@ class Text:
|
|||
def __init__(self, text, pad_char=" "):
|
||||
self.text = str_to_appearance(text, pad_char)
|
||||
|
||||
def appearance_min(self):
|
||||
def appearance(self):
|
||||
return self.text
|
||||
|
||||
def appearance_for(self, dimensions):
|
||||
return appearance_resize(self.appearance_min(), dimensions)
|
||||
return appearance_resize(self.appearance(), dimensions)
|
||||
|
||||
|
||||
class Table:
|
||||
|
|
@ -324,10 +324,10 @@ class Table:
|
|||
self._widgets = table
|
||||
self._pad_char = pad_char
|
||||
|
||||
def appearance_min(self):
|
||||
def appearance(self):
|
||||
if self._widgets == []:
|
||||
return []
|
||||
appearances = [[cell.appearance_min() for cell in row] for row in self._widgets]
|
||||
appearances = [[cell.appearance() for cell in row] for row in self._widgets]
|
||||
row_heights = [0] * len(self._widgets)
|
||||
column_widths = [0] * len(self._widgets[0])
|
||||
for y, row in enumerate(appearances):
|
||||
|
|
@ -376,8 +376,8 @@ class Border:
|
|||
result.append(self.bottom_left + self.bottom * content_width + self.bottom_right)
|
||||
return result
|
||||
|
||||
def appearance_min(self):
|
||||
return self._add_border(self.widget.appearance_min())
|
||||
def appearance(self):
|
||||
return self._add_border(self.widget.appearance())
|
||||
|
||||
def appearance_for(self, dimensions):
|
||||
width, height = dimensions
|
||||
|
|
@ -389,8 +389,8 @@ class Placeholder:
|
|||
def __init__(self, widget=None):
|
||||
self.widget = widget
|
||||
|
||||
def appearance_min(self):
|
||||
return self.widget.appearance_min()
|
||||
def appearance(self):
|
||||
return self.widget.appearance()
|
||||
|
||||
def appearance_for(self, dimensions):
|
||||
return self.widget.appearance_for(dimensions)
|
||||
|
|
@ -398,12 +398,12 @@ class Placeholder:
|
|||
|
||||
class Fixed:
|
||||
|
||||
def __init__(self, appearance_min):
|
||||
self.appearance_min_ = appearance_min
|
||||
self.dimensions = appearance_dimensions(appearance_min)
|
||||
def __init__(self, appearance):
|
||||
self.appearance_ = appearance
|
||||
self.dimensions = appearance_dimensions(appearance)
|
||||
|
||||
def appearance_min(self):
|
||||
return self.appearance_min_
|
||||
def appearance(self):
|
||||
return self.appearance_
|
||||
|
||||
def appearance_dimensions(self):
|
||||
return self.dimensions
|
||||
|
|
|
|||
|
|
@ -17,19 +17,19 @@ class WidgetTests(unittest.TestCase):
|
|||
|
||||
def test_rows_widget(self):
|
||||
rows = fill3.Row([self.TEXT_A, self.TEXT_B])
|
||||
self.assert_string(rows.appearance_min(), "AB")
|
||||
self.assert_string(rows.appearance(), "AB")
|
||||
rows = fill3.Row([fill3.Filler(self.TEXT_A), fill3.Filler(self.TEXT_B)])
|
||||
self.assert_string(rows.appearance_for((4, 1)), "A B ")
|
||||
|
||||
def test_columns_widget(self):
|
||||
columns = fill3.Column([self.TEXT_A, self.TEXT_B])
|
||||
self.assert_string(columns.appearance_min(), "A\n"
|
||||
self.assert_string(columns.appearance(), "A\n"
|
||||
"B")
|
||||
|
||||
def test_text_widget(self):
|
||||
self.assert_string(self.TEXT_A.appearance_min(), "A")
|
||||
self.assert_string(self.TEXT_A.appearance(), "A")
|
||||
text = "foo\nbar"
|
||||
self.assert_string(fill3.Text(text).appearance_min(), "foo\n"
|
||||
self.assert_string(fill3.Text(text).appearance(), "foo\n"
|
||||
"bar")
|
||||
|
||||
def test_portal_widget(self):
|
||||
|
|
@ -47,7 +47,7 @@ class WidgetTests(unittest.TestCase):
|
|||
for empty_contents in [fill3.Filler(fill3.Text("")), fill3.Column([])]:
|
||||
self.assert_string(fill3.Border(empty_contents).appearance_for((2, 2)), "┌┐\n"
|
||||
"└┘")
|
||||
self.assert_string(fill3.Border(fill3.Column([])).appearance_min(), "┌┐\n"
|
||||
self.assert_string(fill3.Border(fill3.Column([])).appearance(), "┌┐\n"
|
||||
"└┘")
|
||||
self.assert_string(fill3.Border(empty_contents).appearance_for((3, 3)), "┌─┐\n"
|
||||
"│ │\n"
|
||||
|
|
@ -62,9 +62,9 @@ class WidgetTests(unittest.TestCase):
|
|||
|
||||
def test_placeholder_widget(self):
|
||||
placeholder = fill3.Placeholder(self.TEXT_A)
|
||||
self.assert_string(placeholder.appearance_min(), "A")
|
||||
self.assert_string(placeholder.appearance(), "A")
|
||||
placeholder.widget = self.TEXT_B
|
||||
self.assert_string(placeholder.appearance_min(), "B")
|
||||
self.assert_string(placeholder.appearance(), "B")
|
||||
|
||||
def assert_string2(self, appearance, expected_string):
|
||||
self.assertEqual(("\n".join(line.data for line in appearance),
|
||||
|
|
@ -103,20 +103,20 @@ class WidgetTests(unittest.TestCase):
|
|||
|
||||
def test_table_widget(self):
|
||||
table = fill3.Table([])
|
||||
self.assert_string(table.appearance_min(), "")
|
||||
self.assert_string(table.appearance(), "")
|
||||
table = fill3.Table([[self.TEXT_A]])
|
||||
self.assert_string(table.appearance_min(), "A")
|
||||
self.assert_string(table.appearance(), "A")
|
||||
table = fill3.Table([[self.TEXT_A, self.TEXT_B]])
|
||||
self.assert_string(table.appearance_min(), "AB")
|
||||
self.assert_string(table.appearance(), "AB")
|
||||
table = fill3.Table([[self.TEXT_A, self.TEXT_B],
|
||||
[self.TEXT_B, self.TEXT_A]])
|
||||
self.assert_string(table.appearance_min(), "AB\n"
|
||||
"BA")
|
||||
self.assert_string(table.appearance(), "AB\n"
|
||||
"BA")
|
||||
label_foo = fill3.Text("FOO")
|
||||
table = fill3.Table([[label_foo, self.TEXT_B],
|
||||
[self.TEXT_B, self.TEXT_A]])
|
||||
self.assert_string(table.appearance_min(), "FOOB\n"
|
||||
"B A")
|
||||
self.assert_string(table.appearance(), "FOOB\n"
|
||||
"B A")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue