YkLib 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +34 -0
- data/LICENSE.txt +21 -0
- data/README.md +44 -0
- data/Rakefile +6 -0
- data/YkLib.gemspec +29 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/YkLib/Yk/__advance__.rb +151 -0
- data/lib/YkLib/Yk/__defun__.rb +44 -0
- data/lib/YkLib/Yk/__hook__.rb +244 -0
- data/lib/YkLib/Yk/__minmax__.rb +123 -0
- data/lib/YkLib/Yk/__stdlog.rb +329 -0
- data/lib/YkLib/Yk/adhocLiterals/email.rb +119 -0
- data/lib/YkLib/Yk/adhocLiterals/path.rb +402 -0
- data/lib/YkLib/Yk/adhocLiterals/tag.rb +19 -0
- data/lib/YkLib/Yk/adhocLiterals/url.rb +36 -0
- data/lib/YkLib/Yk/adhocLiterals.rb +199 -0
- data/lib/YkLib/Yk/auto_escseq.rb +5 -0
- data/lib/YkLib/Yk/auto_pstore.rb +179 -0
- data/lib/YkLib/Yk/bsearch.rb +120 -0
- data/lib/YkLib/Yk/clambda.rb +309 -0
- data/lib/YkLib/Yk/confLine.rb +423 -0
- data/lib/YkLib/Yk/create_tty_width_available.rb +24 -0
- data/lib/YkLib/Yk/crypt.rb +26 -0
- data/lib/YkLib/Yk/debug2 +1 -0
- data/lib/YkLib/Yk/debug2.rb +473 -0
- data/lib/YkLib/Yk/debugout.rb +139 -0
- data/lib/YkLib/Yk/email_tz.rb +533 -0
- data/lib/YkLib/Yk/enum_expect.rb +170 -0
- data/lib/YkLib/Yk/errlog.rb +5 -0
- data/lib/YkLib/Yk/escseq.rb +59 -0
- data/lib/YkLib/Yk/eval_alt.rb +281 -0
- data/lib/YkLib/Yk/expector.rb +93 -0
- data/lib/YkLib/Yk/fetch.rb +556 -0
- data/lib/YkLib/Yk/fetch_old.rb +290 -0
- data/lib/YkLib/Yk/fib.rb +158 -0
- data/lib/YkLib/Yk/file_aux.rb +843 -0
- data/lib/YkLib/Yk/file_aux2.rb +919 -0
- data/lib/YkLib/Yk/file_aux_old.rb +160 -0
- data/lib/YkLib/Yk/filemod.rb +19 -0
- data/lib/YkLib/Yk/force_escseq.rb +3 -0
- data/lib/YkLib/Yk/generator__.rb +144 -0
- data/lib/YkLib/Yk/generator__.rb.org +139 -0
- data/lib/YkLib/Yk/indenter/argless_case.rb +46 -0
- data/lib/YkLib/Yk/indenter/each_token.rb +671 -0
- data/lib/YkLib/Yk/indenter/free_case.rb +313 -0
- data/lib/YkLib/Yk/indenter/if_less.rb +53 -0
- data/lib/YkLib/Yk/indenter/independent_ensure.rb +23 -0
- data/lib/YkLib/Yk/indenter/independent_rescue.rb +23 -0
- data/lib/YkLib/Yk/indenter/operand_circumflex.rb +0 -0
- data/lib/YkLib/Yk/indenter/operand_period.rb +16 -0
- data/lib/YkLib/Yk/indenter/parenless_and.rb +37 -0
- data/lib/YkLib/Yk/indenter/post_test.rb +48 -0
- data/lib/YkLib/Yk/indenter/token.rb +1525 -0
- data/lib/YkLib/Yk/indenter.rb +1382 -0
- data/lib/YkLib/Yk/inot.rb +265 -0
- data/lib/YkLib/Yk/intf.rb +815 -0
- data/lib/YkLib/Yk/io_aux.rb +1332 -0
- data/lib/YkLib/Yk/ioctl.rb +60 -0
- data/lib/YkLib/Yk/ipcc.rb +87 -0
- data/lib/YkLib/Yk/ipcountry.rb +207 -0
- data/lib/YkLib/Yk/ipv4adr.rb +318 -0
- data/lib/YkLib/Yk/localmail.rb +276 -0
- data/lib/YkLib/Yk/method_chain.rb +359 -0
- data/lib/YkLib/Yk/misc_tz.rb +1716 -0
- data/lib/YkLib/Yk/missing_method.rb +50 -0
- data/lib/YkLib/Yk/mojiConv.rb +257 -0
- data/lib/YkLib/Yk/nostdlog.rb +4 -0
- data/lib/YkLib/Yk/on_marshal.rb +20 -0
- data/lib/YkLib/Yk/overrider.rb +47 -0
- data/lib/YkLib/Yk/path.rb +293 -0
- data/lib/YkLib/Yk/path_aux.rb +883 -0
- data/lib/YkLib/Yk/path_aux_alt.rb +0 -0
- data/lib/YkLib/Yk/path_rep.rb +1267 -0
- data/lib/YkLib/Yk/pg_setup.rb +917 -0
- data/lib/YkLib/Yk/procinfo.rb +314 -0
- data/lib/YkLib/Yk/proclist.rb +492 -0
- data/lib/YkLib/Yk/property.rb +863 -0
- data/lib/YkLib/Yk/ranger.rb +606 -0
- data/lib/YkLib/Yk/resolv_tz.rb +88 -0
- data/lib/YkLib/Yk/rlprompt.rb +73 -0
- data/lib/YkLib/Yk/rootexec.rb +48 -0
- data/lib/YkLib/Yk/rpm-packageproxy.rb +784 -0
- data/lib/YkLib/Yk/rpm-packageproxy2.rb +1430 -0
- data/lib/YkLib/Yk/rwhen.rb +21 -0
- data/lib/YkLib/Yk/selector.rb +124 -0
- data/lib/YkLib/Yk/set.rb +170 -0
- data/lib/YkLib/Yk/shellquote.rb +300 -0
- data/lib/YkLib/Yk/sio.rb +1001 -0
- data/lib/YkLib/Yk/sio0.rb +835 -0
- data/lib/YkLib/Yk/sio_aux.rb +1524 -0
- data/lib/YkLib/Yk/sio_inot.rb +86 -0
- data/lib/YkLib/Yk/sock_aux.rb +42 -0
- data/lib/YkLib/Yk/spipe.rb +843 -0
- data/lib/YkLib/Yk/sql_table.rb +565 -0
- data/lib/YkLib/Yk/stdlog.rb +4 -0
- data/lib/YkLib/Yk/syscommand.rb +173 -0
- data/lib/YkLib/Yk/sysinit.rb +75 -0
- data/lib/YkLib/Yk/ttyFontWidth.rb +46113 -0
- data/lib/YkLib/Yk/tty_char.dump +0 -0
- data/lib/YkLib/Yk/tty_char.rb +47 -0
- data/lib/YkLib/Yk/tty_char_create.rb +437031 -0
- data/lib/YkLib/Yk/tty_char_static.rb +437016 -0
- data/lib/YkLib/Yk/tty_rewrite.rb +142 -0
- data/lib/YkLib/Yk/tty_str.rb +461 -0
- data/lib/YkLib/Yk/tty_width.dat.rb +114 -0
- data/lib/YkLib/Yk/tty_width.rb +180 -0
- data/lib/YkLib/Yk/tty_width_available +569 -0
- data/lib/YkLib/Yk/tty_width_list +0 -0
- data/lib/YkLib/Yk/tty_width_list.linux +280 -0
- data/lib/YkLib/Yk/tty_width_list.windows +324 -0
- data/lib/YkLib/Yk/tz_tty +0 -0
- data/lib/YkLib/Yk/tz_tty.rb +0 -0
- data/lib/YkLib/Yk/uprepos.rb +94 -0
- data/lib/YkLib/Yk/userinfo.rb +91 -0
- data/lib/YkLib/Yk/with.rb +109 -0
- data/lib/YkLib/version.rb +3 -0
- data/lib/YkLib.rb +6 -0
- metadata +170 -0
@@ -0,0 +1,142 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "pty"
|
4
|
+
require "Yk/io_aux"
|
5
|
+
require "Yk/path_aux"
|
6
|
+
require "Yk/selector"
|
7
|
+
|
8
|
+
|
9
|
+
module TtyRewrite
|
10
|
+
def handleIO (arr, bl)
|
11
|
+
if bl
|
12
|
+
begin
|
13
|
+
t = Process.detach arr[0].pid
|
14
|
+
t2 = Thread.new do
|
15
|
+
t.join
|
16
|
+
arr[0].close
|
17
|
+
if arr[0].respond_to? :selectors
|
18
|
+
arr[0].selectors.each do |s|
|
19
|
+
s.int
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
ret = bl.call *arr
|
24
|
+
t2.join
|
25
|
+
ret = !$?.exitstatus ? nil : $?.exitstatus == 0
|
26
|
+
ensure
|
27
|
+
arr.each do |e|
|
28
|
+
e.closed? || e.close
|
29
|
+
end
|
30
|
+
end
|
31
|
+
ret
|
32
|
+
else
|
33
|
+
arr
|
34
|
+
end
|
35
|
+
end
|
36
|
+
def pty_spawn3 (*args, &bl)
|
37
|
+
mio = nil
|
38
|
+
args.delete_if do |s|
|
39
|
+
if s.is_a? IO
|
40
|
+
mio = s
|
41
|
+
true
|
42
|
+
else
|
43
|
+
false
|
44
|
+
end
|
45
|
+
end
|
46
|
+
#if !mio.tty? || (CYGWIN || "/dev/" + `ps -p #{$$} -o tty`.split[1] != "/proc/#{$$}/fd/#{mio.to_i}".readlink)
|
47
|
+
# mio = nil
|
48
|
+
#else
|
49
|
+
stty = `stty -g`
|
50
|
+
#end
|
51
|
+
fp, slave = PTY.open
|
52
|
+
if fp
|
53
|
+
Exception.new("cannot allocate pseudo tty")
|
54
|
+
end
|
55
|
+
pid = fork do
|
56
|
+
Process.setsid
|
57
|
+
#Process.setpgrp
|
58
|
+
fq = File.open pty.slave, "rw"
|
59
|
+
fq.reopen fqFile
|
60
|
+
if mio
|
61
|
+
fq.attr = mio.attr
|
62
|
+
fq.winsz = mio.winsz
|
63
|
+
end
|
64
|
+
STDIN.reopen fq
|
65
|
+
STDOUT.reopen fq
|
66
|
+
STDERR.reopen fq
|
67
|
+
if stty
|
68
|
+
system "stty #{stty}"
|
69
|
+
end
|
70
|
+
fq.close
|
71
|
+
fp.close
|
72
|
+
exec *args
|
73
|
+
end
|
74
|
+
trap :WINCH do
|
75
|
+
fp.winsz = STDIN.winsz
|
76
|
+
Process.kill :WINCH, pid
|
77
|
+
end
|
78
|
+
fp.__defun__ :pid, pid
|
79
|
+
handleIO [fp], bl
|
80
|
+
end
|
81
|
+
module_function :handleIO, :pty_spawn3
|
82
|
+
end
|
83
|
+
|
84
|
+
#STDIN.set_raw do
|
85
|
+
# t1 = fp.transfer_to STDOUT
|
86
|
+
# t2 = STDIN.transfer_to fp
|
87
|
+
# t1.join
|
88
|
+
# t2.join
|
89
|
+
#end
|
90
|
+
|
91
|
+
# trap SIGWINCH ?ƃV?O?i???̓]???B
|
92
|
+
|
93
|
+
class String
|
94
|
+
def tty_rewrite &bl
|
95
|
+
[self].tty_rewrite &bl
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
class Array
|
101
|
+
def tty_rewrite
|
102
|
+
TtyRewrite.pty_spawn3 STDIN, *self do |fp|
|
103
|
+
STDIN.set_raw do
|
104
|
+
Selector.select do |s|
|
105
|
+
s.at_read STDIN do |buff|
|
106
|
+
buff == "" && closing = true
|
107
|
+
yield buff, "r", fp.pid
|
108
|
+
s.reserve_write fp, buff
|
109
|
+
if closing
|
110
|
+
s.reserve_write fp, nil
|
111
|
+
end
|
112
|
+
end
|
113
|
+
s.at_read fp do |buff|
|
114
|
+
buff == "" && closing = true
|
115
|
+
yield buff, "w", fp.pid
|
116
|
+
s.reserve_write STDOUT, buff
|
117
|
+
if closing
|
118
|
+
s.reserve_write STDOUT, nil
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
|
128
|
+
if __FILE__.expand_path == $0.expand_path
|
129
|
+
def main
|
130
|
+
ARGV.tty_rewrite do |buff, mode|
|
131
|
+
case mode
|
132
|
+
when "r"
|
133
|
+
|
134
|
+
when "w"
|
135
|
+
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
main
|
140
|
+
end
|
141
|
+
|
142
|
+
|
@@ -0,0 +1,461 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
|
4
|
+
require 'Yk/tty_char'
|
5
|
+
|
6
|
+
|
7
|
+
class TZWhen
|
8
|
+
def self.& obj
|
9
|
+
new obj
|
10
|
+
end
|
11
|
+
def initialize obj
|
12
|
+
@args = []
|
13
|
+
if obj.is_a? Symbol
|
14
|
+
@mname = obj
|
15
|
+
else
|
16
|
+
@obj = obj
|
17
|
+
end
|
18
|
+
end
|
19
|
+
def & ag
|
20
|
+
if !@obj
|
21
|
+
@obj = ag
|
22
|
+
else
|
23
|
+
(@args ||= []).push ag
|
24
|
+
end
|
25
|
+
return self
|
26
|
+
end
|
27
|
+
def === carg
|
28
|
+
if !@obj
|
29
|
+
carg.method(@mname).call *@args
|
30
|
+
elsif @mname
|
31
|
+
args = []
|
32
|
+
@args.each do |e|
|
33
|
+
if e == :_1
|
34
|
+
args.push carg
|
35
|
+
else
|
36
|
+
args.push e
|
37
|
+
end
|
38
|
+
end
|
39
|
+
@obj.method(@mname).call(*args)
|
40
|
+
else
|
41
|
+
raise Exception("unbound method")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
class String
|
48
|
+
class SGRStat
|
49
|
+
Reset = "\x1b[0m\x1b[39m\x1b[49m"
|
50
|
+
def << code
|
51
|
+
while code =~ /((((3|4)8);(5;\d+|2;\d+;\d+;\d+))|(\d+))($|;)/
|
52
|
+
tcCmd, cmd, code = $2, $6 ? $6.to_i : $3.to_i, $'
|
53
|
+
case cmd
|
54
|
+
when 0
|
55
|
+
@bold = nil
|
56
|
+
@thin = nil
|
57
|
+
@italic = nil
|
58
|
+
@underline = nil
|
59
|
+
@blink = nil
|
60
|
+
@reverse = nil
|
61
|
+
@hidden = nil
|
62
|
+
@strike = nil
|
63
|
+
@fgColor = nil
|
64
|
+
@bgColor = nil
|
65
|
+
when 1
|
66
|
+
@bold = true
|
67
|
+
when 2
|
68
|
+
@thin = true
|
69
|
+
when 3
|
70
|
+
@italic = true
|
71
|
+
when 4
|
72
|
+
@underline = true
|
73
|
+
when 5
|
74
|
+
@blink = :on
|
75
|
+
when 6
|
76
|
+
@blink = :quick
|
77
|
+
when 7
|
78
|
+
@reverse = true
|
79
|
+
when 8
|
80
|
+
@hidden = true
|
81
|
+
when 9
|
82
|
+
@strike = true
|
83
|
+
when 30 .. 37
|
84
|
+
@fgColor = code % 30
|
85
|
+
when 38
|
86
|
+
@fgColor = tCmd
|
87
|
+
when 39
|
88
|
+
@fgColor = -1
|
89
|
+
when 40 .. 47
|
90
|
+
@bgColor = code % 30
|
91
|
+
when 48
|
92
|
+
@bgColor = tCmd
|
93
|
+
when 49
|
94
|
+
@bgColor = -1
|
95
|
+
when 90 .. 97
|
96
|
+
@fgColor = code % 90 + 10
|
97
|
+
when 100 .. 107
|
98
|
+
@bgColor = code % 100 + 10
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
def restart
|
103
|
+
cmds = []
|
104
|
+
@bold && cmds.push(1)
|
105
|
+
@thin && cmds.push(2)
|
106
|
+
@italic && cmds.push(3)
|
107
|
+
@underline && cmds.push(4)
|
108
|
+
case @blink
|
109
|
+
when :on
|
110
|
+
cmds.push(5)
|
111
|
+
when :quick
|
112
|
+
cmds.push(6)
|
113
|
+
end
|
114
|
+
@reverse && cmds.push(7)
|
115
|
+
@hidden && cmds.push(8)
|
116
|
+
@strike && cmds.push(9)
|
117
|
+
case @fgColor
|
118
|
+
when 0..7
|
119
|
+
cmds.push(@fgColor + 30)
|
120
|
+
when 10..17
|
121
|
+
cmds.push(@fgColor + 80)
|
122
|
+
when -1
|
123
|
+
cmds.push(39)
|
124
|
+
when nil
|
125
|
+
else
|
126
|
+
cmds.push(38, *@fgColor.split(/;/))
|
127
|
+
end
|
128
|
+
case @bgColor
|
129
|
+
when 0..7
|
130
|
+
cmds.push(@bgColor + 40)
|
131
|
+
when 10..17
|
132
|
+
cmds.push(@bgColor + 90)
|
133
|
+
when -1
|
134
|
+
cmds.push(49)
|
135
|
+
when nil
|
136
|
+
else
|
137
|
+
cmds.push(48, *@bgColor.split(/;/))
|
138
|
+
end
|
139
|
+
"\x1b[#{cmds.map{|e| e.to_s}.join(';')}m"
|
140
|
+
end
|
141
|
+
end
|
142
|
+
def String.tty_char_width c
|
143
|
+
->{
|
144
|
+
if c.size > 1
|
145
|
+
if c[0] == "\x1b"
|
146
|
+
return 0 # escape sequence
|
147
|
+
else
|
148
|
+
raise Exception("is not one character")
|
149
|
+
end
|
150
|
+
end
|
151
|
+
a = TTYChar::Alt[c]
|
152
|
+
if a
|
153
|
+
a.size
|
154
|
+
else
|
155
|
+
TTYChar::Width[c]
|
156
|
+
end
|
157
|
+
}[] || '\u{' + c.ord.to_s(16) + '}'.size
|
158
|
+
end
|
159
|
+
def tty_alt
|
160
|
+
->{
|
161
|
+
a = TTYChar::Alt[self]
|
162
|
+
if a
|
163
|
+
a
|
164
|
+
elsif TTYChar::Width[self]
|
165
|
+
self
|
166
|
+
end
|
167
|
+
}[] || '\u{' + ord.to_s(16) + '}'
|
168
|
+
end
|
169
|
+
class TTYPos
|
170
|
+
def initialize buff, locOrTopTTYPos
|
171
|
+
end
|
172
|
+
def slice! #entityの場合、後続のアクサンを削除
|
173
|
+
end
|
174
|
+
def set pos
|
175
|
+
end
|
176
|
+
def < arg
|
177
|
+
end
|
178
|
+
def <= arg
|
179
|
+
end
|
180
|
+
def > arg
|
181
|
+
end
|
182
|
+
def >= arg
|
183
|
+
end
|
184
|
+
def +
|
185
|
+
end
|
186
|
+
def -
|
187
|
+
end
|
188
|
+
def move_tty_size
|
189
|
+
end
|
190
|
+
def set_at_entity pos
|
191
|
+
end
|
192
|
+
def tty_location
|
193
|
+
end
|
194
|
+
end
|
195
|
+
def is_combining?
|
196
|
+
TTYChar::Width[self] == 0
|
197
|
+
end
|
198
|
+
def is_attribute?
|
199
|
+
self =~ /^\x1b\[(\d+(;\d+)*)m$/
|
200
|
+
end
|
201
|
+
def is_escseq?
|
202
|
+
self =~ /\x1b(\[(\d+(;\d+)*|)([^\d;])|[O#()].|.)$/
|
203
|
+
end
|
204
|
+
def is_combinable?
|
205
|
+
if size == 1
|
206
|
+
ord = self.ord
|
207
|
+
if ord < 0x20 || (0x7f <= ord && ord <= 0x80) || org == 0xad
|
208
|
+
return false
|
209
|
+
end
|
210
|
+
if TTYChar::Width[self] == 1 || TTYChar::Width[self] == 2
|
211
|
+
return true
|
212
|
+
end
|
213
|
+
end
|
214
|
+
return false
|
215
|
+
end
|
216
|
+
def tty_width tabstop = 8
|
217
|
+
ret = 0
|
218
|
+
escRemoved = self.gsub /\x1b(\[(\d+(;\d+)*|)([^\d;])|[O#()].|.)/, ""
|
219
|
+
escRemoved.each_char do |c|
|
220
|
+
case c
|
221
|
+
when "\t"
|
222
|
+
ret = (ret.div tabstop) * tabstop
|
223
|
+
else
|
224
|
+
ret += TTYChar::Width[c]
|
225
|
+
end
|
226
|
+
end
|
227
|
+
ret
|
228
|
+
end
|
229
|
+
def tty_len range
|
230
|
+
tty_each do |c|
|
231
|
+
|
232
|
+
end
|
233
|
+
end
|
234
|
+
def tty_substr range
|
235
|
+
|
236
|
+
end
|
237
|
+
def _tty_width
|
238
|
+
ret = 0
|
239
|
+
escRemoved = self.gsub /\x1b(\[(\d+(;\d+)*|)([^\d;])|[O#()].|.)/, ""
|
240
|
+
escRemoved.each do |c|
|
241
|
+
ret += TTYChar::Width[c]
|
242
|
+
end
|
243
|
+
ret
|
244
|
+
end
|
245
|
+
def tty_slice! w
|
246
|
+
i = 0
|
247
|
+
each do |c|
|
248
|
+
cw = TTYChar::Width[c]
|
249
|
+
if w - cw < 0
|
250
|
+
break
|
251
|
+
end
|
252
|
+
i += 1
|
253
|
+
end
|
254
|
+
slice!(0...i)
|
255
|
+
end
|
256
|
+
class LetterDivider
|
257
|
+
def initialize &bl
|
258
|
+
@buff = ""
|
259
|
+
@block = bl
|
260
|
+
@gs = GStat.new
|
261
|
+
end
|
262
|
+
def flush
|
263
|
+
return if !@char
|
264
|
+
lmode = case @char
|
265
|
+
when " "
|
266
|
+
@forceLetter ? :non_space : :space
|
267
|
+
when "\t"
|
268
|
+
:tab
|
269
|
+
when TZWhen & "`'\"([{「『({〔[【‘“《〈‹«" & :include?
|
270
|
+
:no_last
|
271
|
+
when TZWhen & " 、。,.・:;!?」』)}〕]】!?%)\]},.:;'\"`’”》〉›»" & :include?
|
272
|
+
:no_first
|
273
|
+
else
|
274
|
+
:non_space
|
275
|
+
end
|
276
|
+
@block[@buff, @char, lmode, @gs]
|
277
|
+
@char = nil
|
278
|
+
@forceLetter = false
|
279
|
+
true
|
280
|
+
end
|
281
|
+
def << c
|
282
|
+
if c.is_combining?
|
283
|
+
if !@char || (!@char.is_combinable? && flush)
|
284
|
+
@char = " "
|
285
|
+
@buff += " "
|
286
|
+
end
|
287
|
+
@buff += c
|
288
|
+
@forceLetter = true
|
289
|
+
elsif c.is_attribute?
|
290
|
+
@buff += c
|
291
|
+
@gs << c
|
292
|
+
@gs = @gs.clone
|
293
|
+
elsif !c.is_escseq?
|
294
|
+
if @char
|
295
|
+
flush
|
296
|
+
else
|
297
|
+
@char = c
|
298
|
+
@buff += c
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
302
|
+
def close
|
303
|
+
flush if @char
|
304
|
+
end
|
305
|
+
end
|
306
|
+
NSPC = /[^ \t]/
|
307
|
+
NFST = /[^ 、。,.・:;!?」』)}〕]】!?%)\]},.:;'\"`’”》〉›»]/
|
308
|
+
NLST = /[^`'"(\[{「『({〔[【‘“《〈‹«]/
|
309
|
+
def tty_each_word
|
310
|
+
ret = ""
|
311
|
+
c = nil
|
312
|
+
last_char = nil
|
313
|
+
last_lmode = nil
|
314
|
+
last_gs = nil
|
315
|
+
ld = LetterDivider.new do |c, char, lmode, gs|
|
316
|
+
case Match::Tuple[last_char, char]
|
317
|
+
when [nil, /\w/], [/(\.|\-|\w)/, /\w/], [/\d/, /(\.|\-)/]
|
318
|
+
ret += c
|
319
|
+
else
|
320
|
+
case [last_mode, mode]
|
321
|
+
when [:non_space, :no_first], [:no_last, :non_space]
|
322
|
+
ret += c
|
323
|
+
else
|
324
|
+
yield ret, last_lmode, last_gs if ret != ""
|
325
|
+
ret.replace c
|
326
|
+
end
|
327
|
+
end
|
328
|
+
last_char = char
|
329
|
+
last_gs = gs
|
330
|
+
last_lmode = lmode
|
331
|
+
end
|
332
|
+
while res =~ /\x1b(\[(\d+(;\d+)*|)([^\d;])|[O#()].|.)/
|
333
|
+
c, nres = $&, $'
|
334
|
+
ld << c
|
335
|
+
end
|
336
|
+
yield ret, last_lmode, last_gs if ret != ""
|
337
|
+
end
|
338
|
+
def tty_each_line width, tabstop = 8, &bl
|
339
|
+
_tty_line width width, tabstop, &bl
|
340
|
+
end
|
341
|
+
def tty_line width, tabstop = 8
|
342
|
+
_tty_line width width, tabstop
|
343
|
+
end
|
344
|
+
def _tty_line width, tabstop = 8, &bl #block is needed if print multiline
|
345
|
+
ln = ""
|
346
|
+
isMultiLine = false
|
347
|
+
pos = 0
|
348
|
+
tty_each_word do |w, lmode, gs|
|
349
|
+
case lmode
|
350
|
+
when :tab
|
351
|
+
newPos = (pos.div tabstop) * tabstop
|
352
|
+
if newPos > width
|
353
|
+
ln += w.sub("\t", " " * (width - pos))
|
354
|
+
pos = width
|
355
|
+
else
|
356
|
+
ln += w.sub("\t", " " * (newPos - pos))
|
357
|
+
pos = newPos
|
358
|
+
end
|
359
|
+
when :space
|
360
|
+
if isMultiLine && pos == 0
|
361
|
+
ln += w.sub(" ", "")
|
362
|
+
next
|
363
|
+
end
|
364
|
+
else
|
365
|
+
newPos = pos + w._tty_width
|
366
|
+
if newPos > width
|
367
|
+
if pos > 0
|
368
|
+
ln += " " * (width - pos)
|
369
|
+
pos = 0
|
370
|
+
else
|
371
|
+
sliced = w.tty_slice!(width)
|
372
|
+
if sliced != ""
|
373
|
+
ln += sliced
|
374
|
+
end
|
375
|
+
end
|
376
|
+
if bl
|
377
|
+
bl.call ln + SGRStat::Reset
|
378
|
+
isMultiLine = true
|
379
|
+
else
|
380
|
+
return ln + SGRStat::Reset
|
381
|
+
end
|
382
|
+
ln.replace gs.restart
|
383
|
+
redo
|
384
|
+
else
|
385
|
+
ln += w
|
386
|
+
end
|
387
|
+
end
|
388
|
+
if pos >= width
|
389
|
+
if bl
|
390
|
+
bl.call ln + SGRStat::Reset
|
391
|
+
isMultiLine = true
|
392
|
+
else
|
393
|
+
return ln + SGRStat::Reset
|
394
|
+
end
|
395
|
+
ln.replace gs.restart
|
396
|
+
pos = 0
|
397
|
+
end
|
398
|
+
end
|
399
|
+
if bl
|
400
|
+
bl.call ln + SGRStat::Reset if ln != ""
|
401
|
+
else
|
402
|
+
return ln + SGRStat::Reset
|
403
|
+
end
|
404
|
+
end
|
405
|
+
InputConv = {
|
406
|
+
"\x1b[A" => :up,
|
407
|
+
"\x1b[B" => :down,
|
408
|
+
"\x1b[C" => :right,
|
409
|
+
"\x1b[D" => :left,
|
410
|
+
"\x1b[5~" => :pgaeUp,
|
411
|
+
"\x1b[6~" => :pgaeDown,
|
412
|
+
"\x1b[H" => :home,
|
413
|
+
"\x1b[F" => :end,
|
414
|
+
"\x1b[3" => :del,
|
415
|
+
"\x7f" => :bs,
|
416
|
+
"\r" => :enter,
|
417
|
+
"\x1bOR" => :f3,
|
418
|
+
"\x1b[1;2R" => :F3,
|
419
|
+
"\x1b" => :esc,
|
420
|
+
"\u0003" => :INT
|
421
|
+
}
|
422
|
+
def tty_each
|
423
|
+
res = self
|
424
|
+
while res =~ /^(\x1b(\[(\d+(;\d+)*|)([^\d;])|[O#()].|.)|.)/
|
425
|
+
yield $&
|
426
|
+
res = $'
|
427
|
+
end
|
428
|
+
end
|
429
|
+
def tty_each_input
|
430
|
+
res = self
|
431
|
+
while res =~ /^(\x1b(\[(\d+(;\d+)*|)([^\d;])|[O#()].|.)|.)/
|
432
|
+
c = $&
|
433
|
+
cv = InputConv[c]
|
434
|
+
if !cv && (c.ord < 0x20 || (0x80 <= c.ord && c.ord <= 0x9f))
|
435
|
+
cv = c.intern
|
436
|
+
end
|
437
|
+
yield cv || c
|
438
|
+
res = $'
|
439
|
+
end
|
440
|
+
end
|
441
|
+
end
|
442
|
+
|
443
|
+
|
444
|
+
if __FILE__ == $0
|
445
|
+
require 'Yk/fib'
|
446
|
+
require 'Yk/path_aux'
|
447
|
+
require 'Yk/debug2'
|
448
|
+
Fib.spawn do
|
449
|
+
"/proc/#{$$}/fd/0".readlink.open "rw" do |fp|
|
450
|
+
fp.set_raw
|
451
|
+
buff = ""
|
452
|
+
loop do
|
453
|
+
c = Fib.read fp, buff
|
454
|
+
buff.tty_each_input do |c|
|
455
|
+
print c.inspect + "\r\n"
|
456
|
+
end
|
457
|
+
end
|
458
|
+
end
|
459
|
+
end
|
460
|
+
end
|
461
|
+
|
@@ -0,0 +1,114 @@
|
|
1
|
+
[0x0000, -1], [0x0020, 1], [0x007f, -1], [0x009b, -1], [0x009c, -1],
|
2
|
+
[0x00a0, 1], [0x00a7, -1], [0x00a9, 1], [0x00b0, -1], [0x00b2, 1],
|
3
|
+
[0x00b4, -1], [0x00b5, 1], [0x00b6, -1], [0x00b7, 1], [0x00d7, -1],
|
4
|
+
[0x00d8, 1], [0x00f7, -1], [0x00f8, 1], [0x01ce, -1], [0x01cf, 1],
|
5
|
+
[0x01d0, -1], [0x01d1, 1], [0x01d2, -1], [0x01d3, 1], [0x01d4, -1],
|
6
|
+
[0x01d5, 1], [0x01d6, -1], [0x01d7, 1], [0x01d8, -1], [0x01d9, 1],
|
7
|
+
[0x01da, -1], [0x01db, 1], [0x01dc, -1], [0x01dd, 1], [0x02ca, -1],
|
8
|
+
[0x02cc, 1], [0x0300, -1], [0x0370, 1], [0x0391, -1], [0x03a2, 1],
|
9
|
+
[0x03a3, -1], [0x03aa, 1], [0x03b1, -1], [0x03c2, 1], [0x03c3, -1],
|
10
|
+
[0x03ca, 1], [0x0401, -1], [0x0402, 1], [0x0410, -1], [0x0450, 1],
|
11
|
+
[0x0451, -1], [0x0452, 1], [0x0483, -1], [0x0487, 1], [0x0488, -1],
|
12
|
+
[0x048a, 1], [0x0591, -1], [0x05be, 1], [0x05bf, -1], [0x05c0, 1],
|
13
|
+
[0x05c1, -1], [0x05c3, 1], [0x05c4, -1], [0x05c6, 1], [0x05c7, -1],
|
14
|
+
[0x05c8, 1], [0x0600, -1], [0x0604, 1], [0x0610, -1], [0x0616, 1],
|
15
|
+
[0x064b, -1], [0x065f, 1], [0x0670, -1], [0x0671, 1], [0x06d6, -1],
|
16
|
+
[0x06e5, 1], [0x06e7, -1], [0x06e9, 1], [0x06ea, -1], [0x06ee, 1],
|
17
|
+
[0x070f, -1], [0x0710, 1], [0x0711, -1], [0x0712, 1], [0x0730, -1],
|
18
|
+
[0x074b, 1], [0x07a6, -1], [0x07b1, 1], [0x07eb, -1], [0x07f4, 1],
|
19
|
+
[0x0901, -1], [0x0903, 1], [0x093c, -1], [0x093d, 1], [0x0941, -1],
|
20
|
+
[0x0949, 1], [0x094d, -1], [0x094e, 1], [0x0951, -1], [0x0955, 1],
|
21
|
+
[0x0962, -1], [0x0964, 1], [0x0981, -1], [0x0982, 1], [0x09bc, -1],
|
22
|
+
[0x09bd, 1], [0x09c1, -1], [0x09c5, 1], [0x09cd, -1], [0x09ce, 1],
|
23
|
+
[0x09e2, -1], [0x09e4, 1], [0x0a01, -1], [0x0a03, 1], [0x0a3c, -1],
|
24
|
+
[0x0a3d, 1], [0x0a41, -1], [0x0a43, 1], [0x0a47, -1], [0x0a49, 1],
|
25
|
+
[0x0a4b, -1], [0x0a4e, 1], [0x0a70, -1], [0x0a72, 1], [0x0a81, -1],
|
26
|
+
[0x0a83, 1], [0x0abc, -1], [0x0abd, 1], [0x0ac1, -1], [0x0ac6, 1],
|
27
|
+
[0x0ac7, -1], [0x0ac9, 1], [0x0acd, -1], [0x0ace, 1], [0x0ae2, -1],
|
28
|
+
[0x0ae4, 1], [0x0b01, -1], [0x0b02, 1], [0x0b3c, -1], [0x0b3d, 1],
|
29
|
+
[0x0b3f, -1], [0x0b40, 1], [0x0b41, -1], [0x0b44, 1], [0x0b4d, -1],
|
30
|
+
[0x0b4e, 1], [0x0b56, -1], [0x0b57, 1], [0x0b82, -1], [0x0b83, 1],
|
31
|
+
[0x0bc0, -1], [0x0bc1, 1], [0x0bcd, -1], [0x0bce, 1], [0x0c3e, -1],
|
32
|
+
[0x0c41, 1], [0x0c46, -1], [0x0c49, 1], [0x0c4a, -1], [0x0c4e, 1],
|
33
|
+
[0x0c55, -1], [0x0c57, 1], [0x0cbc, -1], [0x0cbd, 1], [0x0cbf, -1],
|
34
|
+
[0x0cc0, 1], [0x0cc6, -1], [0x0cc7, 1], [0x0ccc, -1], [0x0cce, 1],
|
35
|
+
[0x0ce2, -1], [0x0ce4, 1], [0x0d41, -1], [0x0d44, 1], [0x0d4d, -1],
|
36
|
+
[0x0d4e, 1], [0x0dca, -1], [0x0dcb, 1], [0x0dd2, -1], [0x0dd5, 1],
|
37
|
+
[0x0dd6, -1], [0x0dd7, 1], [0x0e31, -1], [0x0e32, 1], [0x0e34, -1],
|
38
|
+
[0x0e3b, 1], [0x0e47, -1], [0x0e4f, 1], [0x0eb1, -1], [0x0eb2, 1],
|
39
|
+
[0x0eb4, -1], [0x0eba, 1], [0x0ebb, -1], [0x0ebd, 1], [0x0ec8, -1],
|
40
|
+
[0x0ece, 1], [0x0f18, -1], [0x0f1a, 1], [0x0f35, -1], [0x0f36, 1],
|
41
|
+
[0x0f37, -1], [0x0f38, 1], [0x0f39, -1], [0x0f3a, 1], [0x0f71, -1],
|
42
|
+
[0x0f7f, 1], [0x0f80, -1], [0x0f85, 1], [0x0f86, -1], [0x0f88, 1],
|
43
|
+
[0x0f90, -1], [0x0f98, 1], [0x0f99, -1], [0x0fbd, 1], [0x0fc6, -1],
|
44
|
+
[0x0fc7, 1], [0x102d, -1], [0x1031, 1], [0x1032, -1], [0x1033, 1],
|
45
|
+
[0x1036, -1], [0x1038, 1], [0x1039, -1], [0x103a, 1], [0x1058, -1],
|
46
|
+
[0x105a, 1], [0x1100, 2], [0x1160, -1], [0x1200, 1], [0x135f, -1],
|
47
|
+
[0x1360, 1], [0x1712, -1], [0x1715, 1], [0x1732, -1], [0x1735, 1],
|
48
|
+
[0x1752, -1], [0x1754, 1], [0x1772, -1], [0x1774, 1], [0x17b4, -1],
|
49
|
+
[0x17b6, 1], [0x17b7, -1], [0x17be, 1], [0x17c6, -1], [0x17c7, 1],
|
50
|
+
[0x17c9, -1], [0x17d4, 1], [0x17dd, -1], [0x17de, 1], [0x180b, -1],
|
51
|
+
[0x180e, 1], [0x18a9, -1], [0x18aa, 1], [0x1920, -1], [0x1923, 1],
|
52
|
+
[0x1927, -1], [0x1929, 1], [0x1932, -1], [0x1933, 1], [0x1939, -1],
|
53
|
+
[0x193c, 1], [0x1a17, -1], [0x1a19, 1], [0x1b00, -1], [0x1b04, 1],
|
54
|
+
[0x1b34, -1], [0x1b35, 1], [0x1b36, -1], [0x1b3b, 1], [0x1b3c, -1],
|
55
|
+
[0x1b3d, 1], [0x1b42, -1], [0x1b43, 1], [0x1b6b, -1], [0x1b74, 1],
|
56
|
+
[0x1dc0, -1], [0x1dcb, 1], [0x1dfe, -1], [0x1e00, 1], [0x200b, -1],
|
57
|
+
[0x2011, 1], [0x2015, -1], [0x2017, 1], [0x2018, -1], [0x201a, 1],
|
58
|
+
[0x201c, -1], [0x201e, 1], [0x2020, -1], [0x2022, 1], [0x2025, -1],
|
59
|
+
[0x2027, 1], [0x202a, -1], [0x202f, 1], [0x2030, -1], [0x2031, 1],
|
60
|
+
[0x2032, -1], [0x2034, 1], [0x203b, -1], [0x203c, 1], [0x2060, -1],
|
61
|
+
[0x2064, 1], [0x206a, -1], [0x2070, 1], [0x20d0, -1], [0x20f0, 1],
|
62
|
+
[0x2103, -1], [0x2104, 1], [0x2116, -1], [0x2117, 1], [0x2121, -1],
|
63
|
+
[0x2122, 1], [0x212b, -1], [0x212c, 1], [0x2160, -1], [0x216c, 1],
|
64
|
+
[0x2170, -1], [0x217a, 1], [0x2189, -1], [0x218a, 1], [0x2190, -1],
|
65
|
+
[0x2194, 1], [0x21d2, -1], [0x21d3, 1], [0x21d4, -1], [0x21d5, 1],
|
66
|
+
[0x2200, -1], [0x2201, 1], [0x2202, -1], [0x2204, 1], [0x2207, -1],
|
67
|
+
[0x2209, 1], [0x220b, -1], [0x220c, 1], [0x2211, -1], [0x2212, 1],
|
68
|
+
[0x221a, -1], [0x221b, 1], [0x221d, -1], [0x2221, 1], [0x2225, -1],
|
69
|
+
[0x2226, 1], [0x2227, -1], [0x222d, 1], [0x222e, -1], [0x222f, 1],
|
70
|
+
[0x2234, -1], [0x2236, 1], [0x223d, -1], [0x223e, 1], [0x2252, -1],
|
71
|
+
[0x2253, 1], [0x2260, -1], [0x2262, 1], [0x2266, -1], [0x2268, 1],
|
72
|
+
[0x226a, -1], [0x226c, 1], [0x2282, -1], [0x2284, 1], [0x2286, -1],
|
73
|
+
[0x2288, 1], [0x22a5, -1], [0x22a6, 1], [0x22bf, -1], [0x22c0, 1],
|
74
|
+
[0x2312, -1], [0x2313, 1], [0x231a, -1], [0x231b, 1], [0x2328, -1],
|
75
|
+
[0x2329, 2], [0x232b, 1], [0x23e9, -1], [0x23eb, 1], [0x23ed, -1],
|
76
|
+
[0x23ef, 1], [0x23f0, -1], [0x23f3, 1], [0x23f8, -1], [0x23fb, 1],
|
77
|
+
[0x2460, -1], [0x24ea, 1], [0x24eb, -1], [0x2500, 1], [0x25a0, -1],
|
78
|
+
[0x25a2, 1], [0x25b2, -1], [0x25b4, 1], [0x25bc, -1], [0x25be, 1],
|
79
|
+
[0x25c6, -1], [0x25c8, 1], [0x25cb, -1], [0x25cc, 1], [0x25ce, -1],
|
80
|
+
[0x25d0, 1], [0x25ef, -1], [0x25f0, 1], [0x25fb, -1], [0x25ff, 1],
|
81
|
+
[0x2600, -1], [0x2607, 1], [0x2609, -1], [0x260a, 1], [0x260e, -1],
|
82
|
+
[0x2610, 1], [0x2611, -1], [0x2612, 1], [0x2614, -1], [0x2616, 1],
|
83
|
+
[0x2618, -1], [0x2619, 1], [0x261c, -1], [0x261f, 1], [0x2620, -1],
|
84
|
+
[0x2621, 1], [0x2622, -1], [0x2624, 1], [0x2626, -1], [0x2627, 1],
|
85
|
+
[0x262a, -1], [0x262b, 1], [0x262e, -1], [0x2630, 1], [0x2638, -1],
|
86
|
+
[0x2639, 1], [0x2640, -1], [0x2641, 1], [0x2642, -1], [0x2643, 1],
|
87
|
+
[0x2648, -1], [0x2654, 1], [0x265f, -1], [0x2660, 1], [0x2668, -1],
|
88
|
+
[0x2669, 1], [0x266a, -1], [0x266b, 1], [0x266d, -1], [0x266e, 1],
|
89
|
+
[0x266f, -1], [0x2670, 1], [0x267b, -1], [0x267c, 1], [0x267e, -1],
|
90
|
+
[0x267f, 1], [0x2692, -1], [0x2693, 1], [0x2694, -1], [0x2695, 1],
|
91
|
+
[0x2696, -1], [0x2698, 1], [0x2699, -1], [0x269a, 1], [0x269b, -1],
|
92
|
+
[0x269d, 1], [0x269e, -1], [0x26a1, 1], [0x26aa, -1], [0x26ac, 1],
|
93
|
+
[0x26b0, -1], [0x26b1, 1], [0x26bd, -1], [0x26c0, 1], [0x26c4, -1],
|
94
|
+
[0x26e2, 1], [0x26e3, -1], [0x26e4, 1], [0x26e8, -1], [0x2700, 1],
|
95
|
+
[0x2702, -1], [0x2703, 1], [0x2705, -1], [0x2706, 1], [0x2708, -1],
|
96
|
+
[0x270e, 1], [0x270f, -1], [0x2710, 1], [0x2712, -1], [0x2713, 1],
|
97
|
+
[0x2714, -1], [0x2715, 1], [0x2716, -1], [0x2717, 1], [0x271d, -1],
|
98
|
+
[0x271e, 1], [0x2721, -1], [0x2722, 1], [0x2728, -1], [0x2729, 1],
|
99
|
+
[0x2733, -1], [0x2735, 1], [0x273d, -1], [0x273e, 1], [0x2744, -1],
|
100
|
+
[0x2745, 1], [0x2747, -1], [0x2748, 1], [0x274c, -1], [0x274d, 1],
|
101
|
+
[0x274e, -1], [0x274f, 1], [0x2753, -1], [0x2755, 1], [0x2763, -1],
|
102
|
+
[0x2765, 1], [0x2776, -1], [0x2780, 1], [0x2795, -1], [0x2798, 1],
|
103
|
+
[0x27a1, -1], [0x27a2, 1], [0x27b0, -1], [0x27b1, 1], [0x27bf, -1],
|
104
|
+
[0x27c0, 1], [0x2b05, -1], [0x2b08, 1], [0x2b1b, -1], [0x2b1d, 1],
|
105
|
+
[0x2b50, -1], [0x2b51, 1], [0x2b55, -1], [0x2b5a, 1], [0x2e80, 2],
|
106
|
+
[0x302a, -1], [0x3030, 2], [0x303f, 1], [0x3040, -1], [0x3041, 2],
|
107
|
+
[0x3097, -1], [0x309b, 2], [0x3100, -1], [0x3105, 2], [0x312f, -1],
|
108
|
+
[0x3131, 2], [0x318f, -1], [0x3190, 2], [0x4dc0, -1], [0x4e00, 2],
|
109
|
+
[0xa4c7, -1], [0xa4d0, 1], [0xa806, -1], [0xa807, 1], [0xa80b, -1],
|
110
|
+
[0xa80c, 1], [0xa825, -1], [0xa827, 1], [0xa960, -1], [0xa97d, 1],
|
111
|
+
[0xac00, 2], [0xd7a4, 1], [0xd800, -1], [0xf900, 2], [0xfb00, 1],
|
112
|
+
[0xfb1e, -1], [0xfb1f, 1], [0xfe00, -1], [0xfe24, 1], [0xfe30, 2],
|
113
|
+
[0xfe6c, -1], [0xfe70, 1], [0xfeff, -1], [0xff01, 2], [0xff61, 1],
|
114
|
+
[0xffe0, 2], [0xffe7, 1], [0xfff9, -1], [0xfffc, 1]
|