comparison frontends/src/jp/output_std.py @ 2194:322948499db0

jp (output dict): added color and no-header option
author Goffi <goffi@goffi.org>
date Mon, 13 Mar 2017 23:15:06 +0100
parents 9061c7247964
children bf998d8626d9
comparison
equal deleted inserted replaced
2193:33b82250eadd 2194:322948499db0
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 """Standard outputs""" 19 """Standard outputs"""
20 20
21 21
22 from sat_frontends.jp.constants import Const as C 22 from sat_frontends.jp.constants import Const as C
23 from sat.tools.common.ansi import ANSI as A
23 import json 24 import json
24 25
25 __outputs__ = ["Simple", "Json"] 26 __outputs__ = ["Simple", "Json"]
26 SIMPLE = u'simple' 27 SIMPLE = u'simple'
27 JSON = u'json' 28 JSON = u'json'
43 44
44 def list(self, data): 45 def list(self, data):
45 self.host.disp(u'\n'.join(data)) 46 self.host.disp(u'\n'.join(data))
46 47
47 def dict(self, data): 48 def dict(self, data):
48 for k, v in data: 49 options = self.host.parse_output_options()
49 self.host.disp((u'{key}: {value}'.format(key=k, value=v))) 50 self.host.check_output_options({u'no-header'}, options)
51 show_header = not u'no-header' in options
52 for k, v in data.iteritems():
53 if show_header:
54 header = A.color(A.BOLD, A.FG_YELLOW, k) + u': '
55 else:
56 header = u''
57
58 self.host.disp((u'{header}{value}'.format(header=header, value=v)))
50 59
51 60
52 class Json(object): 61 class Json(object):
53 """outputs in json format""" 62 """outputs in json format"""
54 63