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:
parent
fcb33b8a0a
commit
2fdeb55218
|
@ -16,6 +16,7 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Tuple
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
@ -104,6 +105,20 @@ def format_datetime(d):
|
||||||
return _("{amount:2} {unit} ago").format(amount=amount, unit=unit)
|
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):
|
class SnapInfoView(WidgetWrap):
|
||||||
|
|
||||||
# This is mostly like a Pile but it tries to be a bit smart about
|
# 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]
|
publisher = [('info_minor', _("by: ")), snap.publisher]
|
||||||
if snap.verified:
|
if snap.verified:
|
||||||
# Check extend_dec_special_charmap for the meaning of the
|
publisher.append(" ")
|
||||||
# narrow non-breakable space here.
|
publisher.extend(check_mark())
|
||||||
publisher.append(('verified', ' \N{check mark}\N{NNBSP}'))
|
|
||||||
elif snap.starred:
|
elif snap.starred:
|
||||||
publisher.append(' \N{circled white star}')
|
publisher.append(' \N{circled white star}')
|
||||||
|
|
||||||
|
@ -439,9 +453,7 @@ class SnapListView(BaseView):
|
||||||
self, snap, snap.name in self.selections_by_name)
|
self, snap, snap.name in self.selections_by_name)
|
||||||
publisher = [snap.publisher]
|
publisher = [snap.publisher]
|
||||||
if snap.verified:
|
if snap.verified:
|
||||||
# Check extend_dec_special_charmap for the meaning of the
|
publisher.extend(check_mark())
|
||||||
# narrow non-breakable space here.
|
|
||||||
publisher.append(('verified', '\N{check mark}\N{NNBSP}'))
|
|
||||||
elif snap.starred:
|
elif snap.starred:
|
||||||
publisher.append('\N{circled white star}')
|
publisher.append('\N{circled white star}')
|
||||||
row = [
|
row = [
|
||||||
|
@ -453,7 +465,11 @@ class SnapListView(BaseView):
|
||||||
body.append(AttrMap(
|
body.append(AttrMap(
|
||||||
TableRow(row),
|
TableRow(row),
|
||||||
'menu_button',
|
'menu_button',
|
||||||
{None: 'menu_button focus', 'verified': 'verified focus'},
|
{
|
||||||
|
None: 'menu_button focus',
|
||||||
|
'verified': 'verified focus',
|
||||||
|
'verified invisible': 'verified inv focus'
|
||||||
|
},
|
||||||
))
|
))
|
||||||
table = NoTabCyclingTableListBox(
|
table = NoTabCyclingTableListBox(
|
||||||
body,
|
body,
|
||||||
|
|
|
@ -66,6 +66,8 @@ PALETTE_COLOR = [
|
||||||
|
|
||||||
('verified', 'good', 'bg'),
|
('verified', 'good', 'bg'),
|
||||||
('verified focus', 'good', 'gray'),
|
('verified focus', 'good', 'gray'),
|
||||||
|
('verified invisible', 'bg', 'bg'),
|
||||||
|
('verified inv focus', 'gray', 'gray'),
|
||||||
]
|
]
|
||||||
|
|
||||||
PALETTE_MONO = [
|
PALETTE_MONO = [
|
||||||
|
@ -100,6 +102,8 @@ PALETTE_MONO = [
|
||||||
|
|
||||||
('verified', 'white', 'black'),
|
('verified', 'white', 'black'),
|
||||||
('verified focus', 'black', 'white'),
|
('verified focus', 'black', 'white'),
|
||||||
|
('verified invisible', 'white', 'black'),
|
||||||
|
('verified inv focus', 'black', 'white'),
|
||||||
]
|
]
|
||||||
|
|
||||||
urwid_8_names = (
|
urwid_8_names = (
|
||||||
|
|
|
@ -53,11 +53,6 @@ def extend_dec_special_charmap():
|
||||||
ord('\N{upper half block}'): '=',
|
ord('\N{upper half block}'): '=',
|
||||||
ord('\N{FULL BLOCK}'): urwid.escape.DEC_SPECIAL_CHARMAP[
|
ord('\N{FULL BLOCK}'): urwid.escape.DEC_SPECIAL_CHARMAP[
|
||||||
ord('\N{BOX DRAWINGS LIGHT VERTICAL}')],
|
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}'): '*',
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue