ssh_tunnels 0.4.0 → 0.4.1
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/Gemfile.lock +1 -1
- data/README.md +4 -0
- data/lib/ssh_tunnels/stderr_capture.rb +83 -0
- data/lib/ssh_tunnels/ui.rb +47 -5
- data/lib/ssh_tunnels/version.rb +1 -1
- data/lib/ssh_tunnels.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 79e3f82e75a37a3fd7ca199dc827a217d33c91be2b5f1fc65c445e583d14d82c
|
|
4
|
+
data.tar.gz: b08d3849be1742e6581dcdf23e9c65f4cfc3c048d396bf877227e1bc2aa9f177
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8d03a2c30f5e5d341513f0c24dd4d0efbf482b6cce2339dd41fdf128bdf28f9b53c0674afed04dae6de5899a803def7e28c25f0bd7f24d43cead291eab06348c
|
|
7
|
+
data.tar.gz: 87ed978f47c22b43cc27a9fe182ab86d9b30d070cea090eddf5940f37a59bf1ecbf473579c509b01ea140550d07b3ae325a38525106956476f7ce5665576a912
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -113,6 +113,10 @@ The configuration file is checked once a second while the app is running. Saving
|
|
|
113
113
|
* Tunnels deleted from the file are removed from the list if disconnected. If connected they stay listed, marked `removed from config`, until disconnected.
|
|
114
114
|
* An invalid or half-saved file is reported in the status line and leaves the current tunnels untouched until the next successful reload.
|
|
115
115
|
|
|
116
|
+
## Error output
|
|
117
|
+
|
|
118
|
+
Anything written to the standard error stream while the app is running (a backtrace from a failed connection, for example) is captured and shown below the tunnel list. Press `Esc` to clear it. Only the most recent output is kept.
|
|
119
|
+
|
|
116
120
|
## Contributing
|
|
117
121
|
|
|
118
122
|
Pull requests are welcome.
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SshTunnels
|
|
4
|
+
# Captures everything written to the standard error stream while the curses
|
|
5
|
+
# screen is active. Output written straight to the terminal in that mode
|
|
6
|
+
# appears without line breaks and corrupts the display, so the stream is
|
|
7
|
+
# redirected into a pipe and the text is kept for the UI to draw.
|
|
8
|
+
#
|
|
9
|
+
# Only one block of output is retained: output arriving after a quiet period
|
|
10
|
+
# replaces whatever was captured before.
|
|
11
|
+
class StderrCapture
|
|
12
|
+
QUIET_PERIOD = 2
|
|
13
|
+
LIMIT = 64 * 1024
|
|
14
|
+
TAB = ' ' * 4
|
|
15
|
+
|
|
16
|
+
def initialize(stream = $stderr)
|
|
17
|
+
@stream = stream
|
|
18
|
+
@mutex = Mutex.new
|
|
19
|
+
@text = +''
|
|
20
|
+
@updated_at = nil
|
|
21
|
+
@original = nil
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Redirection happens at the file descriptor level so that output from
|
|
25
|
+
# loggers and background threads holding a reference to the stream is
|
|
26
|
+
# captured too.
|
|
27
|
+
def start
|
|
28
|
+
return unless @original.nil?
|
|
29
|
+
|
|
30
|
+
@original = @stream.dup
|
|
31
|
+
@reader, writer = IO.pipe
|
|
32
|
+
@stream.reopen(writer)
|
|
33
|
+
@stream.sync = true
|
|
34
|
+
writer.close
|
|
35
|
+
@thread = Thread.new { drain }
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def stop
|
|
39
|
+
return if @original.nil?
|
|
40
|
+
|
|
41
|
+
@stream.reopen(@original)
|
|
42
|
+
@stream.sync = true
|
|
43
|
+
@original.close
|
|
44
|
+
@original = nil
|
|
45
|
+
@thread.join
|
|
46
|
+
@reader.close
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def empty?
|
|
50
|
+
@mutex.synchronize { @text.empty? }
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def clear
|
|
54
|
+
@mutex.synchronize { @text = +'' }
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Captured text as display lines no wider than +width+.
|
|
58
|
+
def lines(width)
|
|
59
|
+
text = @mutex.synchronize { @text.dup }
|
|
60
|
+
text.force_encoding(Encoding::UTF_8).scrub('?').split(/\r?\n/).flat_map do |line|
|
|
61
|
+
line = line.gsub("\t", TAB).gsub(/[^[:print:]]/, '')
|
|
62
|
+
line.empty? ? [line] : line.scan(/.{1,#{width}}/)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
private
|
|
67
|
+
|
|
68
|
+
def drain
|
|
69
|
+
loop { append(@reader.readpartial(4096)) }
|
|
70
|
+
rescue IOError
|
|
71
|
+
nil
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def append(chunk)
|
|
75
|
+
now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
76
|
+
@mutex.synchronize do
|
|
77
|
+
@text = +'' if @updated_at && now - @updated_at > QUIET_PERIOD
|
|
78
|
+
@updated_at = now
|
|
79
|
+
@text << chunk.byteslice(0, LIMIT - @text.bytesize).to_s
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
data/lib/ssh_tunnels/ui.rb
CHANGED
|
@@ -13,6 +13,7 @@ module SshTunnels
|
|
|
13
13
|
red: Curses::COLOR_RED,
|
|
14
14
|
yellow: Curses::COLOR_YELLOW
|
|
15
15
|
}.freeze
|
|
16
|
+
ESCAPE = [27, "\e"].freeze
|
|
16
17
|
|
|
17
18
|
def initialize(config, user, passphrase)
|
|
18
19
|
@config = config
|
|
@@ -20,9 +21,11 @@ module SshTunnels
|
|
|
20
21
|
@passphrase = passphrase
|
|
21
22
|
@tunnels = config.tunnels(user, passphrase)
|
|
22
23
|
@config_mtime = config.mtime
|
|
24
|
+
@stderr_capture = StderrCapture.new
|
|
23
25
|
end
|
|
24
26
|
|
|
25
27
|
def setup
|
|
28
|
+
@stderr_capture.start
|
|
26
29
|
Curses.init_screen
|
|
27
30
|
Curses.start_color
|
|
28
31
|
COLORS.each_value.with_index(1) { |value, pair| Curses.init_pair(pair, value, Curses::COLOR_BLACK) }
|
|
@@ -37,11 +40,11 @@ module SshTunnels
|
|
|
37
40
|
rescue Net::SSH::Disconnect, Errno::ECONNRESET => e
|
|
38
41
|
shutdown("Error encountered: #{e}")
|
|
39
42
|
ensure
|
|
40
|
-
|
|
43
|
+
close_screen
|
|
41
44
|
end
|
|
42
45
|
|
|
43
46
|
def shutdown(error = nil)
|
|
44
|
-
|
|
47
|
+
close_screen
|
|
45
48
|
puts error unless error.nil?
|
|
46
49
|
puts 'Shutting down connections.'
|
|
47
50
|
@tunnels.select(&:active?).each(&:shutdown)
|
|
@@ -50,13 +53,17 @@ module SshTunnels
|
|
|
50
53
|
|
|
51
54
|
private
|
|
52
55
|
|
|
56
|
+
def close_screen
|
|
57
|
+
Curses.close_screen
|
|
58
|
+
@stderr_capture.stop
|
|
59
|
+
end
|
|
60
|
+
|
|
53
61
|
def monitor
|
|
54
62
|
loop do
|
|
55
63
|
reload_if_changed
|
|
56
64
|
prune_removed
|
|
57
|
-
@tunnels.each_with_index
|
|
58
|
-
|
|
59
|
-
end
|
|
65
|
+
@tunnels.each_with_index { |tunnel, index| display_tunnel(tunnel, index) }
|
|
66
|
+
display_error_output
|
|
60
67
|
refresh
|
|
61
68
|
end
|
|
62
69
|
rescue UserQuit
|
|
@@ -148,8 +155,43 @@ module SshTunnels
|
|
|
148
155
|
"[1-#{IDENTIFIERS[@tunnels.size - 1]}] to connect/disconnect. Press 'q' to quit."
|
|
149
156
|
end
|
|
150
157
|
|
|
158
|
+
# Output captured from the standard error stream (a backtrace, usually) is
|
|
159
|
+
# drawn below the status line, one line per row, until cleared with Esc.
|
|
160
|
+
# Output that does not fit the window is cut short.
|
|
161
|
+
def display_error_output
|
|
162
|
+
top = status_coordinates.first + 2
|
|
163
|
+
clear_rows(top)
|
|
164
|
+
rows = window.maxy - top - 1
|
|
165
|
+
return if @stderr_capture.empty? || rows < 1
|
|
166
|
+
|
|
167
|
+
write_line(top, 'Error output (Esc to clear):', :yellow)
|
|
168
|
+
error_lines(rows).each_with_index { |line, index| write_line(top + 1 + index, line, :red) }
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
def error_lines(rows)
|
|
172
|
+
lines = @stderr_capture.lines([window.maxx - 4, 1].max)
|
|
173
|
+
hidden = lines.size - rows
|
|
174
|
+
return lines unless hidden.positive?
|
|
175
|
+
|
|
176
|
+
lines.first(rows - 1) << "... #{hidden + 1} more lines"
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def write_line(row, text, color_name)
|
|
180
|
+
window.attrset(color(color_name))
|
|
181
|
+
window.setpos(row, 2)
|
|
182
|
+
window.addstr(text)
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def clear_rows(top)
|
|
186
|
+
(top...window.maxy).each do |row|
|
|
187
|
+
window.setpos(row, 0)
|
|
188
|
+
window.clrtoeol
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
|
|
151
192
|
def process_input(input)
|
|
152
193
|
raise UserQuit if input == 'q'
|
|
194
|
+
return @stderr_capture.clear if ESCAPE.include?(input)
|
|
153
195
|
return status("Unrecognized input: #{input}") unless input.is_a?(String) && input =~ /\A[0-9a-zA-Z]\Z/
|
|
154
196
|
|
|
155
197
|
index = IDENTIFIERS.index(input)
|
data/lib/ssh_tunnels/version.rb
CHANGED
data/lib/ssh_tunnels.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ssh_tunnels
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.4.
|
|
4
|
+
version: 0.4.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bob Farrell
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-11-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bcrypt_pbkdf
|
|
@@ -90,6 +90,7 @@ files:
|
|
|
90
90
|
- doc/demo.png
|
|
91
91
|
- lib/ssh_tunnels.rb
|
|
92
92
|
- lib/ssh_tunnels/config.rb
|
|
93
|
+
- lib/ssh_tunnels/stderr_capture.rb
|
|
93
94
|
- lib/ssh_tunnels/tunnel.rb
|
|
94
95
|
- lib/ssh_tunnels/ui.rb
|
|
95
96
|
- lib/ssh_tunnels/version.rb
|