Mercurial > libervia-backend
changeset 2296:1a64fd7b648d
jp (standard output): added simple, json and json_raw for OUTPUT_DICT_DICT
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 02 Jul 2017 19:52:21 +0200 |
parents | 31f586d6ab16 |
children | ad2a8e8b52da |
files | frontends/src/jp/output_std.py |
diffstat | 1 files changed, 14 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/frontends/src/jp/output_std.py Sun Jul 02 19:51:00 2017 +0200 +++ b/frontends/src/jp/output_std.py Sun Jul 02 19:52:21 2017 +0200 @@ -38,6 +38,7 @@ host.register_output(C.OUTPUT_LIST, SIMPLE, self.list) host.register_output(C.OUTPUT_DICT, SIMPLE, self.dict) host.register_output(C.OUTPUT_LIST_DICT, SIMPLE, self.list_dict) + host.register_output(C.OUTPUT_DICT_DICT, SIMPLE, self.dict_dict) host.register_output(C.OUTPUT_COMPLEX, SIMPLE, self.simple_print) def simple_print(self, data): @@ -46,17 +47,20 @@ def list(self, data): self.host.disp(u'\n'.join(data)) - def dict(self, data): + def dict(self, data, indent=0, header_color=C.A_HEADER): options = self.host.parse_output_options() self.host.check_output_options({u'no-header'}, options) show_header = not u'no-header' in options for k, v in data.iteritems(): if show_header: - header = A.color(A.BOLD, A.FG_YELLOW, k) + u': ' + header = A.color(header_color, k) + u': ' else: header = u'' - self.host.disp((u'{header}{value}'.format(header=header, value=v))) + self.host.disp((u'{indent}{header}{value}'.format( + indent=indent*u' ', + header=header, + value=v))) def list_dict(self, data): for idx, datum in enumerate(data): @@ -64,6 +68,11 @@ self.host.disp(u'\n') self.dict(datum) + def dict_dict(self, data): + for key, sub_dict in data.iteritems(): + self.host.disp(A.color(C.A_HEADER, key)) + self.dict(sub_dict, indent=4, header_color=C.A_SUBHEADER) + class Json(object): """outputs in json format""" @@ -77,6 +86,8 @@ host.register_output(C.OUTPUT_DICT, JSON_RAW, self.dump) host.register_output(C.OUTPUT_LIST_DICT, JSON, self.dump_pretty) host.register_output(C.OUTPUT_LIST_DICT, JSON_RAW, self.dump) + host.register_output(C.OUTPUT_DICT_DICT, JSON, self.dump_pretty) + host.register_output(C.OUTPUT_DICT_DICT, JSON_RAW, self.dump) host.register_output(C.OUTPUT_COMPLEX, JSON, self.dump_pretty) host.register_output(C.OUTPUT_COMPLEX, JSON_RAW, self.dump)