[yum-commits] Branch 'yum-3_2_X' - 3 commits - cli.py output.py yum/config.py yum/i18n.py yumcommands.py
James Antill
james at osuosl.org
Fri Nov 21 05:14:45 UTC 2008
cli.py | 16 ++++
output.py | 196 +++++++++++++++++++++++++++++++++++++++------------------
yum/config.py | 13 +++
yum/i18n.py | 6 -
yumcommands.py | 15 ++--
5 files changed, 179 insertions(+), 67 deletions(-)
New commits:
commit e62fbe4cd187fc47d93872e5902f7bae26638de7
Author: James Antill <james at and.org>
Date: Fri Nov 21 00:14:37 2008 -0500
Use highlighting config. in groupinfo -v
diff --git a/output.py b/output.py
index d07d0cb..81b22ca 100755
--- a/output.py
+++ b/output.py
@@ -686,8 +686,14 @@ class YumOutput:
continue
for (apkg, ipkg) in sorted(pkg_names2pkgs[item],
key=lambda x: x[1] or x[0]):
+ if ipkg and apkg:
+ highlight = self.conf.color_list_installed_older
+ elif apkg:
+ highlight = self.conf.color_list_available_install
+ else:
+ highlight = False
self.simpleEnvraList(ipkg or apkg, ui_overflow=True,
- indent=indent, highlight=ipkg and apkg,
+ indent=indent, highlight=highlight,
columns=columns)
def displayPkgsInGroups(self, group):
commit 6707f479bb37b8f45a246a04d209ca37b967d492
Author: James Antill <james at and.org>
Date: Thu Nov 20 19:51:43 2008 -0500
Fix search highlighting to ignore case, allow configurable highlight
diff --git a/output.py b/output.py
index 87bb3c7..d07d0cb 100755
--- a/output.py
+++ b/output.py
@@ -250,7 +250,7 @@ class YumTerm:
cap = self._ctigetstr(cap_name) or ''
return re.sub(r'\$<\d+>[/*]?', '', cap)
- def sub(self, haystack, beg, end, needles, escape=None):
+ def sub(self, haystack, beg, end, needles, escape=None, ignore_case=False):
if not self.__enabled:
return haystack
@@ -259,7 +259,10 @@ class YumTerm:
render = lambda match: beg + match.group() + end
for needle in needles:
- haystack = re.sub(escape(needle), render, haystack)
+ pat = escape(needle)
+ if ignore_case:
+ pat = re.template(pat, re.I)
+ haystack = re.sub(pat, render, haystack)
return haystack
def sub_norm(self, haystack, beg, needles, **kwds):
return self.sub(haystack, beg, self.MODE['normal'], needles, **kwds)
@@ -268,7 +271,7 @@ class YumTerm:
return self.sub_norm(haystack, self.MODE[mode], needles, **kwds)
def sub_bold(self, haystack, needles, **kwds):
- return self.sub_mode(haystack, 'bold', needles)
+ return self.sub_mode(haystack, 'bold', needles, **kwds)
def sub_fg(self, haystack, color, needles, **kwds):
return self.sub_norm(haystack, self.FG_COLOR[color], needles, **kwds)
@@ -341,6 +344,10 @@ class YumOutput:
hiend = self.term.MODE['normal']
return (hibeg, hiend)
+ def _sub_highlight(self, haystack, highlight, needles, **kwds):
+ hibeg, hiend = self._highlight(highlight)
+ return self.term.sub(haystack, hibeg, hiend, needles, **kwds)
+
@staticmethod
def _calc_columns_spaces_helps(current, data_tups, left):
""" Spaces left on the current field will help how many pkgs? """
@@ -775,7 +782,8 @@ class YumOutput:
def format_time(seconds, use_hours=0):
return urlgrabber.progress.format_time(seconds, use_hours)
- def matchcallback(self, po, values, matchfor=None, verbose=None):
+ def matchcallback(self, po, values, matchfor=None, verbose=None,
+ highlight=None):
""" Output search/provides type callback matches. po is the pkg object,
values are the things in the po that we've matched.
If matchfor is passed, all the strings in that list will be
@@ -788,7 +796,9 @@ class YumOutput:
msg = '%s.%s : ' % (po.name, po.arch)
msg = self.fmtKeyValFill(msg, self._enc(po.summary))
if matchfor:
- msg = self.term.sub_bold(msg, matchfor)
+ if highlight is None:
+ highlight = self.conf.color_search_match
+ msg = self._sub_highlight(msg, highlight, matchfor,ignore_case=True)
print msg
@@ -822,7 +832,8 @@ class YumOutput:
key = _("Other : ")
if matchfor:
- item = self.term.sub_bold(item, matchfor)
+ item = self._sub_highlight(item, highlight, matchfor,
+ ignore_case=True)
if can_overflow:
print self.fmtKeyValFill(key, item)
else:
diff --git a/yum/config.py b/yum/config.py
index b1ad657..700b49a 100644
--- a/yum/config.py
+++ b/yum/config.py
@@ -679,6 +679,8 @@ class YumConf(StartupConf):
color_list_available_upgrade = Option('bold,blue')
color_list_available_downgrade = Option('dim,cyan')
color_list_available_install = Option('normal')
+
+ color_search_match = Option('bold')
_reposlist = []
commit c495c1c37d2f70932b71ea897f7b05974e3d8a76
Author: James Antill <james at and.org>
Date: Thu Nov 20 16:58:31 2008 -0500
Make list color programable, so Seth can have blink :).
Allow color to be turned off/on al. la. GNU cmd line (plus .conf).
Add hilight data for fmtColumns().
Add prefix/suffix arguments for utf8_width_fill().
diff --git a/cli.py b/cli.py
index 13a2bfa..e13d48d 100644
--- a/cli.py
+++ b/cli.py
@@ -1106,6 +1106,20 @@ class YumOptionParser(OptionParser):
if opts.showdupesfromrepos:
self.base.conf.showdupesfromrepos = True
+ if opts.color not in (None, 'auto', 'always', 'never',
+ 'tty', 'if-tty', 'yes', 'no', 'on', 'off'):
+ raise ValueError, _("--color takes one of: auto, always, never")
+ elif opts.color is None:
+ if self.base.conf.color != 'auto':
+ self.base.term.reinit(color=self.base.conf.color)
+ else:
+ _remap = {'tty' : 'auto', 'if-tty' : 'auto',
+ 'yes' : 'always', 'on' : 'always',
+ 'no' : 'never', 'off' : 'never'}
+ opts.color = _remap.get(opts.color, opts.color)
+ if opts.color != 'auto':
+ self.base.term.reinit(color=opts.color)
+
if opts.disableexcludes:
disable_excludes = self._splitArg(opts.disableexcludes)
else:
@@ -1251,6 +1265,8 @@ class YumOptionParser(OptionParser):
metavar='[plugin]')
self.add_option("--skip-broken", action="store_true", dest="skipbroken",
help=_("skip packages with depsolving problems"))
+ self.add_option("", "--color", dest="color", default=None,
+ help=_("control whether color is used"))
diff --git a/output.py b/output.py
index a5504c9..87bb3c7 100755
--- a/output.py
+++ b/output.py
@@ -76,42 +76,7 @@ class YumTerm:
__enabled = True
if hasattr(urlgrabber.progress, 'terminal_width_cached'):
- columns = property(lambda self: _term_width())
- else:
- columns = 80
- lines = 24
- # Output modes:
- MODE = {
- 'bold' : '',
- 'blink' : '',
- 'dim' : '',
- 'reverse' : '',
- 'underline' : '',
- 'normal' : ''
- }
-
- # Colours
- FG_COLOR = {
- 'black' : '',
- 'blue' : '',
- 'green' : '',
- 'cyan' : '',
- 'red' : '',
- 'magenta' : '',
- 'yellow' : '',
- 'white' : ''
- }
-
- BG_COLOR = {
- 'black' : '',
- 'blue' : '',
- 'green' : '',
- 'cyan' : '',
- 'red' : '',
- 'magenta' : '',
- 'yellow' : '',
- 'white' : ''
- }
+ __auto_columns = property(lambda self: _term_width())
__cap_names = {
'underline' : 'smul',
@@ -139,8 +104,90 @@ class YumTerm:
'cyan' : 6,
'white' : 7
}
+ __ansi_forced_MODE = {
+ 'bold' : '\x1b[1m',
+ 'blink' : '\x1b[5m',
+ 'dim' : '',
+ 'reverse' : '\x1b[7m',
+ 'underline' : '\x1b[4m',
+ 'normal' : '\x1b(B\x1b[m'
+ }
+ __ansi_forced_FG_COLOR = {
+ 'black' : '\x1b[30m',
+ 'red' : '\x1b[31m',
+ 'green' : '\x1b[32m',
+ 'yellow' : '\x1b[33m',
+ 'blue' : '\x1b[34m',
+ 'magenta' : '\x1b[35m',
+ 'cyan' : '\x1b[36m',
+ 'white' : '\x1b[37m'
+ }
+ __ansi_forced_BG_COLOR = {
+ 'black' : '\x1b[40m',
+ 'red' : '\x1b[41m',
+ 'green' : '\x1b[42m',
+ 'yellow' : '\x1b[43m',
+ 'blue' : '\x1b[44m',
+ 'magenta' : '\x1b[45m',
+ 'cyan' : '\x1b[46m',
+ 'white' : '\x1b[47m'
+ }
+
+ def __forced_init(self):
+ self.MODE = self.__ansi_forced_MODE
+ self.FG_COLOR = self.__ansi_forced_FG_COLOR
+ self.BG_COLOR = self.__ansi_forced_BG_COLOR
+
+ def reinit(self, term_stream=None, color='auto'):
+ if color == 'never':
+ self.__enabled = False
+ return
+
+ self.__enabled = True
+ if hasattr(urlgrabber.progress, 'terminal_width_cached'):
+ self.columns = self.__auto_columns
+ else:
+ self.columns = 80
+ self.lines = 24
+
+ if color == 'always':
+ self.__forced_init()
+ return
+ assert color == 'auto'
+
+ # Output modes:
+ self.MODE = {
+ 'bold' : '',
+ 'blink' : '',
+ 'dim' : '',
+ 'reverse' : '',
+ 'underline' : '',
+ 'normal' : ''
+ }
+
+ # Colours
+ self.FG_COLOR = {
+ 'black' : '',
+ 'blue' : '',
+ 'green' : '',
+ 'cyan' : '',
+ 'red' : '',
+ 'magenta' : '',
+ 'yellow' : '',
+ 'white' : ''
+ }
+
+ self.BG_COLOR = {
+ 'black' : '',
+ 'blue' : '',
+ 'green' : '',
+ 'cyan' : '',
+ 'red' : '',
+ 'magenta' : '',
+ 'yellow' : '',
+ 'white' : ''
+ }
- def __init__(self, term_stream=None):
# Curses isn't available on all platforms
try:
import curses
@@ -166,7 +213,7 @@ class YumTerm:
if not hasattr(urlgrabber.progress, 'terminal_width_cached'):
self.columns = curses.tigetnum('cols')
- self.lines = curses.tigetnum('lines')
+ self.lines = curses.tigetnum('lines')
# Look up string capabilities.
for cap_name in self.MODE:
@@ -193,6 +240,9 @@ class YumTerm:
for (color, val) in self.__ansi_colors.items():
self.BG_COLOR[color] = curses.tparm(set_bg_ansi, val) or ''
+ def __init__(self, term_stream=None, color='auto'):
+ self.reinit(term_stream, color)
+
def _tigetstr(self, cap_name):
# String capabilities can include "delays" of the form "$<2>".
# For any modern terminal, we should be able to just ignore
@@ -359,12 +409,24 @@ class YumOutput:
return (u"-", -width)
return (u"", width)
+ def _col_data(self, col_data):
+ assert len(col_data) == 2 or len(col_data) == 3
+ if len(col_data) == 2:
+ (val, width) = col_data
+ hibeg = hiend = ''
+ if len(col_data) == 3:
+ (val, width, highlight) = col_data
+ (hibeg, hiend) = self._highlight(highlight)
+ return (val, width, hibeg, hiend)
+
def fmtColumns(self, columns, msg=u'', end=u''):
""" Return a string for columns of data, which can overflow."""
total_width = len(msg)
data = []
- for (val, width) in columns[:-1]:
+ for col_data in columns[:-1]:
+ (val, width, hibeg, hiend) = self._col_data(col_data)
+
if not width: # Don't count this column, invisible text
msg += u"%s"
data.append(val)
@@ -373,15 +435,18 @@ class YumOutput:
(align, width) = self._fmt_column_align_width(width)
if utf8_width(val) <= width:
msg += u"%s "
- val = utf8_width_fill(val, width, left=(align == u'-'))
+ val = utf8_width_fill(val, width, left=(align == u'-'),
+ prefix=hibeg, suffix=hiend)
+ data.append(val)
else:
- msg += u"%s\n" + " " * (total_width + width + 1)
+ msg += u"%s%s%s\n" + " " * (total_width + width + 1)
+ data.extend([hibeg, val, hiend])
total_width += width
total_width += 1
- data.append(val)
- (val, width) = columns[-1]
+ (val, width, hibeg, hiend) = self._col_data(columns[-1])
(align, width) = self._fmt_column_align_width(width)
- val = utf8_width_fill(val, width, left=(align == u'-'))
+ val = utf8_width_fill(val, width, left=(align == u'-'),
+ prefix=hibeg, suffix=hiend)
msg += u"%%s%s" % end
data.append(val)
return msg % tuple(data)
@@ -392,12 +457,10 @@ class YumOutput:
if columns is None:
columns = (-40, -22, -16) # Old default
- (hibeg, hiend) = self._highlight(highlight)
ver = pkg.printVer()
na = '%s%s.%s' % (indent, pkg.name, pkg.arch)
- columns = zip((na, ver, pkg.repoid), columns)
- columns.insert(1, (hiend, 0))
- columns.insert(0, (hibeg, 0))
+ hi_cols = [highlight, 'normal', 'normal']
+ columns = zip((na, ver, pkg.repoid), columns, hi_cols)
print self.fmtColumns(columns)
def simpleEnvraList(self, pkg, ui_overflow=False,
@@ -407,11 +470,9 @@ class YumOutput:
if columns is None:
columns = (-63, -16) # Old default
- (hibeg, hiend) = self._highlight(highlight)
envra = '%s%s' % (indent, str(pkg))
- columns = zip((envra, pkg.repoid), columns)
- columns.insert(1, (hiend, 0))
- columns.insert(0, (hibeg, 0))
+ hi_cols = [highlight, 'normal', 'normal']
+ columns = zip((envra, pkg.repoid), columns, hi_cols)
print self.fmtColumns(columns)
def fmtKeyValFill(self, key, val):
diff --git a/yum/config.py b/yum/config.py
index cb7e726..b1ad657 100644
--- a/yum/config.py
+++ b/yum/config.py
@@ -668,6 +668,17 @@ class YumConf(StartupConf):
# best == use the 'best arch' for the system
bugtracker_url = Option('http://yum.baseurl.org/report')
+
+ color = SelectionOption('auto', ('auto', 'never', 'always'),
+ mapper={'on' : 'always',
+ 'off' : 'nevern'})
+ color_list_installed_older = Option('bold')
+ color_list_installed_newer = Option('bold,yellow')
+ color_list_installed_extra = Option('bold,red')
+
+ color_list_available_upgrade = Option('bold,blue')
+ color_list_available_downgrade = Option('dim,cyan')
+ color_list_available_install = Option('normal')
_reposlist = []
diff --git a/yum/i18n.py b/yum/i18n.py
index 2d50e74..bcc895e 100755
--- a/yum/i18n.py
+++ b/yum/i18n.py
@@ -241,7 +241,7 @@ def utf8_width_chop(msg, chop=None):
return ret, msg
-def utf8_width_fill(msg, fill, chop=None, left=True):
+def utf8_width_fill(msg, fill, chop=None, left=True, prefix='', suffix=''):
""" Expand a utf8 msg to a specified "width" or chop to same.
Expansion can be left or right. This is what you want to use instead of
%*.*s, as it does the "right" thing with regard to utf-8 sequences.
@@ -260,9 +260,9 @@ def utf8_width_fill(msg, fill, chop=None, left=True):
if width < fill:
extra = " " * (fill - width)
if left:
- msg = ''.join([msg, extra])
+ msg = ''.join([prefix, msg, suffix, extra])
else:
- msg = ''.join([extra, msg])
+ msg = ''.join([extra, prefix, msg, suffix])
if isinstance(passed_msg, unicode):
return to_unicode(msg)
diff --git a/yumcommands.py b/yumcommands.py
index cc6b387..3783292 100644
--- a/yumcommands.py
+++ b/yumcommands.py
@@ -272,15 +272,20 @@ class InfoCommand(YumCommand):
inst_pkgs[key] = pkg
# Output the packages:
+ clio = base.conf.color_list_installed_older
+ clin = base.conf.color_list_installed_newer
+ clie = base.conf.color_list_installed_extra
rip = base.listPkgs(ypl.installed, _('Installed Packages'), basecmd,
highlight_na=update_pkgs, columns=columns,
- highlight_modes={'>' : 'bold',
- '<' : 'bold,yellow',
- 'not in' : 'red,bold'})
+ highlight_modes={'>' : clio, '<' : clin,
+ 'not in' : clie})
+ clau = base.conf.color_list_available_upgrade
+ clad = base.conf.color_list_available_downgrade
+ clai = base.conf.color_list_available_install
rap = base.listPkgs(ypl.available, _('Available Packages'), basecmd,
highlight_na=inst_pkgs, columns=columns,
- highlight_modes={'<' : 'bold,blue',
- '>' : 'cyan,dim'})
+ highlight_modes={'<' : clau, '>' : clad,
+ 'not in' : clai})
rep = base.listPkgs(ypl.extras, _('Extra Packages'), basecmd,
columns=columns)
rup = base.listPkgs(ypl.updates, _('Updated Packages'), basecmd,
More information about the Yum-commits
mailing list