sumire 24.03.31 → 24.04.03
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/exe/sumire +15 -18
- data/lib/sumire/version.rb +1 -1
- data/lib/sumire.rb +48 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 163fa9383b3591e43b8f8d3cb814bd7b44c2037ffce0c92c49be26c1c4dbf238
|
4
|
+
data.tar.gz: 737005aa5b6552b7734294c754f4b68284ae77ddc296194d9f7f20cc2fab2fa9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3baf3169714078dbbec1955c6daa676c47e62817f860db115ccf31d2333780eea5fac79459eb841af67ebb488c2d22462ca2bdf93dda542a4fa51eb95a9517d
|
7
|
+
data.tar.gz: 5a914c0381618108d77c6c3e575debc97c9d8a09c72a75b372a965032b2ed6eeb0662995872d60b0072d307c50f5de502fa8d4694b1ed238d7dbc529ac71c6f3
|
data/exe/sumire
CHANGED
@@ -22,7 +22,8 @@ require "fileutils"
|
|
22
22
|
"save_to": "Save to: ",
|
23
23
|
"version_info": "Display version information",
|
24
24
|
"arg_command": "Run the command rather than an interactive shell",
|
25
|
-
"license_info": "Displays license information"
|
25
|
+
"license_info": "Displays license information",
|
26
|
+
"legacy": "Enable legacy mode"
|
26
27
|
},
|
27
28
|
"ja": {
|
28
29
|
"arg_less_one": "引数の個数は 1 個以下でなければなりません",
|
@@ -37,7 +38,8 @@ require "fileutils"
|
|
37
38
|
"save_to": "保存先: ",
|
38
39
|
"version_info": "バージョン情報を表示します",
|
39
40
|
"arg_command": "コマンドではなくシェルを実行します",
|
40
|
-
"license_info": "ソフトウェアのライセンス情報を表示します"
|
41
|
+
"license_info": "ソフトウェアのライセンス情報を表示します",
|
42
|
+
"legacy": "レガシーモードを有効にします"
|
41
43
|
}
|
42
44
|
}
|
43
45
|
|
@@ -57,17 +59,7 @@ def main(**kwargs)
|
|
57
59
|
command = command ? " -c \"#{command}\"" : ""
|
58
60
|
|
59
61
|
verbose = kwargs[:verbose] || false
|
60
|
-
|
61
|
-
unless verbose
|
62
|
-
processes = Sys::ProcTable.ps
|
63
|
-
processes.each do |process|
|
64
|
-
next unless process.cmdline.match(/^script/)
|
65
|
-
|
66
|
-
warn("#{comment(:exist_process)}\n\n")
|
67
|
-
warn("\e[32mkill #{process.pid}\e[0m")
|
68
|
-
exit(false)
|
69
|
-
end
|
70
|
-
end
|
62
|
+
legacy = kwargs[:legacy] || false
|
71
63
|
|
72
64
|
dst = "#{dir}/#{Time.now.strftime("%Y%m%d_%H%M%S")}.log"
|
73
65
|
dst = File.expand_path(dst)
|
@@ -75,15 +67,15 @@ def main(**kwargs)
|
|
75
67
|
puts(dst)
|
76
68
|
puts(comment(:start_recording))
|
77
69
|
|
78
|
-
|
79
|
-
tmp = "/tmp/sumire/#{SecureRandom.uuid}.log"
|
70
|
+
tmp = "/tmp/sumire/#{SecureRandom.uuid}/typescript"
|
80
71
|
tmp = Pathname(Dir.pwd).join("typescript").to_path if verbose
|
72
|
+
FileUtils.mkdir_p(Pathname(tmp).dirname.to_path)
|
81
73
|
thread = Thread.new do
|
82
|
-
Sumire::Sumire.exec(destination: dst, target: tmp, verbose: verbose)
|
74
|
+
Sumire::Sumire.exec(destination: dst, target: tmp, verbose: verbose, legacy: legacy)
|
83
75
|
end
|
84
76
|
thread.join if verbose
|
85
77
|
|
86
|
-
script_cmd = "script -f #{tmp}#{command}"
|
78
|
+
script_cmd = "script -q -f #{tmp}#{command}"
|
87
79
|
system(script_cmd) unless verbose
|
88
80
|
|
89
81
|
puts(comment(:EOR))
|
@@ -91,6 +83,7 @@ end
|
|
91
83
|
|
92
84
|
opt = OptionParser.new
|
93
85
|
verbose = false
|
86
|
+
legacy = false
|
94
87
|
dir = "."
|
95
88
|
cmd = nil
|
96
89
|
|
@@ -116,6 +109,10 @@ opt.on("-d [Directory]", "--directory", comment(:specify_dir)) do |directory|
|
|
116
109
|
dir = directory
|
117
110
|
end
|
118
111
|
|
112
|
+
opt.on("-l", "--legacy", comment(:legacy)) do |_v|
|
113
|
+
legacy = true
|
114
|
+
end
|
115
|
+
|
119
116
|
begin
|
120
117
|
opt.parse!(ARGV)
|
121
118
|
rescue OptionParser::InvalidOption
|
@@ -123,4 +120,4 @@ rescue OptionParser::InvalidOption
|
|
123
120
|
exit(false)
|
124
121
|
end
|
125
122
|
|
126
|
-
main(directory: dir, verbose: verbose, command: cmd)
|
123
|
+
main(directory: dir, verbose: verbose, command: cmd, legacy: legacy)
|
data/lib/sumire/version.rb
CHANGED
data/lib/sumire.rb
CHANGED
@@ -8,12 +8,49 @@ module Sumire
|
|
8
8
|
class Error < StandardError; end
|
9
9
|
|
10
10
|
class Sumire # rubocop:disable Style/Documentation
|
11
|
+
def self.remove_cr(text) # rubocop:disable Metrics/MethodLength
|
12
|
+
chars = text.bytes
|
13
|
+
remove_cr_chars = [0] * chars.length
|
14
|
+
idx = 0
|
15
|
+
chars.map do |chr|
|
16
|
+
if chr.eql?(8)
|
17
|
+
idx -= 1
|
18
|
+
next
|
19
|
+
end
|
20
|
+
|
21
|
+
if chr.eql?(13)
|
22
|
+
idx = 0
|
23
|
+
next
|
24
|
+
end
|
25
|
+
remove_cr_chars[idx] = chr
|
26
|
+
idx += 1
|
27
|
+
end
|
28
|
+
remove_cr_chars.filter { |e| e != 0 }.pack("C*")
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.remove_crs(text, mode: false) # rubocop:disable Metrics/MethodLength
|
32
|
+
if mode
|
33
|
+
begin
|
34
|
+
text.encode!("UTF-16", "UTF-8", invalid: :replace, replace: "")
|
35
|
+
text = text.encode!("UTF-8", "UTF-16")
|
36
|
+
text = text.gsub(/\r+/, "\r").gsub(/\r+\n\r+/, "\n").gsub("\r", "\n") if mode
|
37
|
+
rescue StandardError
|
38
|
+
nil
|
39
|
+
end
|
40
|
+
return text
|
41
|
+
end
|
42
|
+
|
43
|
+
text.split("\n").map { |e| remove_cr(e) }.join("\n")
|
44
|
+
end
|
45
|
+
|
11
46
|
# rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity, Lint/MissingCopEnableDirective
|
12
47
|
def self.exec(**kwargs)
|
48
|
+
legacy = kwargs[:legacy] || false
|
13
49
|
destination = kwargs[:destination]
|
14
50
|
if destination.nil?
|
15
|
-
|
16
|
-
|
51
|
+
uuid = SecureRandom.uuid
|
52
|
+
FileUtils.mkdir_p("/tmp/sumire/#{uuid}")
|
53
|
+
destination = "/tmp/sumire/#{uuid}/typescript"
|
17
54
|
end
|
18
55
|
target = kwargs[:target]
|
19
56
|
target = "typescript" if target.nil?
|
@@ -34,16 +71,22 @@ module Sumire
|
|
34
71
|
|
35
72
|
# Add target text
|
36
73
|
add_line_txt = txt[old_text.size...-1]
|
74
|
+
add_line_txt = remove_crs(add_line_txt, mode: legacy)
|
37
75
|
|
38
76
|
regex = /Script\sdone\son\s\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\+\d{2}:\d{2}\s\[COMMAND_EXIT_CODE="\d+"\]/
|
39
|
-
|
77
|
+
begin
|
78
|
+
match = add_line_txt.encode("utf-8", "utf-8").match(regex)
|
79
|
+
exit if !add_line_txt.nil? && match
|
80
|
+
rescue ArgumentError
|
81
|
+
nil
|
82
|
+
end
|
40
83
|
next if add_line_txt.nil?
|
41
84
|
|
42
|
-
add_line = add_line_txt.
|
85
|
+
add_line = add_line_txt.lines.map(&:chomp).map do |line|
|
43
86
|
time = Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
44
87
|
"[#{time}] #{line}"
|
45
88
|
end
|
46
|
-
add_line_color = add_line_txt.
|
89
|
+
add_line_color = add_line_txt.lines.map(&:chomp).map do |line|
|
47
90
|
time = Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
48
91
|
"\e[32m[#{time}]\e[0m #{line}"
|
49
92
|
end
|
@@ -65,10 +108,8 @@ module Sumire
|
|
65
108
|
puts(line)
|
66
109
|
end
|
67
110
|
end
|
68
|
-
|
69
111
|
old_text = txt
|
70
112
|
end
|
71
|
-
|
72
113
|
old_lines = new_lines
|
73
114
|
end
|
74
115
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sumire
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 24.03
|
4
|
+
version: 24.04.03
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MURATA Mitsuharu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ansi2txt
|