summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/shdoc/shdoc.sty
blob: 207543365dac09b845d14ce2303991ed1c2ef87a (plain)
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
%%
%% This is file `shdoc.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% shdoc.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% Copyright 2016 Simon M. Laube
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%% http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%% 
%% This work has the LPPL maintenance status `author maintained'.
%% 
%% The Current Maintainer of this work is S. M. Laube
%% 
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{shdoc}[2016/09/04 v2.1b Package for documenting shell operations]
\RequirePackage[dvipsnames]{xcolor}
\RequirePackage{float}
\RequirePackage{caption}
\RequirePackage{mdframed}
\RequirePackage{kvoptions}
\RequirePackage{relsize}
\RequirePackage{stringstrings}
\RequirePackage{ifthen}
\makeatletter

\DeclareStringOption[gray!70]{backgroundcolor}
\DeclareStringOption[green!80!yellow]{usernamecolor}
\DeclareStringOption[green!80!yellow]{machinenamecolor}
\DeclareStringOption[RoyalBlue]{pathcolor}
\DeclareStringOption[RoyalBlue]{indicatorcolor}
\DeclareStringOption[green!80!yellow]{separatorcolor}
\DeclareStringOption[white!60!gray]{optioncolor}
\DeclareStringOption[black]{textcolor}
\DeclareStringOption[\$]{indicatorsymbol}
\DeclareStringOption[\~]{defaultpath}
\DeclareStringOption[@]{separatorsymbol}
\ProcessKeyvalOptions*
\def\shpreset#1{\csname sh@preset@#1\endcsname}%
\def\shpresetdef#1#2{%
\expandafter\gdef\csname sh@preset@#1\endcsname{\shpreset{default} #2}%
}%
\def\shchange#1#2{\expandafter\gdef\csname shdoc@#1\endcsname{#2}}
\let\shchangesymbol\shchange%
\let\shchangecolor\shchange%
\def\sh@preset@default{%
\shchangecolor{backgroundcolor}{gray!70}%
\shchangecolor{usernamecolor}{green!80!yellow}%
\shchangecolor{machinenamecolor}{green!80!yellow}%
\shchangecolor{pathcolor}{RoyalBlue}%
\shchangecolor{indicatorcolor}{RoyalBlue}%
\shchangecolor{separatorcolor}{green!80!yellow}%
\shchangecolor{optioncolor}{white!60!gray}%
\shchangecolor{textcolor}{black}%
\shchangesymbol{indicatorsymbol}{\$}%
\shchangesymbol{defaultpath}{\~}%
\shchangesymbol{separatorsymbol}{@}%
}%
\shpresetdef{mint}{\shpreset{default}}%
\shpresetdef{arrows}{%
\shchangecolor{usernamecolor}{red}%
\shchangecolor{machinenamecolor}{green!80!yellow}%
\shchangecolor{separatorcolor}{white}%
\shchangecolor{indicatorsymbol}{$\gg$}%
\shchangecolor{indicatorcolor}{green!80!yellow}%
\shchangecolor{backgroundcolor}{black}%
\shchangecolor{textcolor}{white}%
\shchangecolor{optioncolor}{gray}%
}%
\shpresetdef{darkblue}{%
\definecolor{shdarkblue}{RGB}{7,75,138}% xcolor syntax
\shchangecolor{backgroundcolor}{shdarkblue}%
\shchangecolor{textcolor}{white}%
\shchangecolor{separatorcolor}{white}%
\shchangecolor{usernamecolor}{orange}%
\shchangecolor{machinenamecolor}{orange}%
\shchangecolor{pathcolor}{green!60!black}%
\shchangecolor{optioncolor}{SkyBlue!80!black}%
}
\shpresetdef{blackwhite}{%
\shchangecolor{backgroundcolor}{gray!30}%
\shchangecolor{textcolor}{black}%
\shchangecolor{separatorcolor}{black}%
\shchangecolor{usernamecolor}{gray}%
\shchangecolor{machinenamecolor}{gray}%
\shchangecolor{pathcolor}{gray!50!black}%
\shchangecolor{optioncolor}{white}%
\shchangecolor{indicatorcolor}{white}%
}
\shpresetdef{airy}{%
\shchangecolor{backgroundcolor}{SkyBlue!15}%
\shchangecolor{usernamecolor}{Emerald}%
\shchangecolor{machinenamecolor}{Emerald}%
\shchangecolor{pathcolor}{orange!70}%
\shchangecolor{indicatorcolor}{orange!70}%
\shchangecolor{separatorcolor}{Emerald}%
\shchangecolor{optioncolor}{Emerald!30}%
}
\newcounter{shlinenumber}% def new counter
\setcounter{shlinenumber}{0}% set counter to 0
\let\@shlistname\relax%
\gdef\shlistname#1{\gdef\@shlistname{#1}}%
\shlistname{List of Terminal Sessions}% set default value
\newfloat{sh}{tbph}{lsh}% define new float
\restylefloat*{sh}%
\floatstyle{plain}% set style

\let\@shfloatname\relax%
\gdef\shfloatname#1{\gdef\@shfloatname{#1}}%
\shfloatname{Terminal~Session}% default float name
\floatname{sh}{\@shfloatname}%

\captionsetup[sh]{position=bottom}%
\def\listofsh{\listof{sh}{\@shlistname}}%
\let\@shuser\relax%
\let\@shmachine\relax%
\def\shuser#1{\gdef\@shuser{#1}}%
\def\shmachine#1{\gdef\@shmachine{#1}}%
\def\@default@shuser{root}%
\def\@default@shmachine{linux}%
\shuser{\@default@shuser}%
\shmachine{\@default@shmachine}%
\def\sh@lnscale{.7}% default number scaling
\def\sh@fontcheck{% if fontsize < 6pt
\ifthenelse{\f@size<6}{%
\gdef\sh@lnscale{1}% factor = 1
}{% elif fontsize < 8pt
\ifthenelse{\f@size<8}{%
\gdef\sh@lnscale{.84}% factor = 0.84
}{% else: nothing
}%
}%
}%
\newlength{\sh@linenumberwidth}%
\long\def\shline#1#2{
\ttfamily\sh@fontcheck\noindent%
\ifnum\value{shlinenumber}<10%
\textcolor{\shdoc@textcolor}{\relscale{\sh@lnscale}0\theshlinenumber}%
\settowidth{\sh@linenumberwidth}{%
\relscale{\sh@lnscale}0\theshlinenumber%
}%
\else%
\textcolor{\shdoc@textcolor}{\relscale{\sh@lnscale}\theshlinenumber}%
\settowidth{\sh@linenumberwidth}{%
\relscale{\sh@lnscale}\theshlinenumber%
}%
\fi\hspace{\sh@linenumberwidth}%
\hangindent=2\sh@linenumberwidth%
\textcolor{\shdoc@usernamecolor}{\@shuser}%
\textcolor{\shdoc@separatorcolor}{\shdoc@separatorsymbol}%
\textcolor{\shdoc@machinenamecolor}{\@shmachine}%
\ \ifx&#1&%
\textcolor{\shdoc@pathcolor}{\shdoc@defaultpath\ }%
\textcolor{\shdoc@indicatorcolor}{\shdoc@indicatorsymbol}
\else%
\textcolor{\shdoc@pathcolor}{#1\ }%
\textcolor{\shdoc@indicatorcolor}{\shdoc@indicatorsymbol}%
\fi\ \textcolor{\shdoc@textcolor}{#2}%
\stepcounter{shlinenumber}\par
}
\newlength{\sh@optionboxwidth}
\long\def\shoutput#1#2{
\ttfamily\sh@fontcheck\noindent%
\ifnum\value{shlinenumber}<10%
\textcolor{\shdoc@textcolor}{\relscale{\sh@lnscale}0\theshlinenumber}%
\settowidth{\sh@linenumberwidth}{%
\relscale{\sh@lnscale}0\theshlinenumber%
}%
\else%
\textcolor{\shdoc@textcolor}{\relscale{\sh@lnscale}\theshlinenumber}%
\settowidth{\sh@linenumberwidth}{%
\relscale{\sh@lnscale}\theshlinenumber%
}%
\fi\hspace{\sh@linenumberwidth}%
\hangindent=2\sh@linenumberwidth%
\ifx&#1&%
\textcolor{\shdoc@textcolor}{#2}\stepcounter{shlinenumber}%
\settowidth{\sh@optionboxwidth}{0cm}%
\else%
\fcolorbox{\shdoc@optioncolor}%
{\shdoc@optioncolor}{\textcolor{\shdoc@textcolor}{[#1]}}\ %
\settowidth{\sh@optionboxwidth}{%
\fcolorbox{\shdoc@optioncolor}%
{\shdoc@optioncolor}{\textcolor{\shdoc@textcolor}{[#1]}}\ }%
\addtolength{\hangindent}{\sh@optionboxwidth}%
\textcolor{\shdoc@textcolor}{#2}\stepcounter{shlinenumber}%
\fi\par%
}
\let\sh@autoformat\relax%
\def\shautoformat#1{\gdef\sh@autoformat{#1}}%
\shautoformat{false}%

\let\sh@autopath\relax%
\def\shautopath#1{\gdef\sh@autopath{#1}}%
\shautopath{false}%
\def\shpath{%
\immediate\write18{pwd >shpath.tmp 2>&1}%
\newread\sh@pathfile%
\openin\sh@pathfile=shpath.tmp%
\endlinechar=-1%
\readline\sh@pathfile to \sh@path%
\sh@path%
\closein\sh@pathfile
}
\def\shread#1#2{%
\newread\sh@inputfile%
\openin\sh@inputfile=#2%

\endlinechar=-1% hide the endlinechar (-1 is invalid, thus not printed)
\begin{shbox}%
\ifthenelse{\equal{#1}{}}{}% empty: do not print
{%
\ifthenelse{\equal{\sh@autopath}{true}}{%
\shline{\shpath}{#1}%
}{%
\ifthenelse{\equal{\sh@autopath}{false}}{}%
{\typeout{-----------------------------------------------}%
\typeout{ Package shdoc info: I don't know what you}%
\typeout{ mean when passing '\sh@autopath' to autopath}%
\typeout{ and I'm going to ignore it and restore the}%
\typeout{default 'false'} %
\typeout{-----------------------------------------------}%
\shautopath{false}}%
\shline{}{#1}%
}%
}
\loop\unless\ifeof\sh@inputfile%
\readline\sh@inputfile to \sh@fileline%
\ifeof\sh@inputfile% again check of eof prevents last blank line
\else%
\shoutput{}{\sh@fileline}%
\fi%
\repeat%
\end{shbox}%
\closein\sh@inputfile%
}
\def\shrun#1{%
\ifthenelse{\equal{\sh@autoformat}{true}}{%
\immediate\write18{#1 >shrun.tmp 2>&1}%
\immediate\write18{./shreformat.sh}%
\shread{#1}{shrun-formatted.tmp}%
}{%
\ifthenelse{\equal{\sh@autoformat}{false}}{}%
{\typeout{-----------------------------------------------}%
\typeout{ Package shdoc info: I don't know what you}%
\typeout{ mean when passing '\sh@autoformat' to autoformat}%
\typeout{ and I'm going to ignore it and restore the}%
\typeout{default 'false'}%
\typeout{-----------------------------------------------}%
\shautoformat{false}}%
\immediate\write18{#1 >shrun.tmp 2>&1}%
\shread{#1}{shrun.tmp}%
}%
}%
\def\shautoread#1#2{%
\newread\sh@inputfile%
\openin\sh@inputfile=#2%
\endlinechar=-1%
\begin{shbox}
\ifthenelse{\equal{#1}{}}{%
}{%
\ifthenelse{\equal{\sh@autopath}{true}}{%
\shline{\shpath}{#1}%
}{%
\ifthenelse{\equal{\sh@autopath}{false}}{}%
{\typeout{-----------------------------------------------}%
\typeout{ Package shdoc info: I don't know what you}%
\typeout{ mean when passing '\sh@autopath' to autopath}%
\typeout{ and I'm going to ignore it and restore the}%
\typeout{default 'false'}%
\typeout{-----------------------------------------------}%
\shautopath{false}}%
\shline{}{#1}%
}%
}%
\loop\unless\ifeof\sh@inputfile%
\readline\sh@inputfile to \sh@fileline%
\ifeof\sh@inputfile%
\else%
\getnextword[e]{\sh@fileline}%
\findchars[q]{\thestring}{-}%
\ifthenelse{\equal{\theresult}{1}}{%
\shoutput{\thestring}%
{\stringlength[e]{\thestring}\gobblechars[v]{\sh@fileline}{\theresult}}%
}{%
\shoutput{}{\sh@fileline}%
}%
\fi%
\repeat%
\end{shbox}%
\closein\sh@inputfile%
}%
\def\shautorun#1{
\ifthenelse{\equal{\sh@autoformat}{true}}{%
\immediate\write18{#1 >shrun.tmp 2>&1}%
\immediate\write18{./shreformat.sh}%
\shautoread{#1}{shrun-formatted.tmp}%
}{%
\ifthenelse{\equal{\sh@autoformat}{false}}{}%
{\typeout{-----------------------------------------------}%
\typeout{ Package shdoc info: I don't know what you}%
\typeout{ mean when passing '\sh@autoformat' to autoformat}%
\typeout{ and I'm going to ignore it and restore the}%
\typeout{default 'false'}%
\typeout{-----------------------------------------------}%
\shautoformat{false}}%
\immediate\write18{#1 >shrun.tmp 2>&1}%
\shautoread{#1}{shrun.tmp}%
}%
}
\def\shclearfiles{
\immediate\write18{rm shrun.tmp; rm shrun-formatted.tmp; rm shpath.tmp}
}
\newmdenv[linecolor=white,backgroundcolor=\shdoc@backgroundcolor,
settings=\setcounter{shlinenumber}{1}]{shbox}
\makeatother

\endinput
%%
%% End of file `shdoc.sty'.