forked from vain/explain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
241 lines (178 loc) · 7 KB
/
README
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
EXPLAIN.PY(1) Annotate commands EXPLAIN.PY(1)
NAME
explain.py - Annotate commands using ASCII art
SYNOPSIS
explain.py [-w WIDTH] [-c CHARS] [-s CHAR] [-r CHARS] [-j CHAR]
[-P PRESET] [-S] [-u] [-8] [-h]
DESCRIPTION
explain.py allows you to explain commands using ASCII art.
OPTIONS
-w WIDTH
--width WIDTH
Maximum width of output. Defaults to 72.
-c CHARS
--corner CHARS
Characters to use as corners (overrides the preset). The
default is “\- ”.
-s CHAR
--straight CHAR
Character to use as straight lines (overrides the pre‐
set). The default is “|”.
-r CHARS
--range CHARS
Characters to use for ranges (overrides the preset). The
default is “\_/”.
-j CHAR
--joint CHAR
Character to use for joints between lines and ranges
(overrides the preset). The default is “_”.
-P PRESET
--preset PRESET
Use the specified preset list of box-drawing chars. May
be one of “ROUNDED“, “ASCII“, “BOLD“, “UNICODE“, “DOU‐
BLE“ (case insensitive). Defaults to “ASCII“.
-S
--show-characters
Only dump the symbol set and exit. Does not process any
input.
-u
--unicode
Use a preset of unicode glyphs for the graph. This is
equivalent to “-P UNICODE”.
-8
--dont-force-utf-8
Do not enforce UTF-8 as output encoding. Let Python
decide.
-h
--help Show a brief help page.
SYNTAX AND EXAMPLES
A basic example:
vim -p .bashrc .vimrc
--- -- --------------
Open the editor.
Open the files in tabs.
Which files to open?
Result:
vim -p .bashrc .vimrc
\_/ | \____________/
| | |
| | \- Which files to open?
| |
| \- Open the files in tabs.
|
\- Open the editor.
You can use a “+” to end two adjacent ranges. Furthermore, a
“!” will assign a comment to one single character. A more com‐
plex example:
sed 's/hurz/herz/;p;q' < file
--- !-----+-----!!!! ------
Run sed.
Replace ...
... hurz ...
... with herz.
Separator.
Print.
Another separator.
Quit.
Read from this file. The shell will handle the redirection.
Note that a “+” is optional if followed by a “!”.
Result:
sed 's/hurz/herz/;p;q' < file
\_/ |\____/\___/|||| \____/
| | | | |||| |
| | | | |||| \- Read from this file. The shell will handle
| | | | |||| the redirection.
| | | | ||||
| | | | |||\- Quit.
| | | | |||
| | | | ||\- Another separator.
| | | | ||
| | | | |\- Print.
| | | | |
| | | | \- Separator.
| | | |
| | | \- ... with herz.
| | |
| | \- ... hurz ...
| |
| \- Replace ...
|
\- Run sed.
Usually, all adjacent lines of comments will be merged into one
single line. After that, it'll get wrapped to a given length.
This means, that manual line breaks will be lost. On the other
hand, you may want to place manual line breaks. To do so, end a
line with two backslashes:
Number 1
------ -
This is a very long line. There's a lot of text. It'll get wrapped
automatically. Also note that there's line breaks inside of this
comment. They'll be removed. This is the "traditional" way of handling
comments.
1: One! \\
2: Two! \\
3: Three! \\
Now I added '\\' at the ends of those lines.
That line, however, had no '\\' at its end. So, these two lines will
become one single line and get wrapped properly.
And this is what you get:
Number 1
\____/ |
| \- 1: One!
| 2: Two!
| 3: Three!
| Now I added '\\' at the ends of those lines. That line,
| however, had no '\\' at its end. So, these two lines will
| become one single line and get wrapped properly.
|
\- This is a very long line. There's a lot of text. It'll get wrapped
automatically. Also note that there's line breaks inside of this
comment. They'll be removed. This is the "traditional" way of
handling comments.
You can explain several commands in one single source file.
DEVELOPER INFO: TEST CASES
There's a basic test suite available that can be run as fol‐
lows:
$ cd ~/git/explain/tests
$ ./suite.sh
A test case is a short bash(1) script whose filename must end
with .test:
# Complete command line. This is a Bash array.
cmd=("$program" '-j' '+')
# Notes:
# - These here-documents don't have a final newline on the very last
# line. Hence, the "echo" calls in "suite.sh" must NOT add a "-n".
read -rd '' input <<"EOF"
ed .profile
-- --------
Editor.
File to edit.
EOF
read -rd '' expected_output <<"EOF"
ed .profile
| \___+__/
| |
| \- File to edit.
|
\- Editor.
EOF
As you can see, it consists of three variables:
· cmd: The complete command line as a bash(1) array.
· input: The input that is fed to explain.py.
· expected_output: What explain.py must print for the test to
succeed.
Furthermore, there's a file called global_settings.sh. In this
file, $program is defined.
BUGS
Please report bugs at GitHub:
https://github.com/vain/explain/issues.
LICENSE
This is “PIZZA-WARE”, basically. See LICENSE for details.
AUTHORS
For the most up to date list, clone the source repository and
do a git shortlog. As of now, the core was written by Peter
Hofmann ([email protected]), some improvements were made by
tiwo.
SEE ALSO
python2(1), bash(1)
explain.py February 2012 EXPLAIN.PY(1)