snaplist: improve hack to display double stars instead of ✓

We used to rely on the narrow non-breakable space to be displayed as a
star in basic mode. This is not great and could impact other screens.

We now make use of two check-marks (each replaced by a star in basic
mode) and mask one of them in rich mode using display attributes.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
This commit is contained in:
Olivier Gayot 2022-05-04 11:47:34 +02:00
parent fcb33b8a0a
commit 2fdeb55218
3 changed files with 27 additions and 12 deletions

View File

@ -16,6 +16,7 @@
import asyncio
import datetime
import logging
from typing import Tuple
import yaml
@ -104,6 +105,20 @@ def format_datetime(d):
return _("{amount:2} {unit} ago").format(amount=amount, unit=unit)
def check_mark() -> Tuple[Tuple[str, str], ...]:
""" Return a tuple that can be passed to a urwid.Text() """
# We want a single check-mark "✓" in rich-mode but a double star "**" in
# basic mode. Because we have a 1:1 mapping between a given unicode
# character and its ASCII substitute, we use two check-marks and make one
# invisible in rich-mode. In basic mode, they both get substituted with a
# star.
return (
('verified', '\N{check mark}'),
('verified invisible', '\N{check mark}'),
)
class SnapInfoView(WidgetWrap):
# This is mostly like a Pile but it tries to be a bit smart about
@ -182,9 +197,8 @@ class SnapInfoView(WidgetWrap):
publisher = [('info_minor', _("by: ")), snap.publisher]
if snap.verified:
# Check extend_dec_special_charmap for the meaning of the
# narrow non-breakable space here.
publisher.append(('verified', ' \N{check mark}\N{NNBSP}'))
publisher.append(" ")
publisher.extend(check_mark())
elif snap.starred:
publisher.append(' \N{circled white star}')
@ -439,9 +453,7 @@ class SnapListView(BaseView):
self, snap, snap.name in self.selections_by_name)
publisher = [snap.publisher]
if snap.verified:
# Check extend_dec_special_charmap for the meaning of the
# narrow non-breakable space here.
publisher.append(('verified', '\N{check mark}\N{NNBSP}'))
publisher.extend(check_mark())
elif snap.starred:
publisher.append('\N{circled white star}')
row = [
@ -453,7 +465,11 @@ class SnapListView(BaseView):
body.append(AttrMap(
TableRow(row),
'menu_button',
{None: 'menu_button focus', 'verified': 'verified focus'},
{
None: 'menu_button focus',
'verified': 'verified focus',
'verified invisible': 'verified inv focus'
},
))
table = NoTabCyclingTableListBox(
body,

View File

@ -66,6 +66,8 @@ PALETTE_COLOR = [
('verified', 'good', 'bg'),
('verified focus', 'good', 'gray'),
('verified invisible', 'bg', 'bg'),
('verified inv focus', 'gray', 'gray'),
]
PALETTE_MONO = [
@ -100,6 +102,8 @@ PALETTE_MONO = [
('verified', 'white', 'black'),
('verified focus', 'black', 'white'),
('verified invisible', 'white', 'black'),
('verified inv focus', 'black', 'white'),
]
urwid_8_names = (

View File

@ -53,11 +53,6 @@ def extend_dec_special_charmap():
ord('\N{upper half block}'): '=',
ord('\N{FULL BLOCK}'): urwid.escape.DEC_SPECIAL_CHARMAP[
ord('\N{BOX DRAWINGS LIGHT VERTICAL}')],
# XXX: Hack to show the verified snap publishers with two stars when
# unicode is not supported. In rich mode, we display ✪ followed by a
# mostly invisible character (i.e., NNBSP). In basic mode,
# both characters get translated to a star, resulting in two stars.
ord('\N{NNBSP}'): '*',
})