showterm 0.2.7 → 0.3.0

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.
Files changed (4) hide show
  1. data/bin/showterm +115 -66
  2. data/lib/showterm.rb +1 -0
  3. data/showterm.gemspec +1 -1
  4. metadata +19 -37
data/bin/showterm CHANGED
@@ -3,81 +3,130 @@
3
3
  require 'readline'
4
4
  require File.join(File.dirname(File.dirname(__FILE__)), 'lib/showterm')
5
5
 
6
- if '-e' == ARGV[0]
7
- $edit_timings = true
8
- ARGV.shift
9
- end
6
+ class Showterm::Main
10
7
 
11
- if ARGV.include?('-h') || ARGV.include?('--help')
12
- puts <<-EOF
13
- Usage: showterm [-e] <command to run>
8
+ def run
9
+ if ARGV.include?('-h') || ARGV.include?('--help')
14
10
 
15
- showterm will record the exact output of your session, and upload it to the
16
- internet where it can be replayed by anyone to whom you give the URL.
11
+ help
17
12
 
18
- You can pass `-e` as the first arg and it will allow you to edit the timings
19
- file before uploading. This can be nice if you want to take long pauses (such
20
- as searching an answer out) in between commands.
21
- EOF
22
- exit
23
- end
13
+ elsif ARGV[0] == '--retry'
14
+
15
+ ARGV.shift
16
+ reupload
17
+
18
+ else
24
19
 
25
- def save which, data
26
- path = "/tmp/showtime.#$$.#{which}"
27
- File.open(path, 'w') do |f|
28
- f.write(data)
20
+ if '-e' == ARGV[0] || '--edit' == ARGV[0]
21
+ @edit_timings = true
22
+ ARGV.shift
23
+ end
24
+
25
+ sf, tf = record
26
+ sf, tf = edit(sf, tf) if @edit_timings
27
+ upload sf, tf
28
+ end
29
29
  end
30
- path
31
- end
32
30
 
33
- def leave_trace message, sf, tf
34
- script_path = save 'script', sf
35
- times_path = save 'times', tf
36
- puts message
37
- puts %(your work is safe in "#{script_path}" and "#{times_path}")
38
- puts "To try uploading manually, use:"
39
- puts %(ruby -rshowterm -e'Showterm.upload! File.read("/tmp/showtime.#$$.script"), File.read("/tmp/showtime.#$$.times")')
40
- end
31
+ def record
32
+ puts 'showterm recording. (Exit shell when done.)'
33
+ sf, tf = Showterm.record!(*ARGV)
34
+ puts 'showterm recording finished.'
35
+ [sf, tf]
36
+ end
37
+
38
+ def help
39
+ puts <<-EOF
40
+ Usage: showterm [-e] <command to run>
41
+
42
+ showterm will record the exact output of your session, and upload it to the
43
+ internet where it can be replayed by anyone to whom you give the URL.
44
+
45
+ You can pass `-e` as the first arg and it will allow you to edit the timings
46
+ file before uploading. This can be nice if you want to take long pauses (such
47
+ as searching an answer out) in between commands.
48
+ EOF
49
+ end
50
+
51
+ def reupload
52
+ if ARGV.size == 2
53
+ upload(*ARGV.map{ |path| File.read(path) })
54
+ else
55
+ puts "Usage: showterm --retry <scriptfile> <timesfile>"
56
+ end
57
+ end
58
+
59
+ def upload(sf, tf)
60
+ puts "Uploading..."
61
+ puts Showterm.upload! sf, tf
62
+ rescue => e
63
+ puts [e] + e.backtrace
64
+ puts "-" * 80
65
+ die_politely "DON'T PANIC", sf, tf
66
+ end
41
67
 
42
- puts 'showterm recording. (Exit shell when done.)'
43
- sf, tf = Showterm.record! *ARGV
44
- puts 'showterm recording finished.'
45
-
46
- if $edit_timings
47
- editor = ENV.fetch('VISUAL', ENV.fetch('EDITOR', 'vim'))
48
- tips = if 'vim' == editor
49
- <<-TIPS
50
- Hot vim tips:
51
- Use :cq from vim to exit nonzero, and cancel the upload
52
- Use :%s/^[0-9]\./0./ to get rid of all longish pauses.
53
- TIPS
54
- else
55
- <<-CONSOLATION_TIPS
56
- If you can make your editor return nonzero, it will cancel the upload.
57
- CONSOLATION_TIPS
68
+ def edit(sf, tf)
69
+ prepare_to_edit
70
+
71
+ times_path = save 'times', tf
72
+ success = system(editor, times_path)
73
+ if success
74
+ tf = File.read(times_path)
75
+ else
76
+ die_politely "OK, discarding edits and skipping upload.", sf, tf
77
+ end
78
+
79
+ [sf, tf]
80
+ end
81
+
82
+ def prepare_to_edit
83
+ puts "Recording done, now it's time to dress up those timings!" +
84
+ if 'vim' == editor
85
+ <<-TIPS
86
+ Hot vim tips:
87
+
88
+ Use :cq from vim to exit nonzero, and cancel the upload
89
+ Use :%s/^[0-9]\./0./ to get rid of all longish pauses.
90
+ TIPS
91
+ else
92
+ "If you can make your editor return nonzero, it will cancel the upload."
93
+ end +
94
+ "[Hit Enter to edit]"
95
+
96
+ $stdin.readline
97
+ end
98
+
99
+ def save(which, data)
100
+ path = "/tmp/showtime.#$$.#{which}"
101
+ File.open(path, 'w') do |f|
102
+ f.write(data)
103
+ end
104
+ path
58
105
  end
59
- puts <<-TEXT
60
-
61
- Recording done, now it's time to dress up those timings!
62
- #{tips}
63
- [Hit Enter to edit]
64
- TEXT
65
- $stdin.readline
66
- times_path = save 'times', tf
67
- success = system(editor, times_path)
68
- if success
69
- tf = File.read(times_path)
70
- else
71
- leave_trace "OK, discarding edits and skipping upload.", sf, tf
106
+
107
+ def die_politely(message, sf, tf)
108
+ script_path = save 'script', sf
109
+ times_path = save 'times', tf
110
+ puts <<-MESSAGE
111
+ #{message}
112
+ your work is safe in "#{script_path}" and "#{times_path}"
113
+ To try uploading manually, use:
114
+ showterm --retry "#{script_path}" "#{times_path}"
115
+ MESSAGE
72
116
  exit 1
73
117
  end
74
- end
75
118
 
76
- begin
77
- puts "Uploading..."
78
- puts Showterm.upload! sf, tf
79
- rescue => e
80
- puts [e] + e.backtrace
81
- puts "-" * 80
82
- leave_trace "DON'T PANIC", sf, tf
119
+ def dedent(str)
120
+ str.split("\n").map(&:lstrip).join("\n")
121
+ end
122
+
123
+ def puts(str, *a)
124
+ super(String === str ? dedent(str) : str, *a)
125
+ end
126
+
127
+ def editor
128
+ ENV.fetch('VISUAL', ENV.fetch('EDITOR', 'vim'))
129
+ end
83
130
  end
131
+
132
+ Showterm::Main.new.run
data/lib/showterm.rb CHANGED
@@ -35,6 +35,7 @@ module Showterm
35
35
  # @param [String] timingfile The timings
36
36
  # @param [Integer] cols The width of the terminal
37
37
  def upload!(scriptfile, timingfile, cols=terminal_width)
38
+ retried ||= false
38
39
  request = Net::HTTP::Post.new("/scripts")
39
40
  request.set_form_data(:scriptfile => scriptfile,
40
41
  :timingfile => timingfile,
data/showterm.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "showterm"
3
- s.version = "0.2.7"
3
+ s.version = "0.3.0"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.author = "Conrad Irwin"
6
6
  s.email = "conrad.irwin@gmail.com"
metadata CHANGED
@@ -1,32 +1,24 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: showterm
3
- version: !ruby/object:Gem::Version
4
- hash: 25
3
+ version: !ruby/object:Gem::Version
5
4
  prerelease:
6
- segments:
7
- - 0
8
- - 2
9
- - 7
10
- version: 0.2.7
5
+ version: 0.3.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Conrad Irwin
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-11-06 00:00:00 Z
12
+ date: 2012-12-26 00:00:00.000000000 Z
19
13
  dependencies: []
20
-
21
14
  description: Integrates with showterm.io for awesome sharability.
22
15
  email: conrad.irwin@gmail.com
23
- executables:
16
+ executables:
24
17
  - showterm
25
- extensions:
18
+ extensions:
26
19
  - ext/extconf.rb
27
20
  extra_rdoc_files: []
28
-
29
- files:
21
+ files:
30
22
  - LICENSE.MIT
31
23
  - README.md
32
24
  - bin/showterm
@@ -46,37 +38,27 @@ files:
46
38
  - showterm.gemspec
47
39
  homepage: http://github.com/Conradirwin/showterm
48
40
  licenses: []
49
-
50
41
  post_install_message:
51
42
  rdoc_options: []
52
-
53
- require_paths:
43
+ require_paths:
54
44
  - lib
55
- required_ruby_version: !ruby/object:Gem::Requirement
45
+ required_ruby_version: !ruby/object:Gem::Requirement
56
46
  none: false
57
- requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- hash: 3
61
- segments:
62
- - 0
63
- version: "0"
64
- required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
52
  none: false
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- hash: 3
70
- segments:
71
- - 0
72
- version: "0"
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
73
57
  requirements: []
74
-
75
58
  rubyforge_project:
76
59
  rubygems_version: 1.8.24
77
60
  signing_key:
78
61
  specification_version: 3
79
62
  summary: Allows you to make screen casts of your terminal really easily
80
63
  test_files: []
81
-
82
64
  has_rdoc: