term-slides 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 39be56c089c1497a34db87736a1c6bfd92cfae66c30f15dca398e08d475c5090
4
- data.tar.gz: 60a483a945685053b6491355cefb882c7900d6d4a4df19d76290cdcf028b1e83
3
+ metadata.gz: 634623c4210879641f82e3d3da25252de978705ad1744e9e241d9fd5021166e9
4
+ data.tar.gz: 7093b0243258b5af5173d1d27e2b870690748258c5a600b69d166c0b94d52082
5
5
  SHA512:
6
- metadata.gz: 0504c136cb0e33737d0e913924922029b6ce0056b0c13ba76e2c6e57c34f988c52cf3a73a682524a3948cc158b4e93b3d8305a9fe237228f385f65959ec56f35
7
- data.tar.gz: 16929e079368e042f4bba8fab7b1cdbd6f003bcfd894901f7c1837562e0dc2524f56aa9dd7ecd3ba0094bb33f3519612b614494447edfa7a710044c61abeb413
6
+ metadata.gz: f4d580861d5d89e77cb5a635287d8c2f18cdfde3777cf80edf544c4bf00d51908bdd0afe325bee8a062da57725103ca032dc63251da397596824d65b4a014e4f
7
+ data.tar.gz: f3fb4db4ccaf368cbabecbc613f919efac1c81043d55c77a272a70c2535fc437add686deee254d7608d8456df5d704167df6a1bdf747e12587c93421ab14198f
data/lib/term/slides.rb CHANGED
@@ -1,241 +1,239 @@
1
1
  require "term/slides/version"
2
2
 
3
3
  module Term
4
- module Slides
5
- class Error < StandardError; end
6
- require 'io/console'
7
- require 'colorize'
8
- require 'tty-table'
9
- require 'tty-command'
10
- require 'highline'
4
+ class Error < StandardError; end
5
+ require 'io/console'
6
+ require 'colorize'
7
+ require 'tty-table'
8
+ require 'tty-command'
9
+ require 'highline'
11
10
 
12
- class TTYRenderer
13
- def render_code code
14
- path = "code.#{code.format}"
15
- File.write(path, code.content)
16
- out, err = TTY::Command.new(pty: true, printer: :null).run('vimcat', path)
17
- puts out
18
- end
19
- def render_table table
20
- puts center(TTY::Table.new(table.headers, table.rows).render(:unicode))
21
- end
22
- def center text
23
- width = HighLine::SystemExtensions.terminal_size.first
24
- text.split("\n").map { |x| x.center(width) }.join("\n")
25
- end
26
- def render_text text
27
- puts center(text.text)
28
- end
29
- def render_image_file src
30
- kitty = '/Applications/kitty.app/Contents/MacOS/kitty'
31
- kitty = 'kitty' unless File.exists? kitty
32
- `#{kitty} +kitten icat #{src}`
33
- end
34
- def render_image image
35
- render_image_file image.src
36
- end
37
- def render_diagram diagram
38
- render_image_file diagram.build
39
- end
40
- def render_slide slide
41
- puts center(slide.name.colorize(:light_blue).bold)
42
- puts
43
- slide.content.each { |c| c.render }
44
- end
11
+ class TTYRenderer
12
+ def render_code code
13
+ path = "code.#{code.format}"
14
+ File.write(path, code.content)
15
+ out, err = TTY::Command.new(pty: true, printer: :null).run('vimcat', path)
16
+ puts out
17
+ end
18
+ def render_table table
19
+ puts center(TTY::Table.new(table.headers, table.rows).render(:unicode))
20
+ end
21
+ def center text
22
+ width = HighLine::SystemExtensions.terminal_size.first
23
+ text.split("\n").map { |x| x.center(width) }.join("\n")
45
24
  end
25
+ def render_text text
26
+ puts center(text.text)
27
+ end
28
+ def render_image_file src
29
+ kitty = '/Applications/kitty.app/Contents/MacOS/kitty'
30
+ kitty = 'kitty' unless File.exists? kitty
31
+ `#{kitty} +kitten icat #{src}`
32
+ end
33
+ def render_image image
34
+ render_image_file image.src
35
+ end
36
+ def render_diagram diagram
37
+ render_image_file diagram.build
38
+ end
39
+ def render_slide slide
40
+ puts center(slide.name.colorize(:light_blue).bold)
41
+ puts
42
+ slide.content.each { |c| c.render }
43
+ end
44
+ end
46
45
 
47
- class HovercraftRenderer
48
- def render_code code
49
- puts ".. code:: #{code.format}"
50
- puts
51
- puts code.content.gsub(/^/, " ")
52
- end
53
- def render_table table
54
- puts
55
- puts ".. table::"
56
- puts
57
- a = TTY::Table.new(table.headers, table.rows).render(:ascii).split("\n")
58
- s = (a[0..2] + a[3..-1].map { |l| l += "\n#{a[0]}"}).join("\n")
59
- puts s.gsub(/^/, " ")
60
- puts
61
- end
62
- def render_text text
63
- puts text.text
64
- end
65
- def render_image image
66
- puts ".. image:: #{image.src}"
67
- end
68
- def render_diagram diagram
69
- puts ".. image:: #{diagram.build}"
70
- puts " :width: #{diagram.width}" if not diagram.width.nil?
71
- puts " :height: #{diagram.height}" if not diagram.height.nil?
72
- puts
73
- end
74
- def render_slide slide
75
- puts
76
- puts slide.name
77
- puts slide.name.gsub(/./, "=")
78
- puts
79
- slide.content.each { |c| c.render }
80
- puts
81
- puts "----"
82
- puts
83
- end
46
+ class HovercraftRenderer
47
+ def render_code code
48
+ puts ".. code:: #{code.format}"
49
+ puts
50
+ puts code.content.gsub(/^/, " ")
51
+ end
52
+ def render_table table
53
+ puts
54
+ puts ".. table::"
55
+ puts
56
+ a = TTY::Table.new(table.headers, table.rows).render(:ascii).split("\n")
57
+ s = (a[0..2] + a[3..-1].map { |l| l += "\n#{a[0]}"}).join("\n")
58
+ puts s.gsub(/^/, " ")
59
+ puts
60
+ end
61
+ def render_text text
62
+ puts text.text
63
+ end
64
+ def render_image image
65
+ puts ".. image:: #{image.src}"
84
66
  end
67
+ def render_diagram diagram
68
+ puts ".. image:: #{diagram.build}"
69
+ puts " :width: #{diagram.width}" if not diagram.width.nil?
70
+ puts " :height: #{diagram.height}" if not diagram.height.nil?
71
+ puts
72
+ end
73
+ def render_slide slide
74
+ puts
75
+ puts slide.name
76
+ puts slide.name.gsub(/./, "=")
77
+ puts
78
+ slide.content.each { |c| c.render }
79
+ puts
80
+ puts "----"
81
+ puts
82
+ end
83
+ end
85
84
 
86
- class Code
87
- attr_reader :format, :content
88
- def initialize renderer, format, content
89
- @renderer = renderer
90
- @format = format
91
- @content = content
92
- end
93
- def render
94
- @renderer.render_code self
95
- end
85
+ class Code
86
+ attr_reader :format, :content
87
+ def initialize renderer, format, content
88
+ @renderer = renderer
89
+ @format = format
90
+ @content = content
96
91
  end
92
+ def render
93
+ @renderer.render_code self
94
+ end
95
+ end
97
96
 
98
- class Table
99
- attr_reader :rows, :headers
100
- def row *r
101
- @rows << r
102
- end
103
- def initialize renderer, headers, &block
104
- @renderer = renderer
105
- @headers = headers
106
- @rows = []
107
- instance_eval &block
108
- end
109
- def render
110
- @renderer.render_table self
111
- end
97
+ class Table
98
+ attr_reader :rows, :headers
99
+ def row *r
100
+ @rows << r
112
101
  end
102
+ def initialize renderer, headers, &block
103
+ @renderer = renderer
104
+ @headers = headers
105
+ @rows = []
106
+ instance_eval &block
107
+ end
108
+ def render
109
+ @renderer.render_table self
110
+ end
111
+ end
113
112
 
114
- class Text
115
- attr_reader :text
116
- def initialize renderer, text
117
- @renderer = renderer
118
- @text = text
119
- end
113
+ class Text
114
+ attr_reader :text
115
+ def initialize renderer, text
116
+ @renderer = renderer
117
+ @text = text
118
+ end
120
119
 
121
- def render
122
- @renderer.render_text self
123
- end
120
+ def render
121
+ @renderer.render_text self
124
122
  end
123
+ end
125
124
 
126
- class Diagram
127
- attr_reader :dot, :width, :height
128
- def initialize renderer, dot, width = nil, height = nil
129
- @renderer = renderer
130
- @dot = dot
131
- @width = width
132
- @height = height
133
- end
134
- def build
135
- $i ||= 0
136
- path = "graph#{$i}.png"
137
- `echo "#{@dot.gsub('"', '\\"')}" | dot -Tpng > #{path}`
138
- $i += 1
139
- path
140
- end
141
- def render
142
- @renderer.render_diagram self
143
- end
125
+ class Diagram
126
+ attr_reader :dot, :width, :height
127
+ def initialize renderer, dot, width = nil, height = nil
128
+ @renderer = renderer
129
+ @dot = dot
130
+ @width = width
131
+ @height = height
132
+ end
133
+ def build
134
+ $i ||= 0
135
+ path = "graph#{$i}.png"
136
+ `echo "#{@dot.gsub('"', '\\"')}" | dot -Tpng > #{path}`
137
+ $i += 1
138
+ path
139
+ end
140
+ def render
141
+ @renderer.render_diagram self
144
142
  end
143
+ end
145
144
 
146
- class Image
147
- attr_reader :src
148
- def initialize renderer, src
149
- @renderer = renderer
150
- @src = src
151
- end
152
- def render
153
- @renderer.render_image self
154
- end
145
+ class Image
146
+ attr_reader :src
147
+ def initialize renderer, src
148
+ @renderer = renderer
149
+ @src = src
150
+ end
151
+ def render
152
+ @renderer.render_image self
155
153
  end
154
+ end
156
155
 
157
- class Slide
158
- attr_accessor :name, :content, :renderer
159
- def text s
160
- @content << Text.new(@renderer, s)
161
- end
162
- alias t text
163
- def code format, s
164
- @content << Code.new(@renderer, format, s)
165
- end
166
- def table *headers, &block
167
- @content << Table.new(@renderer, headers, &block)
168
- end
169
- def diagram dot
170
- @content << Diagram.new(@renderer, dot)
171
- end
172
- def image src
173
- @content << Image.new(@renderer, src)
174
- end
175
- def initialize renderer, name, &block
176
- @renderer = renderer
177
- @name = name
178
- @content = []
179
- instance_eval &block
180
- end
181
- def render
182
- @renderer.render_slide self
183
- end
156
+ class Slide
157
+ attr_accessor :name, :content, :renderer
158
+ def text s
159
+ @content << Text.new(@renderer, s)
160
+ end
161
+ alias t text
162
+ def code format, s
163
+ @content << Code.new(@renderer, format, s)
164
+ end
165
+ def table *headers, &block
166
+ @content << Table.new(@renderer, headers, &block)
167
+ end
168
+ def diagram dot
169
+ @content << Diagram.new(@renderer, dot)
170
+ end
171
+ def image src
172
+ @content << Image.new(@renderer, src)
184
173
  end
174
+ def initialize renderer, name, &block
175
+ @renderer = renderer
176
+ @name = name
177
+ @content = []
178
+ instance_eval &block
179
+ end
180
+ def render
181
+ @renderer.render_slide self
182
+ end
183
+ end
185
184
 
186
- class Slides
187
- def slide name, &block
188
- @slides << Slide.new(@renderer, name, &block)
189
- end
190
- def initialize args, &block
191
- @args = args
192
- if @args.size > 0 and @args[0] == "hovercraft"
193
- @renderer = HovercraftRenderer.new
194
- else
195
- @renderer = TTYRenderer.new
196
- end
197
- @slides = []
198
- instance_eval &block
199
- end
200
- def read_char
201
- STDIN.echo = false
202
- STDIN.raw!
185
+ class Slides
186
+ def slide name, &block
187
+ @slides << Slide.new(@renderer, name, &block)
188
+ end
189
+ def initialize args, &block
190
+ @args = args
191
+ if @args.size > 0 and @args[0] == "hovercraft"
192
+ @renderer = HovercraftRenderer.new
193
+ else
194
+ @renderer = TTYRenderer.new
195
+ end
196
+ @slides = []
197
+ instance_eval &block
198
+ end
199
+ def read_char
200
+ STDIN.echo = false
201
+ STDIN.raw!
203
202
 
204
- input = STDIN.getc.chr
205
- if input == "\e" then
206
- input << STDIN.read_nonblock(3) rescue nil
207
- input << STDIN.read_nonblock(2) rescue nil
208
- end
209
- ensure
210
- STDIN.echo = true
211
- STDIN.cooked!
203
+ input = STDIN.getc.chr
204
+ if input == "\e" then
205
+ input << STDIN.read_nonblock(3) rescue nil
206
+ input << STDIN.read_nonblock(2) rescue nil
207
+ end
208
+ ensure
209
+ STDIN.echo = true
210
+ STDIN.cooked!
212
211
 
213
- return input
214
- end
215
- def run
216
- i = 0
217
- if @args.size > 0
218
- if @args[0] == "hovercraft"
219
- @slides.each do |slide|
220
- slide.render
221
- end
222
- else
223
- @slides[@args[0].to_i].render
212
+ return input
213
+ end
214
+ def run
215
+ i = 0
216
+ if @args.size > 0
217
+ if @args[0] == "hovercraft"
218
+ @slides.each do |slide|
219
+ slide.render
224
220
  end
225
- return
221
+ else
222
+ @slides[@args[0].to_i].render
226
223
  end
227
- while true
228
- puts `clear`
229
- puts "#{i + 1}/#{@slides.size}"
230
- @slides[i].render
231
- s = read_char
232
- if s == "q"
233
- break
234
- elsif s == "p"
235
- i -= 1 if i > 0
236
- elsif s == "n"
237
- i += 1 if i < (@slides.size - 1)
238
- end
224
+ return
225
+ end
226
+ while true
227
+ puts `clear`
228
+ puts "#{i + 1}/#{@slides.size}"
229
+ @slides[i].render
230
+ s = read_char
231
+ if s == "q"
232
+ break
233
+ elsif s == "p"
234
+ i -= 1 if i > 0
235
+ elsif s == "n"
236
+ i += 1 if i < (@slides.size - 1)
239
237
  end
240
238
  end
241
239
  end
@@ -1,5 +1,5 @@
1
1
  module Term
2
2
  module Slides
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: term-slides
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - yazgoo