multish 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/lib/multish.rb +126 -22
- data/lib/multish/version.rb +1 -1
- 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: a664e0a48f48c32e9cce30421292ccd18b37516f19bdbbdbf7477a0f0bfc6a42
|
4
|
+
data.tar.gz: 1c9bbd3ba226cd35d4d282ea474dff9ec82359360d175e9fcbab57a6f4bcb565
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5357d9dd1aa1c1199eb2af648e82454e6aa59c46583c494e70996f5665f20383dc91ce01c1c6409a926016ea359c6e04d2ef2402ab8d992bf46d5c120d6475e
|
7
|
+
data.tar.gz: dd03f7e31853a5401ace96228ac76fd90e709260d561281e1615c55cdb06d4592b58f3e9bb4ad65a375aa2906d8bc0cdd0488c159505de28d6560e2af0f7e47c
|
data/.rubocop.yml
CHANGED
data/lib/multish.rb
CHANGED
@@ -6,6 +6,110 @@ require 'colorize'
|
|
6
6
|
|
7
7
|
BRIGHT_WHITE = 15
|
8
8
|
|
9
|
+
$log = []
|
10
|
+
|
11
|
+
class Window
|
12
|
+
def initialize(height, width, top, left)
|
13
|
+
@window = Curses::Window.new(height, width, top, left)
|
14
|
+
@fgcolor = :black
|
15
|
+
@bgcolor = :bright_white
|
16
|
+
reset!
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.screen_width
|
20
|
+
Curses.cols
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.screen_height
|
24
|
+
Curses.lines
|
25
|
+
end
|
26
|
+
|
27
|
+
def setpos(x, y)
|
28
|
+
@window.setpos(x, y)
|
29
|
+
end
|
30
|
+
|
31
|
+
def bold=(value)
|
32
|
+
if value
|
33
|
+
@window.attron(Curses::A_BOLD)
|
34
|
+
else
|
35
|
+
@window.attroff(Curses::A_BOLD)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def fgcolor=(value)
|
40
|
+
@fgcolor = value
|
41
|
+
update_color!
|
42
|
+
end
|
43
|
+
|
44
|
+
def bgcolor=(value)
|
45
|
+
@bgcolor = value
|
46
|
+
update_color!
|
47
|
+
end
|
48
|
+
|
49
|
+
def update_color!
|
50
|
+
fgcode = get_code(@fgcolor)
|
51
|
+
bgcode = get_code(@bgcolor)
|
52
|
+
code = Window.create_color_pair(fgcode, bgcode)
|
53
|
+
@window.attron(Curses.color_pair(code))
|
54
|
+
end
|
55
|
+
|
56
|
+
def get_code(color)
|
57
|
+
case color
|
58
|
+
when :black
|
59
|
+
Curses::COLOR_BLACK
|
60
|
+
when :red
|
61
|
+
Curses::COLOR_RED
|
62
|
+
when :green
|
63
|
+
Curses::COLOR_GREEN
|
64
|
+
when :yellow
|
65
|
+
Curses::COLOR_YELLOW
|
66
|
+
when :blue
|
67
|
+
Curses::COLOR_BLUE
|
68
|
+
when :magenta
|
69
|
+
Curses::COLOR_MAGENTA
|
70
|
+
when :cyan
|
71
|
+
Curses::COLOR_CYAN
|
72
|
+
when :white
|
73
|
+
Curses::COLOR_WHITE
|
74
|
+
when :bright_white
|
75
|
+
Window.create_color(:bright_white, 1000, 1000, 1000)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.create_color(code, r, g, b)
|
80
|
+
@colors ||= {}
|
81
|
+
new_index = 15 + @colors.count
|
82
|
+
@colors[code] ||= [new_index, Curses.init_color(new_index, r, g, b)]
|
83
|
+
@colors[code][0]
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.create_color_pair(fg, bg)
|
87
|
+
index = "#{fg}/#{bg}"
|
88
|
+
@pairs ||= {}
|
89
|
+
new_index = 100 + @pairs.count
|
90
|
+
@pairs[index] ||= [new_index, Curses.init_pair(new_index, fg, bg)]
|
91
|
+
@pairs[index][0]
|
92
|
+
end
|
93
|
+
|
94
|
+
def <<(str)
|
95
|
+
@window.addstr(str)
|
96
|
+
end
|
97
|
+
|
98
|
+
def scrollok(value)
|
99
|
+
@window.scrollok(value)
|
100
|
+
end
|
101
|
+
|
102
|
+
def refresh!
|
103
|
+
@window.refresh
|
104
|
+
end
|
105
|
+
|
106
|
+
def reset!
|
107
|
+
self.fgcolor = :black
|
108
|
+
self.bgcolor = :bright_white
|
109
|
+
self.bold = false
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
9
113
|
class MultishItem
|
10
114
|
attr_reader :command
|
11
115
|
|
@@ -17,11 +121,11 @@ class MultishItem
|
|
17
121
|
end
|
18
122
|
|
19
123
|
def width
|
20
|
-
(
|
124
|
+
(Window.screen_width / @count).floor
|
21
125
|
end
|
22
126
|
|
23
127
|
def height
|
24
|
-
|
128
|
+
Window.screen_height
|
25
129
|
end
|
26
130
|
|
27
131
|
def left
|
@@ -33,19 +137,19 @@ class MultishItem
|
|
33
137
|
end
|
34
138
|
|
35
139
|
def create_window!
|
36
|
-
@nav_window =
|
37
|
-
@window =
|
140
|
+
@nav_window = Window.new(1, width - 1, top, left)
|
141
|
+
@window = Window.new(height - 1, width - 1, top + 1, left)
|
38
142
|
@window.scrollok(true)
|
39
143
|
update_title!
|
40
144
|
end
|
41
145
|
|
42
146
|
def color_code
|
43
147
|
if !@wait_thr
|
44
|
-
|
148
|
+
:yellow
|
45
149
|
elsif finished?
|
46
|
-
errored? ?
|
150
|
+
errored? ? :red : :green
|
47
151
|
else # rubocop:disable Lint/DuplicateBranch
|
48
|
-
|
152
|
+
:yellow
|
49
153
|
end
|
50
154
|
end
|
51
155
|
|
@@ -55,9 +159,11 @@ class MultishItem
|
|
55
159
|
|
56
160
|
def update_title!
|
57
161
|
@nav_window.setpos(0, 0)
|
58
|
-
@nav_window.
|
59
|
-
@nav_window.
|
60
|
-
@nav_window.
|
162
|
+
@nav_window.fgcolor = color_code
|
163
|
+
@nav_window.bgcolor = :black
|
164
|
+
@nav_window.bold = true
|
165
|
+
@nav_window << window_title.ljust(width - 1)
|
166
|
+
@nav_window.refresh!
|
61
167
|
end
|
62
168
|
|
63
169
|
def window_title
|
@@ -73,7 +179,7 @@ class MultishItem
|
|
73
179
|
[@stdout, @stderr]
|
74
180
|
end
|
75
181
|
|
76
|
-
def try_update(fd)
|
182
|
+
def try_update(fd)
|
77
183
|
return unless [@stdout, @stderr].include?(fd)
|
78
184
|
|
79
185
|
line = fd.gets
|
@@ -83,27 +189,28 @@ class MultishItem
|
|
83
189
|
def print(text)
|
84
190
|
@output << text
|
85
191
|
color_print(@window, text)
|
86
|
-
@window.refresh
|
192
|
+
@window.refresh!
|
87
193
|
end
|
88
194
|
|
89
195
|
def color_print(window, input)
|
90
196
|
parse_commands(input) do |op, arg|
|
91
197
|
case op
|
92
198
|
when :string
|
93
|
-
window
|
199
|
+
window << arg
|
94
200
|
when :reset
|
95
|
-
window.
|
201
|
+
window.reset!
|
96
202
|
when :bold
|
97
|
-
window.
|
203
|
+
window.bold = true
|
98
204
|
when :color
|
99
|
-
|
100
|
-
window.attron(Curses.color_pair(10))
|
205
|
+
window.fgcolor = arg
|
101
206
|
when :error
|
102
207
|
raise "ERROR: #{arg}"
|
103
208
|
end
|
104
209
|
end
|
105
210
|
end
|
106
211
|
|
212
|
+
COLORS = %i[black red green yellow blue magenta cyan white].freeze
|
213
|
+
|
107
214
|
def parse_commands(string)
|
108
215
|
parse_string(string) do |op, arg|
|
109
216
|
case op
|
@@ -120,7 +227,7 @@ class MultishItem
|
|
120
227
|
when 1
|
121
228
|
yield [:bold]
|
122
229
|
when 30..37
|
123
|
-
color =
|
230
|
+
color = COLORS[subarg - 30]
|
124
231
|
yield [:color, color]
|
125
232
|
end
|
126
233
|
end
|
@@ -200,10 +307,6 @@ class Multish
|
|
200
307
|
Curses.init_screen
|
201
308
|
Curses.start_color
|
202
309
|
Curses.curs_set(0)
|
203
|
-
Curses.init_pair(2, Curses::COLOR_WHITE, Curses::COLOR_GREEN)
|
204
|
-
Curses.init_pair(3, Curses::COLOR_WHITE, Curses::COLOR_RED)
|
205
|
-
Curses.init_pair(4, Curses::COLOR_WHITE, Curses::COLOR_BLACK)
|
206
|
-
Curses.init_color(BRIGHT_WHITE, 1000, 1000, 1000)
|
207
310
|
Curses.use_default_colors
|
208
311
|
Curses.cbreak
|
209
312
|
@commands.each(&:create_window!)
|
@@ -229,6 +332,7 @@ class Multish
|
|
229
332
|
ensure
|
230
333
|
Curses.curs_set(1)
|
231
334
|
Curses.close_screen
|
335
|
+
warn $log.join("\n").blue
|
232
336
|
if errored?
|
233
337
|
warn 'At least one of the commands exited with error.'
|
234
338
|
@commands.select(&:errored?).each(&:print_output!)
|
data/lib/multish/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multish
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomasz Dąbrowski
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|