showterm 0.2.1.pre.2 → 0.2.1.pre.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/showterm.rb +60 -40
- data/showterm.gemspec +1 -1
- metadata +1 -1
data/lib/showterm.rb
CHANGED
@@ -25,6 +25,38 @@ module Showterm
|
|
25
25
|
ret
|
26
26
|
end
|
27
27
|
|
28
|
+
# Get the current width of the terminal
|
29
|
+
#
|
30
|
+
# @return [Integer] number of columns
|
31
|
+
def terminal_width
|
32
|
+
guess = `tput cols`.to_i
|
33
|
+
guess == 0 ? 80 : guess
|
34
|
+
end
|
35
|
+
|
36
|
+
# Upload the termshow to showterm.io
|
37
|
+
#
|
38
|
+
# @param [String] scriptfile The ANSI dump of the terminal
|
39
|
+
# @param [String] timingfile The timings
|
40
|
+
# @param [Integer] cols The width of the terminal
|
41
|
+
def upload!(scriptfile, timingfile, cols=terminal_width)
|
42
|
+
puts 'uploading, please wait.'
|
43
|
+
request = Net::HTTP::Post.new("/scripts")
|
44
|
+
request.set_form_data(:scriptfile => scriptfile,
|
45
|
+
:timingfile => timingfile,
|
46
|
+
:cols => cols)
|
47
|
+
|
48
|
+
response = http(request)
|
49
|
+
raise response.body unless Net::HTTPSuccess === response
|
50
|
+
puts response.body
|
51
|
+
rescue => e
|
52
|
+
raise if retried
|
53
|
+
retried = true
|
54
|
+
retry
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
# Get a temporary file that will be deleted when the program exits.
|
28
60
|
def temp_file
|
29
61
|
f = Tempfile.new('showterm')
|
30
62
|
f.close(false)
|
@@ -32,11 +64,33 @@ module Showterm
|
|
32
64
|
f
|
33
65
|
end
|
34
66
|
|
67
|
+
# Should we try recording using `script`?
|
68
|
+
#
|
69
|
+
# This is a hard question to answer, so we just try it and see whether it
|
70
|
+
# looks like it gives sane results.
|
71
|
+
#
|
72
|
+
# We prefer to use script if it works because ttyrec gives really horrible
|
73
|
+
# errors about missing ptys. This might be fixable by compiling with the
|
74
|
+
# correct flags; but as script seems to work on these platforms, let's just
|
75
|
+
# use that.
|
76
|
+
#
|
77
|
+
# @return [Boolean] whether the script command looks like it's working.
|
78
|
+
def use_script?
|
79
|
+
scriptfile, timingfile = record_with_script('echo', 'foo')
|
80
|
+
|
81
|
+
scriptfile =~ /foo/ && timingfile =~ /^[0-9]/
|
82
|
+
end
|
83
|
+
|
84
|
+
# Record using the modern version of 'script'
|
85
|
+
#
|
86
|
+
# @param [*String] command to run
|
87
|
+
# @return [scriptfile, timingfile]
|
35
88
|
def record_with_script(*cmd)
|
36
89
|
scriptfile, timingfile = [temp_file, temp_file]
|
37
90
|
|
38
91
|
args = ['script']
|
39
92
|
args << '-c' + cmd.join(" ") if cmd.size > 0
|
93
|
+
args << '-q'
|
40
94
|
args << '-t'
|
41
95
|
args << scriptfile.path
|
42
96
|
|
@@ -45,15 +99,13 @@ module Showterm
|
|
45
99
|
[scriptfile.open.read, timingfile.open.read]
|
46
100
|
end
|
47
101
|
|
48
|
-
def use_script?
|
49
|
-
scriptfile, timingfile = record_with_script('echo', 'foo')
|
50
|
-
|
51
|
-
scriptfile =~ /foo/ && timingfile =~ /^[0-9]/
|
52
|
-
end
|
53
102
|
|
103
|
+
# Record using the bundled version of 'ttyrec'
|
104
|
+
#
|
105
|
+
# @param [*String] command to run
|
106
|
+
# @return [scriptfile, timingfile]
|
54
107
|
def record_with_ttyrec(*cmd)
|
55
|
-
scriptfile =
|
56
|
-
scriptfile.close(false)
|
108
|
+
scriptfile = temp_file
|
57
109
|
|
58
110
|
args = [File.join(File.dirname(File.dirname(__FILE__)), 'ext/ttyrec')]
|
59
111
|
if cmd.size > 0
|
@@ -63,41 +115,9 @@ module Showterm
|
|
63
115
|
|
64
116
|
system(*args)
|
65
117
|
|
66
|
-
|
67
|
-
scriptfile.close(true)
|
68
|
-
convert(ret)
|
69
|
-
end
|
70
|
-
|
71
|
-
# Get the current width of the terminal
|
72
|
-
#
|
73
|
-
# @return [Integer] number of columns
|
74
|
-
def terminal_width
|
75
|
-
guess = `tput cols`.to_i
|
76
|
-
guess == 0 ? 80 : guess
|
118
|
+
convert(scriptfile.open.read)
|
77
119
|
end
|
78
120
|
|
79
|
-
# Upload the termshow to showterm.io
|
80
|
-
#
|
81
|
-
# @param [String] scriptfile The ANSI dump of the terminal
|
82
|
-
# @param [String] timingfile The timings
|
83
|
-
# @param [Integer] cols The width of the terminal
|
84
|
-
def upload!(scriptfile, timingfile, cols=terminal_width)
|
85
|
-
puts 'uploading, please wait.'
|
86
|
-
request = Net::HTTP::Post.new("/scripts")
|
87
|
-
request.set_form_data(:scriptfile => scriptfile,
|
88
|
-
:timingfile => timingfile,
|
89
|
-
:cols => cols)
|
90
|
-
|
91
|
-
response = http(request)
|
92
|
-
raise response.body unless Net::HTTPSuccess === response
|
93
|
-
puts response.body
|
94
|
-
rescue => e
|
95
|
-
raise if retried
|
96
|
-
retried = true
|
97
|
-
retry
|
98
|
-
end
|
99
|
-
|
100
|
-
private
|
101
121
|
|
102
122
|
# The original version of showterm used the 'script' binary.
|
103
123
|
#
|
data/showterm.gemspec
CHANGED