comparison sat_frontends/jp/output_xml.py @ 3661:cbb988a6f507

merge bookmark `@`
author Goffi <goffi@goffi.org>
date Wed, 08 Sep 2021 11:20:37 +0200
parents f4c02bdb2d91
children 4b842c1fb686
comparison
equal deleted inserted replaced
3639:05db744f194f 3661:cbb988a6f507
1 #! /usr/bin/env python3 1 #! /usr/bin/env python3
2 2
3 3 # Libervia CLI frontend
4 # jp: a SàT command line tool
5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) 4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
6 5
7 # This program is free software: you can redistribute it and/or modify 6 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by 7 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or 8 # the Free Software Foundation, either version 3 of the License, or
34 except ImportError: 33 except ImportError:
35 pygments = None 34 pygments = None
36 35
37 36
38 __outputs__ = ["XML"] 37 __outputs__ = ["XML"]
39 RAW = "xml_raw"
40 PRETTY = "xml_pretty"
41 38
42 39
43 class XML(object): 40 class XML(object):
44 """Outputs for XML""" 41 """Outputs for XML"""
45 42
46 def __init__(self, host): 43 def __init__(self, host):
47 self.host = host 44 self.host = host
48 host.register_output(C.OUTPUT_XML, PRETTY, self.pretty, default=True) 45 host.register_output(C.OUTPUT_XML, C.OUTPUT_NAME_XML, self.pretty, default=True)
49 host.register_output(C.OUTPUT_LIST_XML, PRETTY, self.pretty_list, default=True) 46 host.register_output(
50 host.register_output(C.OUTPUT_XML, RAW, self.raw) 47 C.OUTPUT_LIST_XML, C.OUTPUT_NAME_XML, self.pretty_list, default=True
51 host.register_output(C.OUTPUT_LIST_XML, RAW, self.list_raw) 48 )
49 host.register_output(C.OUTPUT_XML, C.OUTPUT_NAME_XML_RAW, self.raw)
50 host.register_output(C.OUTPUT_LIST_XML, C.OUTPUT_NAME_XML_RAW, self.list_raw)
52 51
53 def colorize(self, xml): 52 def colorize(self, xml):
54 if pygments is None: 53 if pygments is None:
55 self.host.disp( 54 self.host.disp(
56 _( 55 _(
57 "Pygments is not available, syntax highlighting is not possible. Please install if from http://pygments.org or with pip install pygments" 56 "Pygments is not available, syntax highlighting is not possible. "
57 "Please install if from http://pygments.org or with pip install "
58 "pygments"
58 ), 59 ),
59 error=True, 60 error=True,
60 ) 61 )
61 return xml 62 return xml
62 if not sys.stdout.isatty(): 63 if not sys.stdout.isatty():