From fa76dcdf76bf138a2080ca6269c2365af9cc9071 Mon Sep 17 00:00:00 2001 From: Johann Dreo Date: Tue, 16 Apr 2013 09:32:08 +0200 Subject: [PATCH] Better g++ theme & localization The g++ theme now check the locale to use unicode quotation mark if necessary. Start of error paragraphs are highlighted in green. Colout now use python3 for a simpler unicode support. --- colout/colout.py | 2 +- colout/colout_g++.py | 35 ++++++++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/colout/colout.py b/colout/colout.py index 2bdcd71..0f7cfc3 100755 --- a/colout/colout.py +++ b/colout/colout.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 #encoding: utf-8 # Color Up Arbitrary Command Ouput diff --git a/colout/colout_g++.py b/colout/colout_g++.py index c31cc1f..b37e504 100644 --- a/colout/colout_g++.py +++ b/colout/colout_g++.py @@ -1,16 +1,28 @@ +#encoding: utf-8 def theme(): - import gettext import os + import gettext + import locale # get g++ version gv = os.popen("g++ -dumpversion").read().strip() # get the current translations of gcc t = gettext.translation("gcc-"+gv) - _ = t.ugettext + _ = t.gettext # _("msg") will return the given message, translated + # if the locale is unicode + enc = locale.getpreferredencoding() + if "UTF" in enc: + # gcc will use unicode quotes + qo = "‘" + qc = "’" + else: + # rather than ascii ones + qo = "'" + qc = "'" return [ [ _("error: "), "red", "bold" ], @@ -18,11 +30,20 @@ def theme(): [ _("note: "), "blue", "bold" ], # [-Wflag] [ "\[-W.*\]", "magenta"], - # Filename:line number - [ "(/.*?)/([^/]+\.)(h|cp*):([0-9]+):*([0-9]*)(.*)", - "white,white,white,yellow,yellow,none", - "normal,bold,bold,bold,normal" ], + + # Highlight message start: + # path file ext : line : col … + [ "(/.*?)/([^/:]+): (In .*)"+qo, + "green", + "normal,normal,bold" ], + + # Highlight locations: + # path file ext : line : col … + [ "(/.*?)/([^/:]+):([0-9]+):*([0-9]*)(.*)", + "none,white,yellow,none,none", + "normal,normal,normal,normal" ], + # source code in single quotes - [ "'(.*?)'", "Cpp", "monokai" ] + [ qo+"(.*?)"+qc, "Cpp", "monokai" ] ]