Improved the appearance of the simple cursor.

This commit is contained in:
Andrew Hamilton 2016-02-06 21:16:55 +00:00
parent abad5d298f
commit 603dc78d03
2 changed files with 25 additions and 13 deletions

View file

@ -44,13 +44,13 @@ class Status:
timed_out = 9
_STATUS_COLORS = [(Status.ok, termstr.Color.green),
(Status.problem, termstr.Color.red),
(Status.normal, termstr.Color.white),
(Status.not_applicable, termstr.Color.grey_100),
(Status.running, termstr.Color.light_blue),
(Status.paused, termstr.Color.yellow),
(Status.timed_out, termstr.Color.purple)]
_STATUS_COLORS = {Status.ok: termstr.Color.green,
Status.problem: termstr.Color.red,
Status.normal: termstr.Color.white,
Status.not_applicable: termstr.Color.grey_100,
Status.running: termstr.Color.light_blue,
Status.paused: termstr.Color.yellow,
Status.timed_out: termstr.Color.purple}
STATUS_MEANINGS = [
@ -62,13 +62,13 @@ STATUS_MEANINGS = [
]
_STATUS_TO_TERMSTR = {
status: termstr.TermStr("", termstr.CharStyle(fg_color=color))
for status, color in _STATUS_COLORS}
for status, color in _STATUS_COLORS.items()}
_STATUS_TO_TERMSTR[Status.error] = termstr.TermStr(
"E ", termstr.CharStyle(fg_color=termstr.Color.red))
_STATUS_TO_TERMSTR[Status.pending] = ". "
_STATUS_TO_TERMSTR_SIMPLE = {
status: termstr.TermStr(" ", termstr.CharStyle(bg_color=color))
for status, color in _STATUS_COLORS}
for status, color in _STATUS_COLORS.items()}
_STATUS_TO_TERMSTR_SIMPLE[Status.error] = termstr.TermStr(
"E", termstr.CharStyle(bg_color=termstr.Color.red))
_STATUS_TO_TERMSTR_SIMPLE[Status.pending] = "."

20
vigil
View file

@ -61,6 +61,7 @@ import os
import pickle
import shutil
import signal
import statistics
import subprocess
import sys
import tempfile
@ -227,16 +228,27 @@ class Entry(collections.UserList):
self.widget = fill3.Row(results)
self.appearance_cache = None
def _get_cursor(self):
result_selected = self.widget[self.highlighted]
if self.summary.is_status_simple:
status_color = tools._STATUS_COLORS.get(
result_selected.status, None)
fg_color = (termstr.Color.white
if (status_color is None
or statistics.mean(status_color) < (255 / 2))
else termstr.Color.black)
return fill3.Text(termstr.TermStr("●", termstr.CharStyle(
fg_color=fg_color, bg_color=status_color)))
else:
return fill3.Style(result_selected, reverse_style)
def appearance_min(self):
# 'appearance' local variable exists because appearance_cache can
# become None at any time.
appearance = self.appearance_cache
if appearance is None:
if self.highlighted is not None:
cursor = (fill3.Text("●") if self.summary.is_status_simple
else fill3.Style(self.widget[self.highlighted],
reverse_style))
self.widget[self.highlighted] = cursor
self.widget[self.highlighted] = self._get_cursor()
new_appearance = self.widget.appearance_min()
path = tools._path_colored(self.path)
padding = " " * (self.summary._max_path_length - len(path) + 1)