Skip to content

Commit f0af1fb

Browse files
committed
Use a compacter logo (Closes #112)
1 parent 3c2eea7 commit f0af1fb

File tree

3 files changed

+73
-29
lines changed

3 files changed

+73
-29
lines changed

cookieplone/utils/console.py

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,51 @@
1818
from .internal import cookieplone_info, version_info
1919

2020
BANNER = """
21-
.xxxxxxxxxxxxxx.
22-
;xxxxxxxxxxxxxxxxxxxxxx;
23-
;xxxxxxxxxxxxxxxxxxxxxxxxxxxx;
24-
xxxxxxxxxx xxxxxxxxxx
25-
xxxxxxxx. .xxxxxxxx
26-
xxxxxxx xxxxxxx: xxxxxxx
27-
:xxxxxx xxxxxxxxxx xxxxxx:
28-
:xxxxx+ xxxxxxxxxxx +xxxxx:
29-
.xxxxx. :xxxxxxxxxx .xxxxx.
30-
xxxxx+ ;xxxxxxxx +xxxxx
31-
xxxxx +xx. xxxxx.
32-
xxxxx: .xxxxxxxx :xxxxx
33-
xxxxx .xxxxxxxxxx xxxxx
34-
xxxxx xxxxxxxxxxx xxxxx
35-
xxxxx .xxxxxxxxxx xxxxx
36-
xxxxx: .xxxxxxxx :xxxxx
37-
.xxxxx ;xx. ... xxxxx.
38-
xxxxx+ :xxxxxxxx +xxxxx
39-
.xxxxx. :xxxxxxxxxx .xxxxx.
40-
:xxxxx+ xxxxxxxxxxx ;xxxxx:
41-
:xxxxxx xxxxxxxxxx xxxxxx:
42-
xxxxxxx xxxxxxx; xxxxxxx
43-
xxxxxxxx. .xxxxxxxx
44-
xxxxxxxxxx xxxxxxxxxx
45-
;xxxxxxxxxxxxxxxxxxxxxxxxxxxx+
46-
;xxxxxxxxxxxxxxxxxxxxxx;
47-
.xxxxxxxxxxxxxx.
21+
*******
22+
***************
23+
*** ***
24+
*** *** ***
25+
*** ***** ***
26+
*** *** ***
27+
*** *** ***
28+
*** ***** ***
29+
*** *** *** ***
30+
*** ***** ***
31+
*** *** ***
32+
*** ***
33+
***************
34+
*******
4835
"""
4936

37+
PLONE_LOGOTYPE_BANNER = """
38+
*******
39+
***************
40+
*** *** ********* *** ***
41+
*** *** *** *********** *** * R *
42+
*** ***** *** *** *** *** ***
43+
*** *** *** *** *** *** **** *** *** ****
44+
*** *** *** *** *** *** ******** ********* ********
45+
*** ***** *** *********** *** *** *** **** *** *** ***
46+
*** *** *** *** ********* *** *** *** *** *** **********
47+
*** ***** *** *** *** *** *** *** *** *********
48+
*** *** *** *** **** *** *** *** *** *** ...
49+
*** *** *** ***** ******** *** *** ********
50+
*************** *** *** **** *** *** ****
51+
*******
52+
"""
53+
54+
55+
def choose_banner() -> str:
56+
"""Based on the terminal width, decide which banner to use."""
57+
banner = BANNER
58+
try:
59+
terminal_size = os.get_terminal_size()
60+
except OSError:
61+
return banner
62+
if terminal_size and terminal_size.columns >= 90:
63+
banner = PLONE_LOGOTYPE_BANNER
64+
return banner
65+
5066

5167
def _print(msg: str):
5268
"""Wrapper around rich.print."""
@@ -72,7 +88,8 @@ def print_plone_banner():
7288
"""Print Plone banner."""
7389
style: str = "bold"
7490
color: str = "blue"
75-
print(BANNER, style, color)
91+
banner = choose_banner()
92+
print(banner, style, color)
7693

7794

7895
def info(msg: str):
@@ -142,8 +159,9 @@ def table_available_templates(
142159

143160

144161
def welcome_screen(templates: list[t.CookieploneTemplate] | None = None):
162+
banner = choose_banner()
145163
items = [
146-
Align.center(f"[bold blue]{BANNER}[/bold blue]"),
164+
Align.center(f"[bold blue]{banner}[/bold blue]"),
147165
]
148166
if templates:
149167
items.append(

news/112.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use a compacter logo. @ericof, @acsr

tests/utils/test_console.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,37 @@
55
from cookieplone.utils import console
66

77

8+
@pytest.fixture
9+
def set_console_width(monkeypatch):
10+
import os
11+
12+
def func(width: int) -> None:
13+
monkeypatch.setattr(
14+
"os.get_terminal_size", lambda: os.terminal_size((width, 80))
15+
)
16+
17+
return func
18+
19+
820
@patch("cookieplone.utils.console.print")
921
def test_print_plone_banner(mock_print):
1022
console.print_plone_banner()
1123
mock_print.assert_called_once_with(console.BANNER, "bold", "blue")
1224

1325

26+
@pytest.mark.parametrize(
27+
"width,banner",
28+
[
29+
(80, console.BANNER),
30+
(90, console.PLONE_LOGOTYPE_BANNER),
31+
(100, console.PLONE_LOGOTYPE_BANNER),
32+
],
33+
)
34+
def test_choose_banner(set_console_width, width: int, banner: str):
35+
set_console_width(width)
36+
assert console.choose_banner() == banner
37+
38+
1439
@pytest.mark.parametrize(
1540
"func,msg,style,color",
1641
[

0 commit comments

Comments
 (0)