terminal_rb 0.18.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/bin/bbcode +1 -1
- data/lib/terminal/text/char_width.rb +166 -31
- data/lib/terminal/text.rb +90 -66
- data/lib/terminal/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 76294a5517d1c24b4c85f855cf802ce01dd1fa574dfac92753edd78b7a8fd465
|
|
4
|
+
data.tar.gz: 3e95e7b5ae8f40a9e284cdd3abddbd5a77a70e0a4df40e0deed2702acaf2ed07
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 99e9e190caea636278031df7116ce0fdaf15fa6fdf2c6c1912906862341eae25e3b6aacc77296aca15b833e4548cbad36edf7f41160fc313059c6ecbe472fb2a
|
|
7
|
+
data.tar.gz: 0b5cbc5ef6ed87179d6b74663607bec29c07ad53ca4fc7c1593577214e31d5b08281fa68a119be361eb4ce720420767d09690b5679ee2f6e43ef3061c40b7ec7
|
data/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Terminal.rb supports you with input and output on your terminal. Simple [BBCode]
|
|
|
4
4
|
|
|
5
5
|
- Gem: [rubygems.org](https://rubygems.org/gems/terminal_rb)
|
|
6
6
|
- Source: [codeberg.org](https://codeberg.org/mblumtritt/Terminal.rb)
|
|
7
|
-
- Help: [rubydoc.info](https://rubydoc.info/gems/terminal_rb/0.
|
|
7
|
+
- Help: [rubydoc.info](https://rubydoc.info/gems/terminal_rb/0.19.0/Terminal)
|
|
8
8
|
|
|
9
9
|
## Features
|
|
10
10
|
|
|
@@ -70,7 +70,7 @@ You can install the gem in your system with
|
|
|
70
70
|
gem install terminal_rb
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
-
or you can use [Bundler](
|
|
73
|
+
or you can use [Bundler](https://bundler.io) to add Terminal.rb to your own project:
|
|
74
74
|
|
|
75
75
|
```shell
|
|
76
76
|
bundle add terminal_rb
|
data/bin/bbcode
CHANGED
|
@@ -2,26 +2,37 @@
|
|
|
2
2
|
|
|
3
3
|
module Terminal
|
|
4
4
|
module Text
|
|
5
|
-
#
|
|
6
|
-
|
|
5
|
+
# supported Unicode Standard version
|
|
6
|
+
UNICODE_VERSION = '17.0.0'
|
|
7
|
+
|
|
8
|
+
# Generated file
|
|
9
|
+
# based on https://www.unicode.org/Public/UNIDATA/EastAsianWidth.txt
|
|
7
10
|
#
|
|
8
11
|
module CharWidth
|
|
9
12
|
def self.[](ord) = @width[@last.bsearch_index { ord <= _1 }]
|
|
10
13
|
|
|
11
14
|
@last = [
|
|
15
|
+
0x5d,
|
|
16
|
+
0x5e,
|
|
17
|
+
0x5f,
|
|
18
|
+
0x60,
|
|
12
19
|
0xa0,
|
|
13
20
|
0xa1,
|
|
14
21
|
0xa3,
|
|
15
22
|
0xa4,
|
|
16
23
|
0xa6,
|
|
24
|
+
0xa7,
|
|
17
25
|
0xa8,
|
|
18
26
|
0xa9,
|
|
19
27
|
0xaa,
|
|
20
28
|
0xac,
|
|
21
29
|
0xae,
|
|
22
30
|
0xaf,
|
|
31
|
+
0xb3,
|
|
23
32
|
0xb4,
|
|
24
33
|
0xb5,
|
|
34
|
+
0xb7,
|
|
35
|
+
0xb8,
|
|
25
36
|
0xba,
|
|
26
37
|
0xbb,
|
|
27
38
|
0xbf,
|
|
@@ -99,8 +110,8 @@ module Terminal
|
|
|
99
110
|
0x251,
|
|
100
111
|
0x260,
|
|
101
112
|
0x261,
|
|
102
|
-
|
|
103
|
-
|
|
113
|
+
0x2c1,
|
|
114
|
+
0x2c5,
|
|
104
115
|
0x2c6,
|
|
105
116
|
0x2c7,
|
|
106
117
|
0x2c8,
|
|
@@ -109,14 +120,18 @@ module Terminal
|
|
|
109
120
|
0x2cd,
|
|
110
121
|
0x2cf,
|
|
111
122
|
0x2d0,
|
|
112
|
-
|
|
113
|
-
0x2db,
|
|
114
|
-
0x2dc,
|
|
115
|
-
0x2dd,
|
|
116
|
-
0x2de,
|
|
123
|
+
0x2d1,
|
|
117
124
|
0x2df,
|
|
118
|
-
|
|
125
|
+
0x2e4,
|
|
126
|
+
0x2eb,
|
|
127
|
+
0x2ec,
|
|
128
|
+
0x2ed,
|
|
129
|
+
0x2ee,
|
|
119
130
|
0x36f,
|
|
131
|
+
0x374,
|
|
132
|
+
0x375,
|
|
133
|
+
0x383,
|
|
134
|
+
0x385,
|
|
120
135
|
0x390,
|
|
121
136
|
0x3a1,
|
|
122
137
|
0x3a2,
|
|
@@ -143,20 +158,26 @@ module Terminal
|
|
|
143
158
|
0x5c5,
|
|
144
159
|
0x5c6,
|
|
145
160
|
0x5c7,
|
|
161
|
+
0x5ff,
|
|
162
|
+
0x605,
|
|
146
163
|
0x60f,
|
|
147
164
|
0x61a,
|
|
165
|
+
0x61b,
|
|
166
|
+
0x61c,
|
|
148
167
|
0x64a,
|
|
149
168
|
0x65f,
|
|
150
169
|
0x66f,
|
|
151
170
|
0x670,
|
|
152
171
|
0x6d5,
|
|
153
|
-
|
|
172
|
+
0x6dd,
|
|
154
173
|
0x6de,
|
|
155
174
|
0x6e4,
|
|
156
175
|
0x6e6,
|
|
157
176
|
0x6e8,
|
|
158
177
|
0x6e9,
|
|
159
178
|
0x6ed,
|
|
179
|
+
0x70e,
|
|
180
|
+
0x70f,
|
|
160
181
|
0x710,
|
|
161
182
|
0x711,
|
|
162
183
|
0x72f,
|
|
@@ -177,11 +198,13 @@ module Terminal
|
|
|
177
198
|
0x82d,
|
|
178
199
|
0x858,
|
|
179
200
|
0x85b,
|
|
201
|
+
0x887,
|
|
202
|
+
0x888,
|
|
203
|
+
0x88f,
|
|
204
|
+
0x891,
|
|
180
205
|
0x896,
|
|
181
206
|
0x89f,
|
|
182
207
|
0x8c9,
|
|
183
|
-
0x8e1,
|
|
184
|
-
0x8e2,
|
|
185
208
|
0x902,
|
|
186
209
|
0x939,
|
|
187
210
|
0x93a,
|
|
@@ -359,7 +382,6 @@ module Terminal
|
|
|
359
382
|
0x109d,
|
|
360
383
|
0x10ff,
|
|
361
384
|
0x115f,
|
|
362
|
-
0x11ff,
|
|
363
385
|
0x135c,
|
|
364
386
|
0x135f,
|
|
365
387
|
0x1711,
|
|
@@ -381,8 +403,6 @@ module Terminal
|
|
|
381
403
|
0x17dc,
|
|
382
404
|
0x17dd,
|
|
383
405
|
0x180a,
|
|
384
|
-
0x180d,
|
|
385
|
-
0x180e,
|
|
386
406
|
0x180f,
|
|
387
407
|
0x1884,
|
|
388
408
|
0x1886,
|
|
@@ -464,6 +484,19 @@ module Terminal
|
|
|
464
484
|
0x1cf9,
|
|
465
485
|
0x1dbf,
|
|
466
486
|
0x1dff,
|
|
487
|
+
0x1fbc,
|
|
488
|
+
0x1fbd,
|
|
489
|
+
0x1fbe,
|
|
490
|
+
0x1fc1,
|
|
491
|
+
0x1fcc,
|
|
492
|
+
0x1fcf,
|
|
493
|
+
0x1fdc,
|
|
494
|
+
0x1fdf,
|
|
495
|
+
0x1fec,
|
|
496
|
+
0x1fef,
|
|
497
|
+
0x1ffc,
|
|
498
|
+
0x1ffe,
|
|
499
|
+
0x200a,
|
|
467
500
|
0x200f,
|
|
468
501
|
0x2010,
|
|
469
502
|
0x2012,
|
|
@@ -476,6 +509,8 @@ module Terminal
|
|
|
476
509
|
0x2022,
|
|
477
510
|
0x2023,
|
|
478
511
|
0x2027,
|
|
512
|
+
0x2029,
|
|
513
|
+
0x202e,
|
|
479
514
|
0x202f,
|
|
480
515
|
0x2030,
|
|
481
516
|
0x2031,
|
|
@@ -486,6 +521,10 @@ module Terminal
|
|
|
486
521
|
0x203b,
|
|
487
522
|
0x203d,
|
|
488
523
|
0x203e,
|
|
524
|
+
0x205f,
|
|
525
|
+
0x2064,
|
|
526
|
+
0x2065,
|
|
527
|
+
0x206f,
|
|
489
528
|
0x2073,
|
|
490
529
|
0x2074,
|
|
491
530
|
0x207e,
|
|
@@ -750,7 +789,7 @@ module Terminal
|
|
|
750
789
|
0x3040,
|
|
751
790
|
0x3096,
|
|
752
791
|
0x3098,
|
|
753
|
-
|
|
792
|
+
0x309c,
|
|
754
793
|
0x30ff,
|
|
755
794
|
0x3104,
|
|
756
795
|
0x312f,
|
|
@@ -774,6 +813,12 @@ module Terminal
|
|
|
774
813
|
0xa69f,
|
|
775
814
|
0xa6ef,
|
|
776
815
|
0xa6f1,
|
|
816
|
+
0xa6ff,
|
|
817
|
+
0xa716,
|
|
818
|
+
0xa71f,
|
|
819
|
+
0xa721,
|
|
820
|
+
0xa788,
|
|
821
|
+
0xa78a,
|
|
777
822
|
0xa801,
|
|
778
823
|
0xa802,
|
|
779
824
|
0xa805,
|
|
@@ -832,6 +877,10 @@ module Terminal
|
|
|
832
877
|
0xaaed,
|
|
833
878
|
0xaaf5,
|
|
834
879
|
0xaaf6,
|
|
880
|
+
0xab5a,
|
|
881
|
+
0xab5b,
|
|
882
|
+
0xab69,
|
|
883
|
+
0xab6b,
|
|
835
884
|
0xabe4,
|
|
836
885
|
0xabe5,
|
|
837
886
|
0xabe7,
|
|
@@ -840,15 +889,13 @@ module Terminal
|
|
|
840
889
|
0xabed,
|
|
841
890
|
0xabff,
|
|
842
891
|
0xd7a3,
|
|
843
|
-
0xd7af,
|
|
844
|
-
0xd7c6,
|
|
845
|
-
0xd7ca,
|
|
846
|
-
0xd7fb,
|
|
847
892
|
0xdfff,
|
|
848
893
|
0xf8ff,
|
|
849
894
|
0xfaff,
|
|
850
895
|
0xfb1d,
|
|
851
896
|
0xfb1e,
|
|
897
|
+
0xfbb1,
|
|
898
|
+
0xfbc2,
|
|
852
899
|
0xfdff,
|
|
853
900
|
0xfe0f,
|
|
854
901
|
0xfe19,
|
|
@@ -859,10 +906,20 @@ module Terminal
|
|
|
859
906
|
0xfe66,
|
|
860
907
|
0xfe67,
|
|
861
908
|
0xfe6b,
|
|
909
|
+
0xfefe,
|
|
910
|
+
0xfeff,
|
|
862
911
|
0xff00,
|
|
912
|
+
0xff3d,
|
|
913
|
+
0xff3e,
|
|
914
|
+
0xff3f,
|
|
915
|
+
0xff40,
|
|
863
916
|
0xff60,
|
|
864
917
|
0xffdf,
|
|
918
|
+
0xffe2,
|
|
919
|
+
0xffe3,
|
|
865
920
|
0xffe6,
|
|
921
|
+
0xfff8,
|
|
922
|
+
0xfffb,
|
|
866
923
|
0xfffc,
|
|
867
924
|
0xfffd,
|
|
868
925
|
0x101fc,
|
|
@@ -909,8 +966,12 @@ module Terminal
|
|
|
909
966
|
0x110b6,
|
|
910
967
|
0x110b8,
|
|
911
968
|
0x110ba,
|
|
969
|
+
0x110bc,
|
|
970
|
+
0x110bd,
|
|
912
971
|
0x110c1,
|
|
913
972
|
0x110c2,
|
|
973
|
+
0x110cc,
|
|
974
|
+
0x110cd,
|
|
914
975
|
0x110ff,
|
|
915
976
|
0x11102,
|
|
916
977
|
0x11126,
|
|
@@ -1087,7 +1148,7 @@ module Terminal
|
|
|
1087
1148
|
0x11f42,
|
|
1088
1149
|
0x11f59,
|
|
1089
1150
|
0x11f5a,
|
|
1090
|
-
|
|
1151
|
+
0x1342f,
|
|
1091
1152
|
0x13440,
|
|
1092
1153
|
0x13446,
|
|
1093
1154
|
0x13455,
|
|
@@ -1134,13 +1195,15 @@ module Terminal
|
|
|
1134
1195
|
0x1b2fb,
|
|
1135
1196
|
0x1bc9c,
|
|
1136
1197
|
0x1bc9e,
|
|
1198
|
+
0x1bc9f,
|
|
1199
|
+
0x1bca3,
|
|
1137
1200
|
0x1ceff,
|
|
1138
1201
|
0x1cf2d,
|
|
1139
1202
|
0x1cf2f,
|
|
1140
1203
|
0x1cf46,
|
|
1141
1204
|
0x1d166,
|
|
1142
1205
|
0x1d169,
|
|
1143
|
-
|
|
1206
|
+
0x1d172,
|
|
1144
1207
|
0x1d182,
|
|
1145
1208
|
0x1d184,
|
|
1146
1209
|
0x1d18b,
|
|
@@ -1214,7 +1277,7 @@ module Terminal
|
|
|
1214
1277
|
0x1f190,
|
|
1215
1278
|
0x1f19a,
|
|
1216
1279
|
0x1f1ac,
|
|
1217
|
-
|
|
1280
|
+
0x1f1ff,
|
|
1218
1281
|
0x1f202,
|
|
1219
1282
|
0x1f20f,
|
|
1220
1283
|
0x1f23b,
|
|
@@ -1241,6 +1304,8 @@ module Terminal
|
|
|
1241
1304
|
0x1f3f3,
|
|
1242
1305
|
0x1f3f4,
|
|
1243
1306
|
0x1f3f7,
|
|
1307
|
+
0x1f3fa,
|
|
1308
|
+
0x1f3ff,
|
|
1244
1309
|
0x1f43e,
|
|
1245
1310
|
0x1f43f,
|
|
1246
1311
|
0x1f440,
|
|
@@ -1302,6 +1367,10 @@ module Terminal
|
|
|
1302
1367
|
0x2fffd,
|
|
1303
1368
|
0x2ffff,
|
|
1304
1369
|
0x3fffd,
|
|
1370
|
+
0xe0000,
|
|
1371
|
+
0xe0001,
|
|
1372
|
+
0xe001f,
|
|
1373
|
+
0xe007f,
|
|
1305
1374
|
0xe00ff,
|
|
1306
1375
|
0xe01ef,
|
|
1307
1376
|
0xeffff,
|
|
@@ -1313,24 +1382,26 @@ module Terminal
|
|
|
1313
1382
|
|
|
1314
1383
|
@width = [
|
|
1315
1384
|
1,
|
|
1316
|
-
|
|
1385
|
+
0,
|
|
1317
1386
|
1,
|
|
1318
|
-
|
|
1387
|
+
0,
|
|
1319
1388
|
1,
|
|
1320
1389
|
-1,
|
|
1321
1390
|
1,
|
|
1322
1391
|
-1,
|
|
1323
1392
|
1,
|
|
1324
1393
|
-1,
|
|
1394
|
+
0,
|
|
1325
1395
|
1,
|
|
1326
1396
|
-1,
|
|
1327
1397
|
1,
|
|
1328
1398
|
-1,
|
|
1329
|
-
|
|
1399
|
+
0,
|
|
1330
1400
|
-1,
|
|
1401
|
+
0,
|
|
1331
1402
|
1,
|
|
1332
1403
|
-1,
|
|
1333
|
-
|
|
1404
|
+
0,
|
|
1334
1405
|
-1,
|
|
1335
1406
|
1,
|
|
1336
1407
|
-1,
|
|
@@ -1409,7 +1480,7 @@ module Terminal
|
|
|
1409
1480
|
1,
|
|
1410
1481
|
-1,
|
|
1411
1482
|
1,
|
|
1412
|
-
|
|
1483
|
+
0,
|
|
1413
1484
|
1,
|
|
1414
1485
|
-1,
|
|
1415
1486
|
1,
|
|
@@ -1421,6 +1492,16 @@ module Terminal
|
|
|
1421
1492
|
1,
|
|
1422
1493
|
0,
|
|
1423
1494
|
1,
|
|
1495
|
+
0,
|
|
1496
|
+
1,
|
|
1497
|
+
0,
|
|
1498
|
+
1,
|
|
1499
|
+
0,
|
|
1500
|
+
1,
|
|
1501
|
+
0,
|
|
1502
|
+
1,
|
|
1503
|
+
0,
|
|
1504
|
+
1,
|
|
1424
1505
|
-1,
|
|
1425
1506
|
1,
|
|
1426
1507
|
-1,
|
|
@@ -1661,7 +1742,24 @@ module Terminal
|
|
|
1661
1742
|
1,
|
|
1662
1743
|
0,
|
|
1663
1744
|
1,
|
|
1745
|
+
0,
|
|
1746
|
+
1,
|
|
1747
|
+
0,
|
|
1748
|
+
1,
|
|
1749
|
+
0,
|
|
1750
|
+
1,
|
|
1751
|
+
0,
|
|
1752
|
+
1,
|
|
1664
1753
|
2,
|
|
1754
|
+
1,
|
|
1755
|
+
0,
|
|
1756
|
+
1,
|
|
1757
|
+
0,
|
|
1758
|
+
1,
|
|
1759
|
+
0,
|
|
1760
|
+
1,
|
|
1761
|
+
0,
|
|
1762
|
+
1,
|
|
1665
1763
|
0,
|
|
1666
1764
|
1,
|
|
1667
1765
|
0,
|
|
@@ -1768,6 +1866,7 @@ module Terminal
|
|
|
1768
1866
|
1,
|
|
1769
1867
|
0,
|
|
1770
1868
|
1,
|
|
1869
|
+
0,
|
|
1771
1870
|
-1,
|
|
1772
1871
|
1,
|
|
1773
1872
|
-1,
|
|
@@ -1780,6 +1879,8 @@ module Terminal
|
|
|
1780
1879
|
1,
|
|
1781
1880
|
-1,
|
|
1782
1881
|
1,
|
|
1882
|
+
0,
|
|
1883
|
+
1,
|
|
1783
1884
|
-1,
|
|
1784
1885
|
1,
|
|
1785
1886
|
-1,
|
|
@@ -1790,6 +1891,10 @@ module Terminal
|
|
|
1790
1891
|
1,
|
|
1791
1892
|
-1,
|
|
1792
1893
|
1,
|
|
1894
|
+
0,
|
|
1895
|
+
1,
|
|
1896
|
+
0,
|
|
1897
|
+
1,
|
|
1793
1898
|
-1,
|
|
1794
1899
|
1,
|
|
1795
1900
|
-1,
|
|
@@ -2098,12 +2203,14 @@ module Terminal
|
|
|
2098
2203
|
1,
|
|
2099
2204
|
0,
|
|
2100
2205
|
1,
|
|
2101
|
-
|
|
2206
|
+
0,
|
|
2102
2207
|
1,
|
|
2103
2208
|
0,
|
|
2104
2209
|
1,
|
|
2105
2210
|
0,
|
|
2106
2211
|
1,
|
|
2212
|
+
2,
|
|
2213
|
+
1,
|
|
2107
2214
|
0,
|
|
2108
2215
|
1,
|
|
2109
2216
|
0,
|
|
@@ -2142,18 +2249,24 @@ module Terminal
|
|
|
2142
2249
|
1,
|
|
2143
2250
|
0,
|
|
2144
2251
|
1,
|
|
2145
|
-
|
|
2252
|
+
0,
|
|
2146
2253
|
1,
|
|
2147
2254
|
0,
|
|
2148
2255
|
1,
|
|
2149
2256
|
0,
|
|
2150
2257
|
1,
|
|
2258
|
+
0,
|
|
2259
|
+
1,
|
|
2260
|
+
2,
|
|
2261
|
+
1,
|
|
2151
2262
|
-1,
|
|
2152
2263
|
2,
|
|
2153
2264
|
1,
|
|
2154
2265
|
0,
|
|
2155
2266
|
1,
|
|
2156
2267
|
0,
|
|
2268
|
+
1,
|
|
2269
|
+
0,
|
|
2157
2270
|
2,
|
|
2158
2271
|
1,
|
|
2159
2272
|
0,
|
|
@@ -2163,9 +2276,19 @@ module Terminal
|
|
|
2163
2276
|
1,
|
|
2164
2277
|
2,
|
|
2165
2278
|
1,
|
|
2279
|
+
0,
|
|
2280
|
+
1,
|
|
2281
|
+
2,
|
|
2282
|
+
0,
|
|
2283
|
+
2,
|
|
2284
|
+
0,
|
|
2166
2285
|
2,
|
|
2167
2286
|
1,
|
|
2168
2287
|
2,
|
|
2288
|
+
0,
|
|
2289
|
+
2,
|
|
2290
|
+
1,
|
|
2291
|
+
0,
|
|
2169
2292
|
1,
|
|
2170
2293
|
-1,
|
|
2171
2294
|
1,
|
|
@@ -2407,6 +2530,10 @@ module Terminal
|
|
|
2407
2530
|
1,
|
|
2408
2531
|
0,
|
|
2409
2532
|
1,
|
|
2533
|
+
0,
|
|
2534
|
+
1,
|
|
2535
|
+
0,
|
|
2536
|
+
1,
|
|
2410
2537
|
2,
|
|
2411
2538
|
0,
|
|
2412
2539
|
1,
|
|
@@ -2452,6 +2579,8 @@ module Terminal
|
|
|
2452
2579
|
1,
|
|
2453
2580
|
0,
|
|
2454
2581
|
1,
|
|
2582
|
+
0,
|
|
2583
|
+
1,
|
|
2455
2584
|
2,
|
|
2456
2585
|
1,
|
|
2457
2586
|
2,
|
|
@@ -2545,6 +2674,8 @@ module Terminal
|
|
|
2545
2674
|
2,
|
|
2546
2675
|
1,
|
|
2547
2676
|
2,
|
|
2677
|
+
0,
|
|
2678
|
+
2,
|
|
2548
2679
|
1,
|
|
2549
2680
|
2,
|
|
2550
2681
|
1,
|
|
@@ -2608,6 +2739,10 @@ module Terminal
|
|
|
2608
2739
|
1,
|
|
2609
2740
|
0,
|
|
2610
2741
|
1,
|
|
2742
|
+
0,
|
|
2743
|
+
1,
|
|
2744
|
+
0,
|
|
2745
|
+
1,
|
|
2611
2746
|
-1,
|
|
2612
2747
|
1,
|
|
2613
2748
|
-1,
|
data/lib/terminal/text.rb
CHANGED
|
@@ -108,18 +108,39 @@ module Terminal
|
|
|
108
108
|
end
|
|
109
109
|
alias each_with_size each_line_with_size
|
|
110
110
|
|
|
111
|
+
# Returns maximal width of a line of given text.
|
|
112
|
+
#
|
|
113
|
+
# @param (see each_line)
|
|
114
|
+
# @return [Integer] width
|
|
115
|
+
def max_line_width(*text, ignore_newline: false)
|
|
116
|
+
return 0 if text.empty?
|
|
117
|
+
ret = 0
|
|
118
|
+
pairs(as_snippets(text, false, false, ignore_newline, Word)) do |_l, w|
|
|
119
|
+
ret = w if w > ret
|
|
120
|
+
end
|
|
121
|
+
ret
|
|
122
|
+
end
|
|
123
|
+
|
|
111
124
|
private
|
|
112
125
|
|
|
113
126
|
def char_width(char)
|
|
114
127
|
ord = char.ord
|
|
115
|
-
return @ctrlchar_width[ord]
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
128
|
+
return @ctrlchar_width[ord] if ord < 0x20
|
|
129
|
+
if char.size == 1
|
|
130
|
+
return 1 if ord < 0xa1
|
|
131
|
+
width = CharWidth[ord]
|
|
132
|
+
return width < 0 ? @ambiguous_char_width : width
|
|
133
|
+
end
|
|
134
|
+
sum = 0
|
|
135
|
+
zwj = false
|
|
136
|
+
char.each_char do |c|
|
|
137
|
+
next zwj = false if zwj
|
|
138
|
+
ord = c.ord
|
|
139
|
+
next zwj = true if ord == 0x200d # zero with joiner
|
|
140
|
+
width = CharWidth[ord]
|
|
141
|
+
sum += (width < 0 ? @ambiguous_char_width : width)
|
|
142
|
+
end
|
|
143
|
+
sum
|
|
123
144
|
end
|
|
124
145
|
|
|
125
146
|
def lim_pairs(snippets, limit)
|
|
@@ -153,8 +174,8 @@ module Terminal
|
|
|
153
174
|
next csi = nil
|
|
154
175
|
end
|
|
155
176
|
|
|
156
|
-
next line << (csi = snippet) if snippet
|
|
157
|
-
next line << snippet if snippet
|
|
177
|
+
next line << (csi = snippet) if Csi === snippet
|
|
178
|
+
next line << snippet if Osc === snippet
|
|
158
179
|
|
|
159
180
|
# Word:
|
|
160
181
|
|
|
@@ -217,12 +238,12 @@ module Terminal
|
|
|
217
238
|
next csi = nil
|
|
218
239
|
end
|
|
219
240
|
|
|
220
|
-
next line << (csi = snippet) if snippet
|
|
221
|
-
next line << snippet if snippet
|
|
241
|
+
next line << (csi = snippet) if Csi === snippet
|
|
242
|
+
next line << snippet if Osc === snippet
|
|
222
243
|
|
|
223
244
|
# Word:
|
|
224
|
-
line << snippet
|
|
225
245
|
size += snippet.size
|
|
246
|
+
line << snippet
|
|
226
247
|
end
|
|
227
248
|
nil
|
|
228
249
|
end
|
|
@@ -258,8 +279,8 @@ module Terminal
|
|
|
258
279
|
next csi = nil
|
|
259
280
|
end
|
|
260
281
|
|
|
261
|
-
next line << (csi = snippet) if snippet
|
|
262
|
-
next line << snippet if snippet
|
|
282
|
+
next line << (csi = snippet) if Csi === snippet
|
|
283
|
+
next line << snippet if Osc === snippet
|
|
263
284
|
|
|
264
285
|
# Word:
|
|
265
286
|
|
|
@@ -322,12 +343,12 @@ module Terminal
|
|
|
322
343
|
next csi = nil
|
|
323
344
|
end
|
|
324
345
|
|
|
325
|
-
next line << (csi = snippet) if snippet
|
|
326
|
-
next line << snippet if snippet
|
|
346
|
+
next line << (csi = snippet) if Csi === snippet
|
|
347
|
+
next line << snippet if Osc === snippet
|
|
327
348
|
|
|
328
349
|
# Word:
|
|
329
|
-
line << snippet
|
|
330
350
|
size += snippet.size
|
|
351
|
+
line << snippet
|
|
331
352
|
end
|
|
332
353
|
nil
|
|
333
354
|
end
|
|
@@ -335,9 +356,10 @@ module Terminal
|
|
|
335
356
|
def as_snippets(text, bbcode, ansi, ignore_newline, word_class)
|
|
336
357
|
ret = []
|
|
337
358
|
last = nil
|
|
359
|
+
to_s = bbcode ? ->(s) { Ansi.bbcode(s) } : :to_s.to_proc
|
|
338
360
|
text.each do |txt|
|
|
339
|
-
if (txt =
|
|
340
|
-
next ret[-1] = last = :hard_nl if last
|
|
361
|
+
if (txt = to_s[txt]).empty?
|
|
362
|
+
next ret[-1] = last = :hard_nl if Symbol === last
|
|
341
363
|
next ret << (last = :hard_nl)
|
|
342
364
|
end
|
|
343
365
|
|
|
@@ -345,15 +367,15 @@ module Terminal
|
|
|
345
367
|
|
|
346
368
|
txt.scan(@scan_snippet) do |nl, csi, osc, space, gc|
|
|
347
369
|
if gc
|
|
348
|
-
next last.add(gc, char_width(gc)) if last
|
|
370
|
+
next last.add(gc, char_width(gc)) if word_class === last
|
|
349
371
|
next ret << (last = word_class.new(gc, char_width(gc)))
|
|
350
372
|
end
|
|
351
373
|
|
|
352
|
-
next
|
|
374
|
+
next Symbol === last ? nil : ret << (last = :space) if space
|
|
353
375
|
|
|
354
376
|
if nl
|
|
355
377
|
if ignore_newline # handle nl like space
|
|
356
|
-
next
|
|
378
|
+
next Symbol === last ? nil : ret << (last = :space)
|
|
357
379
|
end
|
|
358
380
|
next last == :space ? ret[-1] = last = :nl : ret << (last = :nl)
|
|
359
381
|
end
|
|
@@ -366,11 +388,10 @@ module Terminal
|
|
|
366
388
|
next last == CsiEnd ? nil : ret << (last = CsiEnd)
|
|
367
389
|
end
|
|
368
390
|
|
|
369
|
-
|
|
391
|
+
Csi === last ? last.add(csi) : ret << (last = Csi.new(csi))
|
|
370
392
|
end
|
|
371
393
|
|
|
372
|
-
|
|
373
|
-
ret << (last = :hard_nl)
|
|
394
|
+
Symbol === last ? ret[-1] = last = :hard_nl : ret << (last = :hard_nl)
|
|
374
395
|
end
|
|
375
396
|
ret
|
|
376
397
|
end
|
|
@@ -378,9 +399,7 @@ module Terminal
|
|
|
378
399
|
|
|
379
400
|
class Osc
|
|
380
401
|
attr_reader :to_str, :size
|
|
381
|
-
alias _to_s to_s
|
|
382
402
|
alias to_s to_str
|
|
383
|
-
def inspect = "#{_to_s.chop} #{@to_str.inspect}>"
|
|
384
403
|
|
|
385
404
|
def initialize(str)
|
|
386
405
|
@to_str = str
|
|
@@ -402,9 +421,7 @@ module Terminal
|
|
|
402
421
|
|
|
403
422
|
class Word
|
|
404
423
|
attr_reader :to_str, :size
|
|
405
|
-
alias _to_s to_s
|
|
406
424
|
alias to_s to_str
|
|
407
|
-
def inspect = "#{_to_s.chop} #{@size}:#{@to_str.inspect}>"
|
|
408
425
|
|
|
409
426
|
def initialize(char, size)
|
|
410
427
|
@to_str = char.dup
|
|
@@ -461,42 +478,49 @@ module Terminal
|
|
|
461
478
|
| (\X)
|
|
462
479
|
)/x
|
|
463
480
|
|
|
464
|
-
@ctrlchar_width =
|
|
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
|
-
|
|
481
|
+
@ctrlchar_width =
|
|
482
|
+
Hash
|
|
483
|
+
.new(2)
|
|
484
|
+
.compare_by_identity
|
|
485
|
+
.merge!(
|
|
486
|
+
0x00 => 0,
|
|
487
|
+
0x01 => 1,
|
|
488
|
+
0x02 => 1,
|
|
489
|
+
0x03 => 1,
|
|
490
|
+
0x04 => 1,
|
|
491
|
+
0x05 => 0,
|
|
492
|
+
0x06 => 1,
|
|
493
|
+
0x07 => 0,
|
|
494
|
+
0x08 => 0,
|
|
495
|
+
0x09 => 8,
|
|
496
|
+
0x0a => 0,
|
|
497
|
+
0x0b => 0,
|
|
498
|
+
0x0c => 0,
|
|
499
|
+
0x0d => 0,
|
|
500
|
+
0x0e => 0,
|
|
501
|
+
0x0f => 0,
|
|
502
|
+
0x10 => 1,
|
|
503
|
+
0x11 => 1,
|
|
504
|
+
0x12 => 1,
|
|
505
|
+
0x13 => 1,
|
|
506
|
+
0x14 => 1,
|
|
507
|
+
0x15 => 1,
|
|
508
|
+
0x16 => 1,
|
|
509
|
+
0x17 => 1,
|
|
510
|
+
0x18 => 1,
|
|
511
|
+
0x19 => 1,
|
|
512
|
+
0x1a => 1,
|
|
513
|
+
0x1b => 1,
|
|
514
|
+
0x1c => 1,
|
|
515
|
+
0x1d => 1,
|
|
516
|
+
0x1e => 1,
|
|
517
|
+
0x1f => 1
|
|
518
|
+
)
|
|
519
|
+
.freeze
|
|
520
|
+
|
|
521
|
+
cw_file = "#{__dir__}/text/char_width.rb"
|
|
522
|
+
autoload :CharWidth, cw_file
|
|
523
|
+
autoload :UNICODE_VERSION, cw_file
|
|
500
524
|
|
|
501
525
|
private_constant :Osc, :Csi, :CsiEnd, :Word, :WordEx, :CharWidth
|
|
502
526
|
end
|
data/lib/terminal/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: terminal_rb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.19.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mike Blumtritt
|
|
@@ -55,7 +55,7 @@ licenses:
|
|
|
55
55
|
metadata:
|
|
56
56
|
source_code_uri: https://codeberg.org/mblumtritt/Terminal.rb
|
|
57
57
|
bug_tracker_uri: https://codeberg.org/mblumtritt/Terminal.rb/issues
|
|
58
|
-
documentation_uri: https://rubydoc.info/gems/terminal_rb/0.
|
|
58
|
+
documentation_uri: https://rubydoc.info/gems/terminal_rb/0.19.0
|
|
59
59
|
rubygems_mfa_required: 'true'
|
|
60
60
|
yard.run: yard
|
|
61
61
|
rdoc_options: []
|
|
@@ -72,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
72
72
|
- !ruby/object:Gem::Version
|
|
73
73
|
version: '0'
|
|
74
74
|
requirements: []
|
|
75
|
-
rubygems_version: 4.0.
|
|
75
|
+
rubygems_version: 4.0.4
|
|
76
76
|
specification_version: 4
|
|
77
77
|
summary: Fast terminal access with ANSI, CSIu, mouse events, BBCode, word-wise line
|
|
78
78
|
break support and much more.
|