summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/termsim/termsim.dtx
blob: 856192470a539aaa1d88580325c545dcd8d880bb (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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
% \iffalse meta-comment
% !TEX program  = XeLaTeX
%<*internal>
\iffalse
%</internal>
%<*readme>
Terminal simulation based on tcolorbox and minted/listings
=======

`termsim` is a LaTeX package developed based on tcolorbox and minted/listings, which provides a environment `terminal`(`terminal*`) and a macro `\termfile`(`\termfile*`) to simulate Win10, Ubuntu and Mac terminal.

The `terminal`(`terminal*`) evironment create a tcolorbox to simulate terminal with the eviroment body and the `\termfile`(`\termfile*`) macro from a source file.

The OS type was selected from win10, mac and ubuntu and
the terminal theme was selected from dark and light with key-value option.

All options can be set with `\termset` macro or `terminal`(`terminal*`) eniroment's and
`\termfile`(`\termfile*`) macro's option

You can read the manual (in Chinese) for more details and examples.

Contributing
------------

1. github repository:
    1. repository: [termsim](https://github.com/registor/termsim)
    2. Issues and pull requests are welcome. [issue](https://github.com/registor/termsim/issues) or [pull request](https://github.com/registor/termsim/pulls).

2. gitee repository:
    1. repository: [termsim](https://gitee.com/nwafu_nan/termsim)
    2. Issues and pull requests are welcome. [issue](https://gitee.com/nwafu_nan/termsim/issues) or [pull request](https://gitee.com/nwafu_nan/termsim/pulls).

基于tcolorbox的终端模拟宏包
=======

`termsim`是一个基于tcolorbox的用LaTeX3开发的终端模拟LaTeX宏包,它提供了用于模拟终端窗口的`terminal`(`terminal*`)环境和`\termfile`(`\termfile*`)命令,以模拟Win10、Ubuntu或Mac的终端窗口。

`terminal`(`terminal*`)环境根据环境内容创建一个`tcolorbox`盒子用于模拟终端窗口,
`\termfile`(`\termfile*`)命令根据载入的文件内容创建一个`tcolorbox`盒子用于模拟终端窗口。

可以通过`terminal`(`terminal*`)环境或`\termfile`(`\termfile*`)命令的`key-value`选项设置操作系统类型(win10、mac或ubuntu),

所有选项即可以通过环境或命令选项设置,也可以通过`\termset`命令进行设置。

可以通过阅读宏包手册(中文)以也解该宏包更多的使用细节和使用样例。

###  参与贡献
---------------------

1. github仓库:
    (1). 仓库地址: [termsim](https://github.com/registor/termsim)
    (2). Issues和PR: [issue](https://github.com/registor/termsim/issues) or [pull request](https://github.com/registor/termsim/pulls).

2. gitee仓库:
    (1). 仓库地址: [termsim-l3](https://gitee.com/nwafu_nan/termsim)
    (2). Issues and PR: [issue](https://gitee.com/nwafu_nan/termsim/issues) or [pull request](https://gitee.com/nwafu_nan/termsim/pulls).

Copyright and Licence
---------------------

    Copyright (C) 2020-2021 by Nan Geng <nangeng@nwafu.edu.cn>
    ----------------------------------------------------------------------

    This work may be distributed and/or modified under the
    conditions of the LaTeX Project Public License, either
    version 1.3c of this license or (at your option) any later
    version. This version of this license is in
       http://www.latex-project.org/lppl/lppl-1-3c.txt
    and the latest version of this license is in
       http://www.latex-project.org/lppl.tx        \IfBooleanTF{#1}
          {
            \bool_set_true:N  \l_@@_comment_bool
          }{
t
    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 "maintained".

    The Current Maintainer of this work is Nan Geng.

    This package consists of the file  termsim.dtx,
                 and the derived files termsim.sty,
                                       termsim.pdf,
                                       termsim.ins,
                                       README.md (this file).

%</readme>
%<*internal>
\fi
\begingroup
  \def\temp{LaTeX2e}
\expandafter\endgroup\ifx\temp\fmtname\else
\csname fi\endcsname
%</internal>
%<*install>

\input ctxdocstrip %

\let\MetaPrefix\relax

\preamble

    Copyright (C) 2020-2021 by Nan Geng <nangeng@nwafu.edu.cn>
--------------------------------------------------------------------------

    This work may be distributed and/or modified under the
    conditions of the LaTeX Project Public License, either
    version 1.3c of this license or (at your option) any later
    version. This version of this license is in
       http://www.latex-project.org/lppl/lppl-1-3c.txt
    and 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 "maintained".

    The Current Maintainer of this work is Nan Geng.

--------------------------------------------------------------------------

\endpreamble

\postamble

    This package consists of the file  termsim.dtx,
                 and the derived files termsim.sty,
                                       termsim.pdf,
                                       termsim.ins,
                                       README.md.
\endpostamble

\declarepostamble\emptypostamble
\endpostamble

\def\MetaPrefix{-- }


\let\MetaPrefix\DoubleperCent

\generate
  {
%</install>
%<*internal>
    \usedir{source/xelatex/termsim}
    \file{termsim.ins} {\from{\jobname.dtx}{install}}
%</internal>
%<*install>
    \usedir{xetex/xelatex/termsim}
    \file{termsim.sty} {\from{\jobname.dtx}{package}}
    \nopreamble\nopostamble
    \usedir{doc/xelatex/termsim}
    \file{README.md}   {\from{\jobname.dtx}{readme}}
  }

\endbatchfile
%</install>
%<*internal>
\fi
%</internal>
%<package>\NeedsTeXFormat{LaTeX2e}[2020/10/01]
%<package>\RequirePackage{expl3}
%<+package>\GetIdInfo$Id: termsim.dtx 1.0.0 2021-12-14 08:00:00 +0800 Nan Geng <nangeng@nwafu.edu.cn> $
%<package>  {Terminal simulation with tcolorbox and minted/listings.}
%<package>\ProvidesExplPackage{\ExplFileName}
%<package>  {\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription}
%<*driver>
\documentclass{ctxdoc}
\usepackage{minted}
\usepackage{listings}
\usepackage{xcolor}
\usepackage{xcolor-material}
\usepackage{termsim}
\renewcommand*\marg[1]{\{\meta{#1}\}}
\renewcommand*\oarg[1]{[\meta{#1}]}
\renewcommand*\parg[1]{(\meta{#1})}
\NewDocumentCommand{\init}{+v}{\hspace{\fill}初始值~=~\textcolor{blue}{\bfseries#1}}
\DeclareDocumentCommand\opt{m}{\texttt{#1}}
\DeclareDocumentCommand\kvopt{mm}
  {\texttt{#1\breakablethinspace=\breakablethinspace#2}}
\def\breakablethinspace{\hskip 0.16667em\relax}
\begin{document}
%<!--CODEDOC-->  \DisableImplementation
  \EnableImplementation
  \DocInput{\jobname.dtx}
  \IndexLayout
  \PrintChanges
  \PrintIndex
\end{document}
%</driver>
% \fi
%
% \changes{v1.0.0}{2021/12/14}{开始编写模板}
%
% \CheckSum{376}
% \GetFileId{termsim.sty}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
%
% \title{\bfseries\pkg{termsim}:终端窗口模拟宏包\\\bfseries\pkg{termsim}:terminal simulation pachage}
% \author{耿楠\\ \path{nangeng@nwafu.edu.cn}}
% \date{\filedate\qquad\fileversion\thanks{\url{https://github.com/registor/termsim}}\thanks{\url{https://gitee.com/nwafu_nan/termsim}}}
% \maketitle
%
% \begin{documentation}
%
% \begin{abstract}
%
% \pkg{termsim} 是一个基于\pkg{tcolorbox}宏包,用\LaTeX3 开发的 \LaTeX 宏包,
% 它提供了用于模拟Win10、Ubuntu和Mac的终端窗口的\env{terminal}环境和\tn{termfile}命令,
% \env{terminal}环境将环境中的内容在模拟的终端窗口中输出,
% 而\tn{termfile}命令用于将指定的文件读入后在模拟的终端窗口中输出。
% 同时提供了\env{terminal*}环境和\tn{termfile*}命令,用于模拟带底线注释的终端窗口。
% 操作系统类型和终端窗口颜色主题等样式,
% 可以通过\tn{termset}命令或\env{terminal}(\env{terminal*})环境和
% \tn{termfile}(\tn{termfile*})命令的可选项进行设置。
%
% \end{abstract}
%
% \tableofcontents
%
% \section{简要说明}
%
% \pkg{termsim} 是一个用于模拟Win10、Ubuntu和Mac终端窗口的\LaTeX{}宏包,
% 用于实现对Win10、Mac或Ubuntu终端窗口的模拟排版。
%
% \section{用户接口}
%
% \subsection{\env{terminal}和\env{terminal*}环境}
%
% \begin{function}[added=2021-12-17,updated=2021-12-17]{terminal,terminal*}
%   \begin{syntax}
%     \tn{begin}\{terminal\} \oarg{外观选项} \Arg{窗口标题}
%     .....
%     \tn{end}\{terminal\}
%
%     \tn{begin}\{terminal*\} \oarg{外观选项} \oarg{底线注释} \Arg{窗口标题}
%     .....
%     \tn{end}\{terminal*\}
%   \end{syntax}
%
%   排版终端窗口,内容来自于由环境内容,
%   可以通过\Arg{窗口标题}为窗口设置标题。
%
%   \oarg{外观选项}中通过key-value方式设置终端窗口的外观。
%
%   星号环境\texttt{terminal*}用于为终端窗口添加底线注释,
%   注意此时需要在\oarg{外观选项}后提供\oarg{底线注释}内容。
%
%   终端窗口的外观也可以通过\tn{termset}命令的逗号分隔
%   key-value列表进行设置。
%
% \end{function}
%   \begin{Verbatim}[frame=none,numbers=left,gobble=5]
%     \centering
%     \termset{os=win10,theme=dark,shstretch=1.0}
%     \begin{terminal}{窗口标题}
%       C:\Users\Administrator 的目录
%       2018/07/21  15:39    <DIR>          .
%       2018/07/21  15:39    <DIR>          ..
%       2018/07/13  08:35    <DIR>          3D Objects
%       2018/07/13  08:35    <DIR>          Contacts
%       2018/08/06  07:46    <DIR>          Desktop
%                       2 个文件      6,029,312 字节
%                      18 个目录 14,035,107,840 可用字节
%     \end{terminal}
%   \end{Verbatim}
%
%\begin{center}
%\begin{minipage}{0.75\textwidth}
%\termset{os=win10,theme=dark,shstretch=1.0}
%\begin{terminal}{窗口标题}
%C:\Users\Administrator 的目录
%2018/07/21  15:39    <DIR>          .
%2018/07/21  15:39    <DIR>          ..
%2018/07/13  08:35    <DIR>          3D Objects
%2018/07/13  08:35    <DIR>          Contacts
%2018/08/06  07:46    <DIR>          Desktop
%                2 个文件      6,029,312 字节
%               18 个目录 14,035,107,840 可用字节
%\end{terminal}
%\end{minipage}
%\end{center}
%
% \subsection{\tn{termfile}和\tn{termfile*}命令}
%
% \begin{function}[added=2021-12-18,updated=2021-12-18]{\termfile,\termfile*}
%   \begin{syntax}
%     \tn{termfile}  \oarg{外观选项} \Arg{窗口标题} \Arg{内容文件}
%     \tn{termfile*} \oarg{外观选项} \oarg{底线注释} \Arg{窗口标题} \Arg{内容文件}
%   \end{syntax}
%
%   排版终端窗口,内容来自于由\Arg{内容文件},
%   可以通过\Arg{窗口标题}为窗口设置标题。
%
%   \oarg{外观选项}中通过key-value方式设置终端窗口的外观。
%
%   星号命令\tn{termfile*}用于为终端窗口添加底线注释,
%   注意此时需要在\oarg{外观选项}后提供\oarg{底线注释}内容。
%
%   排版样式也可以通过\tn{termset}命令的逗号分隔的
%   key-value列表进行设置。
% \end{function}
%
% \newpage
%
%   \begin{Verbatim}[frame=none,numbers=left,gobble=5]
%     \centering
%     \termfile{窗口标题}{test.bat}
%   \end{Verbatim}
%
%\begin{center}
%\begin{minipage}{0.75\textwidth}
%\termfile{窗口标题}{test.bat}
%\end{minipage}
%\end{center}
%
%\subsection{\tn{termset}命令}
%
% \begin{function}[added=2021-12-18,updated=2021-12-18]{\termset}
%   \begin{syntax}
%     \tn{termset} \marg{键值列表}
%   \end{syntax}
%   \tn{termset} 的参数是一组由(英文)逗号分隔的选项列表,
%   列表中的选项采用 \kvopt{\meta{key}}{\meta{value}} 形式。
%   部分选项的\meta{value} 可以省略。
%   对于同一选项,后续设置会覆盖以前的设置。
%
%   多数选项都设有默认值。
%
%   \tn{termset} 采用 \LaTeX3 风格的键值设置,支持不同类型以及多种
%   层次的选项设定。键值列表中,“|=|”左右的空格不影响设置;但需注意,
%   参数列表中\textbf{不可以出现空行}。
%
%   布尔型的参数 \kvopt{\meta{选项}}{true} 中的“|= true|”可以省略。
% \end{function}
%
% \section{选项说明}
%
%   \pkg{termsim}宏包提供了一系列选项,以设置终端窗口外观样式。
%   载入\pkg{termsim}宏包后,以下选项均可通过用户接口命令\tn{termset}进行设置。
%   同时,这些选项也可以通过\env{terminal}(\env{terminal*})环境或
%   \tn{termfile}(\tn{termfile*})命令的\oarg{外观选项}进行设置。
%
% \subsection{代码引擎}
%
% \begin{function}[added=2021-12-18,updated=2021-12-18]{minted}
%   \begin{syntax}
%     minted = <\TTF> \init{true}
%   \end{syntax}
%   \opt{minted} 用于设置代码排版引擎,如为\textbf{true}则使用\pkg{minted}宏包
%   排版终端窗口中的内容,如为\textbf{false}则使用\pkg{listings}宏包排版
%   终端窗口中的内容。默认值为\textbf{true}。
% \end{function}
%
% \subsection{操作系统}
%
% \begin{function}[added=2021-12-18,updated=2021-12-18]{os}
%   \begin{syntax}
%     os =  <win10|mac|ubuntu> \init{win10}
%   \end{syntax}
%   \opt{os} 用于设置终端窗口的操作系统类型,默认值为\textbf{win10}。
% \end{function}
%
% \subsection{颜色主题}
%
% \begin{function}[added=2021-12-18,updated=2021-12-18]{theme}
%   \begin{syntax}
%     theme =  <dark|light|white> \init{dark}
%   \end{syntax}
%   \opt{theme} 用于设置终端窗口的颜色主题,默认值为\textbf{dark}。
% \end{function}
%
% \subsection{代码样式}
%
% \begin{function}[added=2021-12-18,updated=2021-12-18]{shstyle}
%   \begin{syntax}
%     shstyle = \Arg{代码样式} \init{bw}
%   \end{syntax}
%   \opt{shstyle} 用于设置终端窗口内容(代码)的样式,仅对\textbf{minted}
%   引擎有效,默认值为\textbf{bw}。
% \end{function}
%
% \subsection{代码字号}
%
% \begin{function}[added=2021-12-18,updated=2021-12-18]{shsize}
%   \begin{syntax}
%     shsize = \Arg{字号命令} \init{\small}
%   \end{syntax}
%   \opt{shsize} 用于设置终端窗口内容(代码)的字号,仅对\textbf{minted}
%   引擎有效,默认值为\textbf{\tn{small}}。
% \end{function}
%
% \subsection{底线注释格式}
%
% \begin{function}[added=2021-12-18,updated=2021-12-18]{commentf}
%   \begin{syntax}
%     commentf = \Arg{格式命令组} \init{\small\sffamily}
%   \end{syntax}
%   \opt{commentf} 用于设置终端窗口底线注释的格式,
%   默认值为\textbf{\tn{small}\tn{sffamily}}。
% \end{function}
%
% \subsection{代码行距}
%
% \begin{function}[added=2021-12-18,updated=2021-12-18]{shstretch}
%   \begin{syntax}
%     shstretch = \Arg{浮点数} \init{1.0}
%   \end{syntax}
%   \opt{shstretch} 用于设置终端窗口内容(代码)的行距,仅对\textbf{minted}
%   引擎有效,取浮点数。默认值为\textbf{1.0}。
% \end{function}
%
% \newpage
%
% \section{排版样例}
%
% \pkg{termsim}宏包可用于需要排版操作系统终端窗口的场合,
% 以避免使用截图。终端窗口可以带/不带底线注释,也可以
% 是暗色(dark)、亮色(light)或白色(white)颜色主题。
%
% \subsection{Win10终端窗口}
%
% \subsubsection{\env{terminal}/\env{terminal*}环境}
%
%   \begin{Verbatim}[frame=none,numbers=left,gobble=5]
%     \centering
%     \termset{os=win10,theme=dark,shstretch=1.0}
%     \begin{terminal}{窗口标题}
%       C:\Users\Administrator 的目录
%       2018/07/21  15:39    <DIR>          .
%       2018/07/21  15:39    <DIR>          ..
%       2018/07/13  08:35    <DIR>          3D Objects
%       2018/07/13  08:35    <DIR>          Contacts
%       2018/08/06  07:46    <DIR>          Desktop
%                       2 个文件      6,029,312 字节
%                      18 个目录 14,035,107,840 可用字节
%     \end{terminal}
%   \end{Verbatim}
%
%\begin{center}
%\begin{minipage}{0.75\textwidth}
%\termset{os=win10,theme=dark,shstretch=1.0}
%\begin{terminal}{窗口标题}
%C:\Users\Administrator 的目录
%2018/07/21  15:39    <DIR>          .
%2018/07/21  15:39    <DIR>          ..
%2018/07/13  08:35    <DIR>          3D Objects
%2018/07/13  08:35    <DIR>          Contacts
%2018/08/06  07:46    <DIR>          Desktop
%                2 个文件      6,029,312 字节
%               18 个目录 14,035,107,840 可用字节
%\end{terminal}
%\end{minipage}
%\end{center}
%
%   \begin{Verbatim}[frame=none,numbers=left,gobble=5]
%     \centering
%     \begin{terminal*}[os=win10,theme=light][底线注释]{窗口标题}
%       C:\Users\Administrator 的目录
%       2018/07/21  15:39    <DIR>          .
%       2018/07/21  15:39    <DIR>          ..
%       2018/07/13  08:35    <DIR>          3D Objects
%       2018/07/13  08:35    <DIR>          Contacts
%       2018/08/06  07:46    <DIR>          Desktop
%                       2 个文件      6,029,312 字节
%                      18 个目录 14,035,107,840 可用字节
%     \end{terminal*}
%   \end{Verbatim}
%
%\begin{center}
%\begin{minipage}{0.75\textwidth}
%\begin{terminal*}[os=win10,theme=light][底线注释]{窗口标题}
%C:\Users\Administrator 的目录
%2018/07/21  15:39    <DIR>          .
%2018/07/21  15:39    <DIR>          ..
%2018/07/13  08:35    <DIR>          3D Objects
%2018/07/13  08:35    <DIR>          Contacts
%2018/08/06  07:46    <DIR>          Desktop
%                2 个文件      6,029,312 字节
%               18 个目录 14,035,107,840 可用字节
%\end{terminal*}
%\end{minipage}
%\end{center}
%
%
% \subsubsection{\tn{termfile}/\tn{termfile*}命令}
%
%   \begin{Verbatim}[frame=none,numbers=left]
%     \centering
%     \termset{os=win10,theme=dark}
%     \termfile{窗口标题}{test.bat}
%   \end{Verbatim}
%
%\begin{center}
%\begin{minipage}{0.75\textwidth}
%\termset{os=win10,theme=dark}
%\termfile{窗口标题}{test.bat}
%\end{minipage}
%\end{center}
%
%   \begin{Verbatim}[frame=none,numbers=left]
%     \centering
%     \termfile*[os=win10,theme=light][底线注释]{窗口标题}{test.bat}
%   \end{Verbatim}
%
%\begin{center}
%\begin{minipage}{0.75\textwidth}
%\termfile*[os=win10,theme=light][底线注释]{窗口标题}{test.bat}
%\end{minipage}
%\end{center}
%
% \newpage
% \subsection{Mac终端窗口}
%
% \subsubsection{\env{terminal}/\env{terminal*}环境}
%
%   \begin{Verbatim}[frame=none,numbers=left,gobble=5]
%     \centering
%     \termset{os=mac,theme=dark}
%     \begin{terminal}{窗口标题}
%       xxxxxx@xxxxxx-lap:~$ ls
%       Desktop     Downloads   p2         Public   Templates   Videos
%       Documents   Music       Pictures   snap    '#test#'     workspace
%       xxxxxx@xxxxxx-lap:~$
%     \end{terminal}
%   \end{Verbatim}
%
%\begin{center}
%\begin{minipage}{0.75\textwidth}
%\termset{os=mac,theme=dark}
%\begin{terminal}{窗口标题}
%xxxxxx@xxxxxx-lap:~$ ls
%Desktop     Downloads   p2         Public   Templates   Videos
%Documents   Music       Pictures   snap    '#test#'     workspace
%xxxxxx@xxxxxx-lap:~$
%\end{terminal}
%\end{minipage}
%\end{center}
%
%   \begin{Verbatim}[frame=none,numbers=left,gobble=5]
%     \centering
%     \begin{terminal*}[os=mac,theme=light][底线注释]{窗口标题}
%       xxxxxx@xxxxxx-lap:~$ ls
%       Desktop     Downloads   p2         Public   Templates   Videos
%       Documents   Music       Pictures   snap    '#test#'     workspace
%       xxxxxx@xxxxxx-lap:~$
%     \end{terminal*}
%   \end{Verbatim}
%
%\begin{center}
%\begin{minipage}{0.75\textwidth}
%\begin{terminal*}[os=mac,theme=light][底线注释]{窗口标题}
%xxxxxx@xxxxxx-lap:~$ ls
%Desktop     Downloads   p2         Public   Templates   Videos
%Documents   Music       Pictures   snap    '#test#'     workspace
%xxxxxx@xxxxxx-lap:~$
%\end{terminal*}
%\end{minipage}
%\end{center}
%
% \subsubsection{\tn{termfile}/\tn{termfile*}命令}
%
%   \begin{Verbatim}[frame=none,numbers=left]
%     \centering
%     \termset{os=mac,theme=dark}
%     \termfile{窗口标题}{testls}
%   \end{Verbatim}
%
%\begin{center}
%\begin{minipage}{0.75\textwidth}
%\termset{os=mac,theme=dark}
%\termfile{窗口标题}{testls}
%\end{minipage}
%\end{center}
% \newpage
%   \begin{Verbatim}[frame=none,numbers=left]
%     \centering
%     \termfile*[os=mac,theme=light][底线注释]{窗口标题}{testls}
%   \end{Verbatim}
%
%\begin{center}
%\begin{minipage}{0.75\textwidth}
%\termfile*[os=mac,theme=light][底线注释]{窗口标题}{testls}
%\end{minipage}
%\end{center}
%
% \subsection{Ubuntu终端窗口}
%
% \subsubsection{\env{terminal}/\env{terminal*}环境}
%
%   \begin{Verbatim}[frame=none,numbers=left,gobble=5]
%     \centering
%     \termset{os=ubuntu,theme=dark}
%     \begin{terminal}{窗口标题}
%       xxxxxx@xxxxxx-lap:~/Desktop $
%       git clone git@gitee.com:xxxxxx/xxxxxx
%       正克隆到 'xxxxxx'...
%       remote: Enumerating objects: 106, done.
%       remote: Counting objects: 100% (106/106), done.
%       remote: Compressing objects: 100% (105/105), done.
%       remote: Total 106 (delta 9), reused 0 (delta 0)
%       接收对象中: 100% (106/106), 237.88 MiB | 730.00 KiB/s,
%       完成.
%       处理 delta 中: 100% (9/9), 完成.
%       正在检出文件: 100% (75/75), 完成.
%       xxxxxx@xxxxxx-lap:~/Desktop $
%     \end{terminal}
%   \end{Verbatim}
%
%\begin{center}
%\begin{minipage}{0.75\textwidth}
%\termset{os=ubuntu,theme=dark}
%\begin{terminal}{窗口标题}
%xxxxxx@xxxxxx-lap:~/Desktop $
%git clone git@gitee.com:xxxxxx/xxxxxx
%正克隆到 'xxxxxx'...
%remote: Enumerating objects: 106, done.
%remote: Counting objects: 100% (106/106), done.
%remote: Compressing objects: 100% (105/105), done.
%remote: Total 106 (delta 9), reused 0 (delta 0)
%接收对象中: 100% (106/106), 237.88 MiB | 730.00 KiB/s,
%完成.
%处理 delta 中: 100% (9/9), 完成.
%正在检出文件: 100% (75/75), 完成.
%xxxxxx@xxxxxx-lap:~/Desktop $
%\end{terminal}
%\end{minipage}
%\end{center}
%
%   \begin{Verbatim}[frame=none,numbers=left,gobble=5]
%     \centering
%     \begin{terminal*}[os=ubuntu,theme=light][底线注释]{窗口标题}
%       xxxxxx@xxxxxx-lap:~/Desktop $
%       git clone git@gitee.com:xxxxxx/xxxxxx
%       正克隆到 'xxxxxx'...
%       remote: Enumerating objects: 106, done.
%       remote: Counting objects: 100% (106/106), done.
%       remote: Compressing objects: 100% (105/105), done.
%       remote: Total 106 (delta 9), reused 0 (delta 0)
%       接收对象中: 100% (106/106), 237.88 MiB | 730.00 KiB/s,
%       完成.
%       处理 delta 中: 100% (9/9), 完成.
%       正在检出文件: 100% (75/75), 完成.
%       xxxxxx@xxxxxx-lap:~/Desktop $
%     \end{terminal*}
%   \end{Verbatim}
%
%\begin{center}
%\begin{minipage}{0.75\textwidth}
%\begin{terminal*}[os=ubuntu,theme=light][底线注释]{窗口标题}
%xxxxxx@xxxxxx-lap:~/Desktop $
%git clone git@gitee.com:xxxxxx/xxxxxx
%正克隆到 'xxxxxx'...
%remote: Enumerating objects: 106, done.
%remote: Counting objects: 100% (106/106), done.
%remote: Compressing objects: 100% (105/105), done.
%remote: Total 106 (delta 9), reused 0 (delta 0)
%接收对象中: 100% (106/106), 237.88 MiB | 730.00 KiB/s,
%完成.
%处理 delta 中: 100% (9/9), 完成.
%正在检出文件: 100% (75/75), 完成.
%xxxxxx@xxxxxx-lap:~/Desktop $
%\end{terminal*}
%\end{minipage}
%\end{center}
%
% \subsubsection{\tn{termfile}/\tn{termfile*}命令}
%
%   \begin{Verbatim}[frame=none,numbers=left]
%     \centering
%     \termset{os=ubuntu,theme=dark}
%     \termfile{窗口标题}{testsh}
%   \end{Verbatim}
%
%\begin{center}
%\begin{minipage}{0.75\textwidth}
%\termset{os=ubuntu,theme=dark}
%\termfile{窗口标题}{testsh}
%\end{minipage}
%\end{center}
%
%   \begin{Verbatim}[frame=none,numbers=left]
%     \centering
%     \termfile*[os=ubuntu,theme=light][底线注释]{窗口标题}{testsh}
%   \end{Verbatim}
%
%\begin{center}
%\begin{minipage}{0.75\textwidth}
%\termfile*[os=ubuntu,theme=light][底线注释]{窗口标题}{testsh}
%\end{minipage}
%\end{center}
%
%  也可以使用\texttt{white}颜色主题,使用白底黑字排版,以便
%  打印输出。
%
%   \begin{Verbatim}[frame=none,numbers=left,gobble=5]
%     \centering
%     \termset{os=ubuntu,theme=white}
%     \begin{terminal}{窗口标题}
%       xxxxxx@xxxxxx-lap:~/Desktop $
%       git clone git@gitee.com:xxxxxx/xxxxxx
%       正克隆到 'xxxxxx'...
%       remote: Enumerating objects: 106, done.
%       remote: Counting objects: 100% (106/106), done.
%       remote: Compressing objects: 100% (105/105), done.
%       remote: Total 106 (delta 9), reused 0 (delta 0)
%       接收对象中: 100% (106/106), 237.88 MiB | 730.00 KiB/s,
%       完成.
%       处理 delta 中: 100% (9/9), 完成.
%       正在检出文件: 100% (75/75), 完成.
%       xxxxxx@xxxxxx-lap:~/Desktop $
%     \end{terminal}
%   \end{Verbatim}
%
%\begin{center}
%\begin{minipage}{0.75\textwidth}
%\termset{os=ubuntu,theme=white}
%\begin{terminal}{窗口标题}
%xxxxxx@xxxxxx-lap:~/Desktop $
%git clone git@gitee.com:xxxxxx/xxxxxx
%正克隆到 'xxxxxx'...
%remote: Enumerating objects: 106, done.
%remote: Counting objects: 100% (106/106), done.
%remote: Compressing objects: 100% (105/105), done.
%remote: Total 106 (delta 9), reused 0 (delta 0)
%接收对象中: 100% (106/106), 237.88 MiB | 730.00 KiB/s,
%完成.
%处理 delta 中: 100% (9/9), 完成.
%正在检出文件: 100% (75/75), 完成.
%xxxxxx@xxxxxx-lap:~/Desktop $
%\end{terminal}
%\end{minipage}
%\end{center}
%
% \end{documentation}
%
% \StopEventually{}
%
% \begin{implementation}
%
% \section{代码实现}
%
% 该宏包使用 \LaTeX3 语法编写,依赖 \pkg{expl3} 环境,
% 并需调用 \pkg{l3packages}、\pkg{tcolorbox}、\pkg{minted}
% \pkg{listings}、\pkg{fontawesome5}等宏包。
%
% 按照 \LaTeX3 语法,代码中的空格、换行、回车与制表符会完全被忽略,
% 而下划线“|_|”和冒号“|:|”则可作为一般字母使用。
% 正常的空格可以使用“|~|”代替;至于 |~| 原来所表示的“带子”,
% 则要用 \LaTeXe{} 的原始命令 \tn{nobreakspace} 代替。
%
% 以下代码中有一些形如 \textcolor[HTML]{2E3191}{\textsf{<*package>}}
% 的标记,这是 \pkg{DocStrip} 中的“guard”,用来选择性地提取文件。
% “\textsf{*}”和“\textsf{/}”分别表示该部分的开始和结束。不含
% “\textsf{*}”和“\textsf{/}”的 guard 出现在行号右侧,它们用来确定
% 单独一行代码的归属。这些 guard 的颜色深浅不一,用以明确嵌套关系。
%
% 另有若干形如 \textcolor[HTML]{AD1457}{\textsf{<@@=termsim>}} 的 guard,
% 它们由 \pkg{l3docstrip} 定义,用来标识名字空间(模块)。
%
% \subsection{环境检测与准备}
%
%    \begin{macrocode}
%<*package>
%<@@=termsim>
%    \end{macrocode}
%
% \subsection{载入宏包}
%
% 载入必要的宏包
%
%    \begin{macrocode}
\RequirePackage { xtemplate, l3keys2e, xparse }
%    \end{macrocode}
%
% 载入\pkg{fontawesome5}、\pkg{tcolorbox}、\pkg{varwidth}、
% \pkg{amssymb}、\pkg{xcolor}、\pkg{etoolbox}宏包。
%
%    \begin{macrocode}
\RequirePackage {fontawesome5, tcolorbox, varwidth, amssymb, xcolor, etoolbox}
%    \end{macrocode}
%
% 解决Expl3中\pkg{tcolorbox}和\pkg{tikz}附加库无法加载的
% 补丁(需要\pkg{etoolbox}宏包支持)
%
% \url{https://tex.stackexchange.com/questions/57424/using-of-usetikzlibrary-in-an-expl3-package-fails}
%
%    \begin{macrocode}
\ExplSyntaxOff
\patchcmd
{\tcb@input@library@in}
  {%
   \input\tcbpkgprefix#1\relax%
  }
  {%
    \@pushfilename
    \input\tcbpkgprefix#1\relax%
    \@popfilename
  }
  {}{}

\patchcmd
{\pgfutil@InputIfFileExists}
  {\input #1}
  {%
    \@pushfilename
    \xdef\@currname{#1}%
    \input #1 %
    \@popfilename
  }
  {}{}
\ExplSyntaxOn
%    \end{macrocode}
%
% 解决minted的autogobble选项与Python3的兼容性问题
% 和fancyvrb宏包命令变更的问题
%
% \url{https://github.com/gpoore/minted/issues/316}
%
%    \begin{macrocode}
\ExplSyntaxOff
\RequirePackage {regexpatch} % for starred \xpatchcmd which can replace all
\makeatletter
% trick, in order to get the integer value from either a macro or register
% in an expandable way
\def\minted@use@FancyVerbStartNum{\the\numexpr\FancyVerbStartNum}
\def\minted@use@FancyVerbStopNum{\the\numexpr\FancyVerbStopNum}

% patch for fivesum computation
\xpatchcmd*\minted@pygmentize
  {\ifx\FancyVerbStartNum\z@ 0\else\FancyVerbStartNum\fi}
  {\minted@use@FancyVerbStartNum}
  {}{\PatchFailed}
\xpatchcmd*\minted@pygmentize
  {\ifx\FancyVerbStopNum\z@ 0\else\FancyVerbStopNum\fi}
  {\minted@use@FancyVerbStopNum}
  {}{\PatchFailed}

% patch for option "autogobble"
\xpatchcmd\minted@autogobble
  {\ifx\FancyVerbStartNum\z@ 0\else\FancyVerbStartNum\fi}
  {\minted@use@FancyVerbStartNum}
  {}{\PatchFailed}
\xpatchcmd\minted@autogobble
  {\ifx\FancyVerbStopNum\z@ 0\else\FancyVerbStopNum\fi}
  {\minted@use@FancyVerbStopNum}
  {}{\PatchFailed}
\makeatother
\ExplSyntaxOn
%    \end{macrocode}
%
% 载入\pkg{tcolorbox}和\pkg{tikz}附加库
%
%    \begin{macrocode}
\tcbuselibrary{skins, xparse, breakable}
\usetikzlibrary{shapes.geometric}
%    \end{macrocode}
%
% \subsection{定义颜色}
%
%    \begin{macrocode}
\definecolor{mpurple}{RGB}{48,10,36}
\definecolor{mgray}{RGB}{70,72,67}
\definecolor{ogray}{RGB}{148,147,141}
\definecolor{oorange}{RGB}{233,101,56}
\definecolor{termimal}{RGB}{80,78,70}
\definecolor{linux}{RGB}{0,39,51}
\definecolor{windows}{HTML}{00B294}
\definecolor{cvgrayc}{RGB}{247,247,247}
\definecolor{cvgray}{RGB}{220,220,220}
\definecolor{cvgrayb}{RGB}{153,153,153}
\definecolor{cvblue}{RGB}{223,238,255}
\definecolor{zhanqing}{RGB}{0,51,113}
\definecolor{chengse}{RGB}{250,140,53}

\definecolor{AppleRed}{RGB}{255,95,86}
\definecolor{AppleYellow}{RGB}{255,189,46}
\definecolor{AppleGreen}{RGB}{39,201,63}
\definecolor{AppleGray}{HTML}{D8D6D9}

\definecolor{WinGray}{HTML}{FFFFFF}
\definecolor{WinBlue}{HTML}{1883D7}
%    \end{macrocode}
%
% \subsection{终端盒子图标设计}
%
% 用TikZ绘制Ubuntu终端盒子的最小化、关闭和最大化图标
%
%    \begin{macrocode}
\newcommand{\UbuntuMin}{%
  \begin{tikzpicture}[x=2.4ex,y=2.4ex,line~width=0.15ex,scale=1]
    \shade[shading=ball,left~color=ogray,right~color=ogray!50!white] (0,0) circle (0.5);
    \draw[termimal](-0.3,0)--(0.3,0);
  \end{tikzpicture}
}
\newcommand{\UbuntuClose}{%
  \begin{tikzpicture}[x=2.4ex,y=2.4ex,line~width=0.15ex,scale=1]
    \shade[shading=ball,left~color=oorange,right~color=oorange!70!white] (0,0) circle (0.5);
    \draw[termimal](-0.25,-0.25)--(0.25,0.25);
    \draw[termimal](-0.25,0.25)--(0.25,-0.25);
  \end{tikzpicture}
}
\newcommand{\UbuntuMax}{%
  \begin{tikzpicture}[x=2.4ex,y=2.4ex,line~width=0.15ex,scale=1]
    \shade [shading=ball,left~color=ogray,right~color=ogray!50!white] (0,0) circle (0.5);
    \draw[termimal](-0.25,-0.2)rectangle(0.25,0.2);
  \end{tikzpicture}
}
%    \end{macrocode}
%
% 绘制Windows Logo
%
%    \begin{macrocode}
\newcommand{\WindowsLogo}{%
  \begin{tikzpicture}[square/.style={regular~polygon,regular~polygon~sides=4},
         scale=0.65, every~node/.style={scale=0.65}]
    \node[square,draw,fill=black,text=white] at (0, 0) (a) {\small\faTerminal};
  \end{tikzpicture}
}
%    \end{macrocode}
%
% \subsection{终端盒子样式设计}
%
% 定义Mac终端盒子的tcolorbox样式
%
%    \begin{macrocode}
\tcbset{%
  skin=enhanced,%
  apple/.style={%
    halign~title=center,%
    skin=bicolor,%
    boxrule=0.5mm,%
    breakable,%
    frame~style={%
      draw=AppleGray,%
      left~color=AppleGray,%
      right~color=AppleGray%
    },%
    overlay~unbroken = {%
      \node[inner~sep=0pt,anchor=north~west,yshift=-4pt,xshift=10pt,text=white]
        at (frame.north~west) {\textcolor{AppleRed}{\faCircle}$\,$
                               \textcolor{AppleYellow}{\faCircle}$\,$
                               \textcolor{AppleGreen}{\faCircle}};
    },%
    overlay~first = {%
      \node[inner~sep=0pt,anchor=north~west,yshift=-4pt,xshift=10pt,text=white]
        at (frame.north~west) {\textcolor{AppleRed}{\faCircle}$\,$
                               \textcolor{AppleYellow}{\faCircle}$\,$
                               \textcolor{AppleGreen}{\faCircle}};
    },%
    fonttitle=\sffamily,%\bfseries,%
    fontupper=\small\sffamily,%
    fontlower=\small\sffamily%
  },
  appledark/.style={%
    apple,%
    colback=black,%
    colupper=white,%
    colbacktitle=AppleGray,%
    colframe=AppleGray,%
    coltitle=black%
    %coltext=MyLightGray
  },
  applelight/.style={%
    apple,%
    colback=cvgrayc,%
    colupper=black,%
    colbacktitle=AppleGray,%
    colframe=AppleGray,%
    coltitle=black%
  },%
  applewhite/.style={%
    apple,%
    colback=white,%
    colupper=black,%
    colbacktitle=AppleGray,%
    colframe=AppleGray,%
    coltitle=black%
  },%
}%
%    \end{macrocode}
%
% 定义Win10终端盒子的tcolorbox样式
%
%    \begin{macrocode}
\tcbset{%
  skin=enhanced,%
  win10/.style={%
    skin=bicolor,%
    boxrule=0.1mm,%
    %toptitle=1ex,
    sharp~corners,
    breakable,%
    colbacktitle=WinGray,%
    colframe=WinGray,%
    coltitle=black,%
    fonttitle=\sffamily,%\bfseries,
    fontupper=\small\sffamily,
    fontlower=\small\sffamily,
    frame~style={%
      draw=WinBlue,%
      left~color=WinBlue,%
      right~color=WinBlue%
    },%
    overlay~unbroken = {%
      \node[inner~sep=0pt,anchor=north~west,yshift=-3pt,xshift=1.2pt,text=black]
        at (frame.north~west){\WindowsLogo};
      \node[inner~sep=0pt,anchor=north~east,yshift=-5pt,xshift=-8pt,text=black]
        at (frame.north~east){\rule{0.8em}{0.6pt}\quad$\square$\quad{\Large$\times$}};
    },%
    overlay~first = {%
      \node[inner~sep=0pt,anchor=north~west,yshift=-3pt,xshift=1.0pt,text=black]
        at (frame.north~west){\WindowsLogo};
      \node[inner~sep=0pt,anchor=north~east,yshift=-5pt,xshift=-8pt,text=black]
        at (frame.north~east){\rule{0.8em}{0.6pt}\quad$\square$\quad{\Large$\times$}};
    }%
  },
  win10dark/.style={
    win10,%
    colback=black,%
    colupper=white,%
    %coltext=white%
  },
  win10light/.style={
    win10,%
    colback=white,%
    colupper=black,%
    %coltext=black%
  },
  win10white/.style={
    win10,%
    colback=white,%
    colupper=black,%
    %coltext=white%
  },
}%
%    \end{macrocode}
%
% 定义Ubuntu终端盒子的tcolorbox样式
%
%    \begin{macrocode}
\tcbset{%
  skin=enhanced,%
  ubuntu/.style={%
    halign~title=center,%
    skin=bicolor,%
    boxrule=0.5mm,%
    breakable,% 
    overlay~unbroken = {%
      \node[inner~sep=0pt,anchor=north~east,yshift=-3.5pt,xshift=-5pt,text=white]
        at (frame.north~east){\UbuntuMin$\,$\UbuntuMax$\,$\UbuntuClose};%
    },%
    overlay~first = {%
      \node[inner~sep=0pt,anchor=north~east,yshift=-3.5pt,xshift=-5pt,text=white]
        at (frame.north~east){\UbuntuMin$\,$\UbuntuMax$\,$\UbuntuClose};%
    },%
    fonttitle=\sffamily,%
    fontupper=\small\sffamily,%
    fontlower=\small\sffamily%
  },
  udark/.style={%
    ubuntu,%
    frame~style={%
      draw=mgray,%
      left~color=mgray,%
      right~color=mgray%
    },%
    colback=mpurple,%
    colupper=white,%
    colbacktitle=mgray,%
    colframe=mgray,%
    coltitle=white%
    %coltext=MyLightGray
  },
  ulight/.style={%
    ubuntu,%
    frame~style={%
      draw=cvgrayb,%
      left~color=cvgrayb,%
      right~color=cvgrayb%
    },%
    colback=cvgrayc,%
    colupper=black,%
    colbacktitle=cvgrayb,%
    colframe=cvgrayb,%
    coltitle=black%
  },%
  uwhite/.style={%
    ubuntu,%
    frame~style={%
      draw=cvgrayb,%
      left~color=cvgrayb,%
      right~color=cvgrayb%
    },%
    colback=white,%
    colupper=black,%
    colbacktitle=cvgrayb,%
    colframe=cvgrayb,%
    coltitle=black%
  },%
}%
%    \end{macrocode}
%
% \subsection{内部变量声明}
%
% \begin{variable}{\l_@@_minted_bool,
% \l_@@_comment_bool,
% \l_@@_os_type_int,
% \l_@@_color_theme_int,
% \l_@@_code_style_tl,
% \l_@@_code_fontsize_tl,
% \l_@@_comment_format_tl,
% \l_@@_baseline_stretch_tl,
% \l_@@_linenumber_sep_tl
%  }
% 定义变量。
%
%    \begin{macrocode}
\bool_new:N   \l_@@_minted_bool
\bool_new:N   \l_@@_comment_bool
\int_new:N    \l_@@_os_type_int
\int_new:N    \l_@@_color_theme_int
%
\tl_new:N     \l_@@_shell_style_tl
\tl_new:N     \l_@@_shell_fontsize_tl
\tl_new:N     \l_@@_comment_format_tl
\tl_new:N     \l_@@_shell_baseline_stretch_tl
\tl_new:N     \l_@@_linenumber_sep_tl
%    \end{macrocode}
% \end{variable}
%
% \subsection{选项处理}
%
% 定义 |termsim| 键值类。
%    \begin{macrocode}
\keys_define:nn { termsim }
  {
%    \end{macrocode}
%
% \begin{macro}{minted}
% 是否使用minted宏包排版代码,默认为true。
%    \begin{macrocode}
    minted .bool_set:N = \l_@@_minted_bool,
    minted .default:n = true,
    minted .initial:n = true,
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{os}
% 选择操作系统,默认为Win10。
%    \begin{macrocode}
    os .choice:,
    os .value_required:n = true,
    os .choices:nn =
      { win10, mac, ubuntu }
      { \int_set_eq:NN \l_@@_os_type_int \l_keys_choice_int },
    os .initial:n = win10,
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{theme}
% 选择终端窗口颜色主题,默认为dark。
%    \begin{macrocode}
    theme .choice:,
    theme .value_required:n = true,
    theme .choices:nn =
      { dark, light, white }
      { \int_set_eq:NN \l_@@_color_theme_int \l_keys_choice_int },
    theme .initial:n = dark,
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{shstyle}
% 代码样式
%    \begin{macrocode}
    shstyle .tl_set:N = \l_@@_shell_style_tl,
    shstyle .initial:n = bw,
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{shsize}
% 代码字号
%    \begin{macrocode}
    shsize .tl_set:N = \l_@@_shell_fontsize_tl,
    shsize .initial:n = \small,
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{commentf}
% 注释格式
%    \begin{macrocode}
    commentf .tl_set:N = \l_@@_comment_format_tl,
    commentf .initial:n = \small\sffamily,
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{shstrech}
% 基线伸展系数
%    \begin{macrocode}
    shstretch .tl_set:N  = \l_@@_shell_baseline_strech_tl,
    shstretch .initial:n = 1.0,
%    \end{macrocode}
% \end{macro}
%
% 处理未知选项。
%    \begin{macrocode}
    unknown .code:n = { \@@_error:n { unknown-option } }
  }
\msg_new:nnn { termsim } { unknown-option }
  { package~ option~ "\l_keys_key_tl"~ is~ unknown. }
%    \end{macrocode}
%
% 参数默认值
%    \begin{macrocode}
\keys_set:nn { termsim }
  {
    minted = true,
    os     = win10,
    theme  = dark,
  }
%    \end{macrocode}
%
% \subsection{选项用户接口}
%
% \begin{macro}{\termset}
% 选项设置用户接口。
%    \begin{macrocode}
\NewDocumentCommand \termset { m }
  { \keys_set:nn { termsim } {#1} }
%    \end{macrocode}
% \end{macro}
%
% \subsection{内部函数}
%
% \begin{macro}{\@@_minted_tcbset:}
% 设置终端盒子minted宏包参数。
%
%    \begin{macrocode}
\cs_new:Npn \@@_minted_tcbset:n #1
  {
    \tcbset{
      listing~engine=minted,%
      minted~style=\tl_use:N \l_@@_shell_style_tl,%
      minted~options={%
        breaklines,%
        fontsize=\tl_use:N \l_@@_shell_fontsize_tl,%
        baselinestretch=#1,%
        breaksymbolleft={},%
        linenos=false,%
      },%
      minted~language=bash%
    }
  }
\cs_generate_variant:Nn \@@_minted_tcbset:n {V}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_listings_tcbset:}
% 设置终端盒子listings宏包参数。
%
%    \begin{macrocode}
\cs_new:Npn \@@_listings_tcbset:
  {
    \lstset{% general command to set parameter(s)
      basicstyle=\ttfamily\tl_use:N \l_@@_shell_fontsize_tl, % print whole listing small
      keywordstyle=\color{chengse}\bfseries,%
      identifierstyle=, % nothing happens
      breaklines=true,
      commentstyle=\itshape\color{gray},
      stringstyle=\ttfamily, % typewriter type for strings
      numbers=left,%
      numberstyle=\tl_use:N \l_@@_shell_fontsize_tl\sffamily\color[rgb]{0.5,0.5,1.0},%
    }%
  }
\cs_generate_variant:Nn \@@_minted_tcbset:n {V}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_comment_tcbset:}
% 设置终端盒子底线注释。
%
%    \begin{macrocode}
\cs_new:Npn \@@_comment_tcbset:n #1
  {
    \bool_if:NTF { \l_@@_comment_bool }
    {
      \tcbset{%
        listing~and~comment,%
        colbacklower=tcbcolback!5!yellow!10!white,%
        collower=linux,%
        comment={\tl_use:N \l_@@_comment_format_tl~#1},%
      }
    }{
      \tcbset{ listing~only,}
    }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_terminal_theme_select:}
% 选择终端盒子颜色主题。
%
%    \begin{macrocode}
\cs_new:Npn \@@_terminal_theme_select:
  {
    \int_case:nn {\l_@@_os_type_int}
      {
        {1}{
          \int_case:nn {\l_@@_color_theme_int}
            {
              {1}{
                \tcbset{ win10dark, }
              }
              {2}{
                \tcbset{ win10light, }
              }
              {3}{
                \tcbset{ win10white, }
              }
            }
        }
        {2}{
          \int_case:nn {\l_@@_color_theme_int}
            {
              {1}{
                \tcbset{ appledark, }
              }
              {2}{
                \tcbset{ applelight, }
              }
              {3}{
                \tcbset{ applewhite, }
              }
            }
        }
        {3}{
          \int_case:nn {\l_@@_color_theme_int}
            {
              {1}{
                \tcbset{ udark, }
              }
              {2}{
                \tcbset{ ulight, }
              }
              {3}{
                \tcbset{ uwhite, }
              }
            }
        }
    }
  }
%    \end{macrocode}
% \end{macro}
%
% \subsection{定义排版环境和命令}
%
%    \begin{macrocode}
\bool_if:NTF \l_@@_minted_bool
  {
%    \end{macrocode}
%
%  使用\pkg{minted}宏包排版代码
%
%    \begin{macrocode}
    \tcbuselibrary{minted}
%    \end{macrocode}
%
%  定义不带底线注释的窗口模拟环境\env{terminal}
%
%    \begin{macrocode}
    \NewDocumentEnvironment{ terminal }{O{} O{} m }
      {
        \bool_set_false:N  \l_@@_comment_bool
        \group_begin:
        \IfNoValueF{#1}{ \keys_set:nn { termsim } { #1 } }
        \@@_comment_tcbset:n { #2 }
        \@@_terminal_theme_select:
        \@@_minted_tcbset:V \l_@@_shell_baseline_stretch_tl
        \tcbset{ title={#3} }%
        \tcblisting{}
      }{
        \endtcblisting
        \group_end:
      }
%    \end{macrocode}
%
%  定义带底线注释的窗口模拟环境\env{terminal*}
%
%    \begin{macrocode}
    \NewDocumentEnvironment{ terminal* }{O{} O{} m }
      {
        \bool_set_true:N \l_@@_comment_bool
        \group_begin:
        \IfNoValueF{#1}{ \keys_set:nn { termsim } { #1 } }
        \@@_comment_tcbset:n { #2 }
        \@@_terminal_theme_select:
        \@@_minted_tcbset:V \l_@@_shell_baseline_stretch_tl
        \tcbset{ title={#3} }%
        \tcblisting{}
      }{
        \endtcblisting
        \group_end:
      }
%    \end{macrocode}
%
%  定义带/不带底线注释的从文件读取内容的命令\tn{termfile}/\tn{termfile*}
%
%    \begin{macrocode}
    \NewDocumentCommand \termfile { s O{} O{} m m }
      {
        \IfBooleanTF{#1}
          {
            \bool_set_true:N  \l_@@_comment_bool
          }{
            \bool_set_false:N \l_@@_comment_bool
          }

        \group_begin:
        \IfNoValueF{#2}{ \keys_set:nn { termsim } { #2 } }
        \@@_comment_tcbset:n { #3 }
        \@@_terminal_theme_select:
        \@@_minted_tcbset:V \l_@@_shell_baseline_stretch_tl
        \tcbset{
          title={#4},
          listing~file={#5},
        }%
        \tcbinputlisting{  }
        \group_end:
      }
  }{
%    \end{macrocode}
%
%  使用\pkg{listings}宏包排版代码,并设置代码样式。
%
%    \begin{macrocode}
    \tcbuselibrary{listings}% 用listings排版代码

    \@@_listings_tcbset:

%    \end{macrocode}
%
%  定义不带底线注释的窗口模拟环境\env{terminal}
%
%    \begin{macrocode}
    \NewDocumentEnvironment{ terminal }{O{} O{} m }
      {
        \bool_set_false:N \l_@@_comment_bool
        \group_begin:
        \IfNoValueF{#1}{ \keys_set:nn { termsim } { #1 } }
        \@@_comment_tcbset:n { #2 }
        \@@_terminal_theme_select:
        \tcbset{
          title={#3},
          listing~options={
            language=bash,
            numbers=none,
          }
        }%
        \tcblisting{}
      }{
        \endtcblisting
        \group_end:
      }
%    \end{macrocode}
%
%  定义带底线注释的窗口模拟环境\env{terminal*}
%
%    \begin{macrocode}
    \NewDocumentEnvironment{ terminal* }{O{} O{} m }
      {
        \bool_set_true:N  \l_@@_comment_bool
        \group_begin:
        \IfNoValueF{#1}{ \keys_set:nn { termsim } { #1 } }
        \@@_comment_tcbset:n { #2 }
        \@@_terminal_theme_select:
        \tcbset{
          title={#3},
          listing~options={
            language=bash,
            numbers=none,
          }
        }%
        \tcblisting{}
      }{
        \endtcblisting
        \group_end:
      }
%    \end{macrocode}
%
%  定义带/不带底线注释的从文件读取内容的命令\tn{termfile}/\tn{termfile*}
%
%    \begin{macrocode}
    \NewDocumentCommand \termfile { s O{} O{} m m }
      {
        \IfBooleanTF{#1}
          {
            \bool_set_true:N  \l_@@_comment_bool
          }{
            \bool_set_false:N \l_@@_comment_bool
          }
        \group_begin:
        \IfNoValueF{#2}{ \keys_set:nn { termsim } { #2 } }
        \@@_comment_tcbset:n { #3 }
        \@@_terminal_theme_select:
        \tcbset{
          title={#4},
          listing~file={#5},
          listing~options={
            language=bash,
            numbers=none,
          },%
        }%
        \tcbinputlisting{  }
        \group_end:
      }
  }
%    \end{macrocode}
%
%    \begin{macrocode}
\endinput
%    \end{macrocode}
%
%    \begin{macrocode}
%</package>
%    \end{macrocode}
%
% \end{implementation}
%
% \Finale
%
\endinput