forked from aws/aws-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstyle.py
More file actions
149 lines (110 loc) · 3.64 KB
/
style.py
File metadata and controls
149 lines (110 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# Copyright 2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
import textwrap
from six.moves import cStringIO
class BaseStyle(object):
def __init__(self, doc, indent_width=4, **kwargs):
self.doc = doc
self.indent_width = indent_width
self.kwargs = kwargs
self.keep_data = True
def spaces(self, indent):
return ' ' * (indent * self.indent_width)
def start_bold(self, attrs=None):
return ''
def end_bold(self):
return ''
def bold(self, s):
return self.start_bold() + s + self.end_bold()
def h2(self, s):
return self.bold(s)
def h3(self, s):
return self.bold(s)
def start_underline(self, attrs=None):
return ''
def end_underline(self):
return ''
def underline(self, s):
return self.start_underline() + s + self.end_underline()
def start_italics(self, attrs=None):
return ''
def end_italics(self):
return ''
def italics(self, s):
return self.start_italics() + s + self.end_italics()
def start_p(self, attrs=None):
self.doc.add_paragraph()
def end_p(self):
return ''
def start_code(self, attrs=None):
self.doc.do_translation = True
return self.start_bold(attrs)
def end_code(self):
self.doc.do_translation = False
return self.end_bold()
def start_a(self, attrs=None):
self.doc.do_translation = True
return self.start_underline()
def end_a(self):
self.doc.do_translation = False
return self.end_underline()
def start_i(self, attrs=None):
self.doc.do_translation = True
return self.start_italics()
def end_i(self):
self.doc.do_translation = False
return self.end_italics()
def start_li(self, attrs):
return ''
def end_li(self):
return ''
def start_examples(self, attrs):
self.doc.keep_data = False
def end_examples(self):
self.doc.keep_data = True
class CLIStyle(BaseStyle):
def start_bold(self, attrs=None):
if self.kwargs.get('do_ansi', False):
return '\033[1m'
return ''
def end_bold(self):
if self.kwargs.get('do_ansi', False):
return '\033[0m'
return ''
def start_underline(self, attrs=None):
if self.kwargs.get('do_ansi', False):
return '\033[4m'
return ''
def end_underline(self):
if self.kwargs.get('do_ansi', False):
return '\033[0m'
return ''
def start_italics(self, attrs=None):
if self.kwargs.get('do_ansi', False):
return '\033[3m'
return ''
def end_italics(self):
if self.kwargs.get('do_ansi', False):
return '\033[0m'
return ''
def start_li(self, attrs=None):
para = self.doc.add_paragraph()
para.subsequent_indent = para.initial_indent + 1
para.write(' * ')
def h2(self, s):
para = self.doc.get_current_paragraph()
para.lines_before = 1
return self.bold(s)
def end_p(self):
para = self.doc.get_current_paragraph()
para.lines_after = 2