cheap-impression-presenter 1.2.1 → 1.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4209c6083d151bd361c30b8f9023a0423129a9c574dbbbbf1a985604b92ce613
4
- data.tar.gz: fdeae446fbbab6131e8c9057f8497742216e236e23c435fda32faebb3d13eb50
3
+ metadata.gz: 5c1332225abcc4dbf7775e4b0d37f307f4064534c6d4b0f8bdebb2807e24a8ca
4
+ data.tar.gz: 5c485763345a02c618718f58129f9440caef86aff4e370e44dce152bf57034e1
5
5
  SHA512:
6
- metadata.gz: 9871191241cc17fff202da966deafa55bc51f05300d02d19608e165d1cb52f902ec8a859787f08091ba2f49d086a399769d770eccec0c68e87ad39e1b25eb29b
7
- data.tar.gz: ed9f7d89cd31fc5f9f97257795d2116b38aac833b475e8ca37076932aa55b3e4d9356d8803368cdde545d09060aa5dc43650d7b13b4600a78e932af859870c51
6
+ metadata.gz: 7518a354e8a650be9caaefdbd29904303105d270f283f2f5c5a73359f88f552d37383385eb056735983e6266c2153c9920c5f657e3ed89164fad715239eef58f
7
+ data.tar.gz: c5dd43b178bb625374aee939d50ae607fc4d5bba7e140e0a269c4d1bb059658a8f62e68e86ff08239f606d7d1cd6b56247a21e7df737aa9170ff9a3e0d081750
data/README.md CHANGED
@@ -12,7 +12,7 @@ Make a cheap impression. Present via terminal.
12
12
 
13
13
  ```gem install cheap-impression-presenter```
14
14
 
15
- The ruby gems it needs (tty-screen, pastel, hexapdf) are installed with it. Some
15
+ The ruby gems it needs (redel, tty-screen, pastel, hexapdf) are installed with it. Some
16
16
  features need external programs, which have to be installed separately (all are
17
17
  available in the usual linux distributions and homebrew):
18
18
 
data/chimp.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cheap-impression-presenter"
3
- s.version = "1.2.1"
3
+ s.version = "1.2.2"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.license = "GPL-3.0-or-later"
6
6
  s.summary = "CHIMP - Make a cheap impression. Present via terminal."
@@ -13,13 +13,14 @@ Gem::Specification.new do |s|
13
13
  s.bindir = 'tools'
14
14
  s.executables = ['chimp']
15
15
 
16
- s.required_ruby_version = '>=2.7.0'
16
+ s.required_ruby_version = '>=3.2'
17
17
 
18
18
  s.authors = ['Juergen eTM Mangler']
19
19
 
20
20
  s.email = 'juergen.mangler@gmail.com'
21
21
  s.homepage = 'https://github.com/etm/chimp'
22
22
 
23
+ s.add_runtime_dependency 'redel', '~> 3.1'
23
24
  s.add_runtime_dependency 'tty-screen', '~> 0.8'
24
25
  s.add_runtime_dependency 'pastel', '~> 0.8'
25
26
  s.add_runtime_dependency 'hexapdf', '~> 1.0'
@@ -3,7 +3,7 @@ require_relative 'ChimpParser'
3
3
  module Chimp
4
4
  class Parser
5
5
 
6
- class SimpleGrammar < Grammar
6
+ class SimpleGrammar < ReDel::Grammar
7
7
  #### Patterns ####
8
8
  #### Name of pattern has to be the first parameter to pattern ####
9
9
  #### According to the names the methods are selected ####
@@ -35,6 +35,11 @@ module Chimp
35
35
  GP_TEMPLATE = GP_INCREMENTAL
36
36
  GP_CENTER = [ P_STRONGRED, P_STRONGBLUE, P_STRONG, P_RED, P_BLUE ]
37
37
 
38
+ def initialize(parameters={})
39
+ super()
40
+ @parameters = parameters
41
+ end
42
+
38
43
  ### Optional functions called when a pattern occurs (m + patternname) ####
39
44
  def mP_INCLUDE(ts,ti,te)
40
45
  @tree.last.data = {}
data/lib/ChimpParser.rb CHANGED
@@ -1,33 +1,8 @@
1
- require 'strscan'
2
- require 'pp'
1
+ require 'redel/parser'
3
2
 
4
3
  module Chimp
5
4
  class Parser
6
- class OpenTag
7
- attr_reader :ttype, :level
8
- attr_accessor :data, :close, :userdata
9
- def initialize(ttype,level)
10
- @ttype = ttype
11
- @data = nil
12
- @close = -1
13
- @userdata = nil
14
- @level = level
15
- end
16
- end
17
- class CloseTag
18
- attr_reader :ttype, :open, :position_in_markup, :level
19
- def initialize(ttype,open,position_in_markup,level)
20
- @ttype = ttype
21
- @open = open
22
- @position_in_markup = position_in_markup
23
- @level = level
24
- end
25
- end
26
-
27
- class TagEvent < Exception; end
28
- class TagSkipEvent < Exception; end
29
5
  class TagMoveEvent < Exception; end
30
- class TagContentSkipEvent < Exception; end
31
6
  class ReloadEvent < Exception
32
7
  attr_reader :goto # [slide, step] to return to after reloading
33
8
  def initialize(goto)
@@ -36,25 +11,55 @@ module Chimp
36
11
  end
37
12
  end
38
13
 
39
- class Output
14
+ class Output < ReDel::Output
40
15
  SIZE = 26 # default number of lines of a slide (including the footer), #size: overrides
41
16
 
42
- def finish_prepare
43
- end
44
- def finish_output
45
- ""
17
+ #### called by redel with the whole tree, as presenting also has to move back and forth in it
18
+ def render(tree)
19
+ prepare tree
20
+ out = +''; i = 0
21
+ while tree.length > i
22
+ c = tree[i]
23
+ begin
24
+ out << dispatch(tree,i).to_s
25
+ i += 1
26
+ rescue NameError
27
+ i += 1
28
+ rescue ReDel::TagSkipError
29
+ i = c.close + 1
30
+ rescue TagMoveEvent => e
31
+ i = e.message.to_i
32
+ end
33
+ end
34
+ out << finish_output.to_s
46
35
  end
47
- def string(data)
48
- data
36
+
37
+ #### calls the prepare methods (mP + patternname) for everything that has to be known before the output starts
38
+ def prepare(tree)
39
+ tree.each_with_index do |c,i|
40
+ next unless c.is_a?(ReDel::OpenTag)
41
+ begin
42
+ met = method("mP" + c.type)
43
+ case met.arity
44
+ when 0; met.call
45
+ when 1; met.call(c.data)
46
+ when 2; met.call(c,tree)
47
+ when 3; met.call(c,tree,i)
48
+ end
49
+ rescue NameError
50
+ end
51
+ end
52
+ finish_prepare
49
53
  end
54
+ private :prepare
50
55
 
51
56
  #### calls the output method for element i of the tree, raises NameError if there is none
52
57
  def dispatch(tree,i)
53
58
  c = tree[i]
54
59
  met, data = case c
55
60
  when String then [method("string"), c]
56
- when OpenTag then [method("mO" + c.ttype), c.data]
57
- when CloseTag then [method("mC" + c.ttype), tree[c.open].data]
61
+ when ReDel::OpenTag then [method("mO" + c.type), c.data]
62
+ when ReDel::CloseTag then [method("mC" + c.type), tree[c.open].data]
58
63
  end
59
64
  case met.arity
60
65
  when 0; met.call
@@ -78,157 +83,5 @@ module Chimp
78
83
  end
79
84
  end
80
85
 
81
- class Grammar
82
- attr_reader :tree # a list which pretends to be a tree :-)
83
-
84
- class Pattern
85
- attr_reader :ptype, :pstart, :pend, :bol
86
- def initialize(ptype, pstart, pend, bol=false)
87
- @ptype = ptype
88
- @pstart = pstart
89
- @pend = pend
90
- @bol = bol
91
- end
92
- end
93
-
94
- def initialize
95
- @tree = []
96
- @parameters = {}
97
- end
98
-
99
- def Grammar.parse(text,params = {})
100
- new.parse(text,params)
101
- end
102
-
103
- def parse(text,params = {})
104
- @parameters = params
105
- gparse(text,self.class::constants.include?(:ROOT) ? self.class::ROOT : [])
106
- self
107
- end
108
-
109
- def inspect
110
- out = ""; indent = ""
111
- @tree.each do |c|
112
- indent = indent[0..-3] if c.class == CloseTag
113
- out << indent + c.inspect + "\n"
114
- indent << " " if c.class == OpenTag
115
- end
116
- out
117
- end
118
-
119
- def output(output)
120
- out = ''; i = 0
121
- while @tree.length > i
122
- c = @tree[i]
123
- begin
124
- out << output.dispatch(@tree,i).to_s
125
-
126
- i += 1
127
- rescue NameError => e
128
- i += 1
129
- rescue TagSkipEvent
130
- i = c.close + 1 if c.class == OpenTag
131
- rescue TagContentSkipEvent
132
- i = c.close if c.class == OpenTag
133
- rescue TagMoveEvent => e
134
- i = e.message.to_i
135
- ensure
136
- begin
137
- unless @tree.length > i
138
- met = output.method("finish_output")
139
- out << case met.arity
140
- when 0; met.call
141
- when 1; met.call(@tree)
142
- else
143
- ""
144
- end.to_s
145
- end
146
- rescue TagMoveEvent => e
147
- i = e.message.to_i
148
- end
149
- end
150
- end
151
- out
152
- end
153
-
154
- def prepare(output)
155
- @tree.each_with_index do |c,i|
156
- begin
157
- if c.class == OpenTag
158
- met = output.method("mP" + c.ttype)
159
- case met.arity
160
- when 0; met.call
161
- when 1; met.call(c.data)
162
- when 2; met.call(c,@tree)
163
- when 3; met.call(c,@tree,i)
164
- end
165
- end
166
- rescue NameError
167
- rescue TagSkipEvent
168
- rescue TagContentSkipEvent
169
- rescue TagMoveEvent
170
- end
171
- end
172
- output.method("finish_prepare").call
173
- self
174
- end
175
-
176
- def gparse(text,grammar,position_in_markup=0,level=0)
177
- return if text.nil?
178
- s = StringScanner.new(text)
179
- while !s.eos?
180
- success = false
181
- grammar.each do |pat|
182
- if s.match?(pat.pstart)
183
- pos = s.pos
184
- bol = (pos == 0) ? true : s.string[pos-1] == "\n"
185
- ts = s.scan(pat.pstart)
186
- te = if s.eos?
187
- "" =~ pat.pend ? "" : nil
188
- else
189
- (pat.bol && !bol) ? nil : s.scan_until(pat.pend)
190
- end
191
-
192
- if te.nil?
193
- s.pos = pos
194
- else
195
- ti = te.sub(pat.pend,"")
196
- te = te[ti.length..-1]
197
- @tree << ot = OpenTag.new(pat.ptype,level)
198
- tpos = @tree.length-1
199
- inner = begin
200
- self.method("m" + pat.ptype).call(ts,ti,te)
201
- rescue NameError
202
- ti
203
- rescue TagEvent
204
- @tree.pop
205
- s.pos = pos
206
- next
207
- rescue TagSkipEvent
208
- @tree.pop
209
- success = true
210
- next
211
- end
212
- gparse(inner,self.class::constants.include?(("G" + pat.ptype).to_sym) ? self.class::const_get(("G" + pat.ptype).to_sym) : [],position_in_markup+pos+ts.length,level+1)
213
- @tree << CloseTag.new(pat.ptype,tpos,position_in_markup+s.pos,level)
214
- ot.close = @tree.length-1
215
- success = true
216
- break
217
- end
218
- end
219
- end
220
- unless success
221
- if @tree.last.class == String
222
- @tree.last << s.getch
223
- else
224
- @tree << s.getch
225
- end
226
- end
227
- end
228
- end
229
-
230
- private :gparse
231
- end
232
-
233
86
  end
234
87
  end
data/lib/output/pdf.rb CHANGED
@@ -152,14 +152,14 @@ module Chimp
152
152
  end #}}}
153
153
 
154
154
  def mOP_SLIDES(c,tree)
155
- @page = c.userdata
155
+ @page = c.data
156
156
  @screen.clear
157
157
  template tree
158
158
  end
159
159
  #### every +++ step (animation frame) becomes a page of its own
160
160
  def mOP_INCREMENTAL(c,tree); end
161
161
  def mCP_INCREMENTAL(c,tree,i)
162
- render
162
+ render_page
163
163
  end
164
164
 
165
165
  #### plugins only need to prepare things for the terminal
@@ -183,7 +183,7 @@ module Chimp
183
183
  [img, (width * @cw * h / w / @rowh).ceil]
184
184
  end #}}}
185
185
 
186
- def render #{{{
186
+ def render_page #{{{
187
187
  return if @page.nil?
188
188
  canvas = @doc.pages.add([0, 0, WIDTH, HEIGHT]).canvas
189
189
  canvas.fill_color(@theme[:background]).rectangle(0, 0, WIDTH, HEIGHT).fill
@@ -221,7 +221,7 @@ module Chimp
221
221
  def baseline(y)
222
222
  top(y) - (@rowh + @fsize * 0.6) / 2
223
223
  end
224
- private :render, :top, :baseline
224
+ private :render_page, :top, :baseline
225
225
 
226
226
  end
227
227
  end
data/lib/output/screen.rb CHANGED
@@ -152,13 +152,13 @@ module Chimp
152
152
  #{{{
153
153
  @scounter += 1
154
154
  @ccounter += 1
155
- c.userdata = @ccounter
155
+ c.data = @ccounter
156
156
  #}}}
157
157
  end
158
158
  def mOP_SLIDES(c,tree)
159
159
  #{{{
160
160
  ### after a reload, skip the slides before the one we were on
161
- raise TagSkipEvent if @goto && c.userdata < [@goto[0], @scounter].min
161
+ raise ReDel::TagSkipError if @goto && c.data <[@goto[0], @scounter].min
162
162
  @screen.clear
163
163
  lines = @screen.lines
164
164
  columns = @screen.columns
@@ -167,7 +167,7 @@ module Chimp
167
167
  @screen.print (lines > @size ? ("-"*(columns-1) + "^") : "-"*columns)
168
168
  @screen.set_pos 0, lines
169
169
  @screen.print @what
170
- num = "#{c.userdata}/#{@scounter}"
170
+ num = "#{c.data}/#{@scounter}"
171
171
  @screen.set_pos columns-num.length+1, lines
172
172
  @screen.print num
173
173
  @screen.set_pos 0, 0
@@ -179,7 +179,7 @@ module Chimp
179
179
  @templates << [i+1, c.close-1]
180
180
  end
181
181
  def mOP_TEMPLATE(data)
182
- raise TagSkipEvent
182
+ raise ReDel::TagSkipError
183
183
  end
184
184
 
185
185
  def mPP_INCREMENTAL(c,tree,i)
@@ -188,12 +188,12 @@ module Chimp
188
188
  def mOP_INCREMENTAL(c,tree)
189
189
  @x, @y = @screen.get_pos
190
190
  @drawn = []
191
- c.userdata = { :x => @x, :y => @y, :drawn => @drawn }
191
+ c.data = { :x => @x, :y => @y, :drawn => @drawn }
192
192
  end
193
193
  #### the slide the incremental closing at i belongs to, which step it is, and how many steps the slide has
194
194
  def position(tree,i)
195
- b = i.downto(0).find { |x| tree[x].class == OpenTag && tree[x].ttype == "P_SLIDES" }
196
- steps = tree[b..tree[b].close].select { |t| t.class == CloseTag && t.ttype == "P_INCREMENTAL" }
195
+ b = i.downto(0).find { |x| tree[x].class == ReDel::OpenTag && tree[x].type == "P_SLIDES" }
196
+ steps = tree[b..tree[b].close].select { |t| t.class == ReDel::CloseTag && t.type == "P_INCREMENTAL" }
197
197
  [b, steps.index(tree[i]) + 1, steps.length]
198
198
  end
199
199
  private :position
@@ -207,7 +207,7 @@ module Chimp
207
207
  end
208
208
  ### on the first part of the first slide there is nothing to go back to
209
209
  pos = c.open-1
210
- first = tree[pos].ttype == "P_SLIDES" && tree[0...pos].none? { |t| t.class == OpenTag && t.ttype == "P_SLIDES" }
210
+ first = tree[pos].type == "P_SLIDES" && tree[0...pos].none? { |t| t.class == ReDel::OpenTag && t.type == "P_SLIDES" }
211
211
  begin
212
212
  if @last == i
213
213
  lines = @screen.lines
@@ -225,17 +225,17 @@ module Chimp
225
225
  when :goto
226
226
  #{{{
227
227
  slide = slide.clamp(1, @scounter)
228
- raise TagMoveEvent, tree.index { |t| t.class == OpenTag && t.ttype == "P_SLIDES" && t.userdata == slide }
228
+ raise TagMoveEvent, tree.index { |t| t.class == ReDel::OpenTag && t.type == "P_SLIDES" && t.data == slide }
229
229
  #}}}
230
230
  when :previous
231
231
  #{{{
232
232
  tag = tree[pos]
233
- if tag.ttype == "P_SLIDES"
233
+ if tag.type == "P_SLIDES"
234
234
  raise TagMoveEvent, tree[pos-1].open
235
235
  end
236
- if tag.ttype == "P_INCREMENTAL"
236
+ if tag.type == "P_INCREMENTAL"
237
237
  ### erase only what this step has drawn (pictures next to it stay), then wait at the end of the previous step again
238
- step = tree[c.open].userdata
238
+ step = tree[c.open].data
239
239
  step[:drawn].each do |x1,y1,x2,y2,erase|
240
240
  y1.upto(y2) do |y|
241
241
  @screen.set_pos x1, y
@@ -251,7 +251,7 @@ module Chimp
251
251
  #{{{
252
252
  ### reparse the presentation (it may have changed) and return to the same slide and step
253
253
  b, step, steps = position(tree,i)
254
- raise ReloadEvent, [tree[b].userdata, step]
254
+ raise ReloadEvent, [tree[b].data, step]
255
255
  #}}}
256
256
  when :exit
257
257
  @screen.finish
data/tools/chimp CHANGED
@@ -29,10 +29,9 @@ fname = File.realpath(ARGV[0])
29
29
  require_relative "../lib/output/#{output}"
30
30
  goto = nil
31
31
  begin
32
- grammy = Chimp::Parser::SimpleGrammar.parse File::read(fname), :fname => fname
32
+ grammy = Chimp::Parser::SimpleGrammar.new(:fname => fname).parse File::read(fname)
33
33
  screen = Chimp::Parser.const_get(output.capitalize).new fname
34
34
  screen.goto = goto if goto
35
- grammy.prepare screen
36
35
  grammy.output screen
37
36
  rescue Chimp::Parser::ReloadEvent => e # refresh
38
37
  goto = e.goto
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cheap-impression-presenter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juergen eTM Mangler
@@ -9,6 +9,20 @@ bindir: tools
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: redel
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '3.1'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '3.1'
12
26
  - !ruby/object:Gem::Dependency
13
27
  name: tty-screen
14
28
  requirement: !ruby/object:Gem::Requirement
@@ -88,7 +102,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
88
102
  requirements:
89
103
  - - ">="
90
104
  - !ruby/object:Gem::Version
91
- version: 2.7.0
105
+ version: '3.2'
92
106
  required_rubygems_version: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - ">="