cheap-impression-presenter 1.1.3 → 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 +4 -4
- data/INSTALL.md +10 -4
- data/README.md +19 -6
- data/chimp.gemspec +3 -2
- data/lib/ChimpParser-Grammar.rb +6 -1
- data/lib/ChimpParser.rb +40 -187
- data/lib/output/pdf.rb +4 -4
- data/lib/output/screen.rb +40 -17
- data/lib/plugins/kitty.rb +117 -0
- data/lib/plugins/pic.rb +59 -0
- data/tools/chimp +1 -2
- metadata +18 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5c1332225abcc4dbf7775e4b0d37f307f4064534c6d4b0f8bdebb2807e24a8ca
|
|
4
|
+
data.tar.gz: 5c485763345a02c618718f58129f9440caef86aff4e370e44dce152bf57034e1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7518a354e8a650be9caaefdbd29904303105d270f283f2f5c5a73359f88f552d37383385eb056735983e6266c2153c9920c5f657e3ed89164fad715239eef58f
|
|
7
|
+
data.tar.gz: c5dd43b178bb625374aee939d50ae607fc4d5bba7e140e0a269c4d1bb059658a8f62e68e86ff08239f606d7d1cd6b56247a21e7df737aa9170ff9a3e0d081750
|
data/INSTALL.md
CHANGED
|
@@ -6,11 +6,17 @@ It wont work in a windows terminal for now.
|
|
|
6
6
|
|
|
7
7
|
You can utilize 'figlet' (chimp has a plugin).
|
|
8
8
|
|
|
9
|
-
You can utilize 'img2sixel' if you want to display graphics on
|
|
10
|
-
(chimp has a sixel plugin).
|
|
9
|
+
You can utilize 'img2sixel' if you want to display graphics on a terminal with
|
|
10
|
+
sixel support (chimp has a sixel plugin).
|
|
11
11
|
|
|
12
|
-
You can utilize '
|
|
13
|
-
|
|
12
|
+
You can utilize 'magick' (ImageMagick 7) if you want to display graphics on a
|
|
13
|
+
terminal with kitty graphics support, e.g. kitty, Ghostty, WezTerm (chimp has a
|
|
14
|
+
kitty plugin).
|
|
15
|
+
|
|
16
|
+
The pic plugin uses whichever of the two your terminal supports.
|
|
17
|
+
|
|
18
|
+
You can utilize 'inkscape' if you want to display svgs as graphics on your
|
|
19
|
+
terminal, or include them in the PDF output.
|
|
14
20
|
|
|
15
21
|
The PDF output (chimp -o pdf) uses the DejaVu Sans Mono font if it is
|
|
16
22
|
installed. Otherwise Courier is used, which lacks some characters (e.g. box
|
data/README.md
CHANGED
|
@@ -12,16 +12,22 @@ 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
|
|
|
19
19
|
* ``figlet``: for the figlet plugin.
|
|
20
|
-
*
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
(
|
|
24
|
-
|
|
20
|
+
* Pictures in the terminal need a terminal that supports either sixel or the
|
|
21
|
+
kitty graphics protocol. The pic plugin finds out which one your terminal
|
|
22
|
+
has and uses it, so you only need the program for that one:
|
|
23
|
+
* ``img2sixel`` (from libsixel): for sixel (the sixel plugin). On linux a
|
|
24
|
+
VTE based terminal with sixel enabled works well, e.g. Black Box
|
|
25
|
+
(https://flathub.org/apps/com.raggesilver.BlackBox), where sixel has to be
|
|
26
|
+
switched on in the preferences.
|
|
27
|
+
* ``magick`` (ImageMagick 7): for the kitty graphics protocol (the kitty
|
|
28
|
+
plugin), e.g. in kitty (https://sw.kovidgoyal.net/kitty/), Ghostty
|
|
29
|
+
(https://ghostty.org) or WezTerm (https://wezterm.org). Pictures are sent
|
|
30
|
+
through the terminal, so this also works via ssh.
|
|
25
31
|
* ``inkscape``: for svg pictures, in the terminal as well as in the PDF output.
|
|
26
32
|
* DejaVu Sans Mono font: for the PDF output. If it is not installed, Courier is
|
|
27
33
|
used, which lacks some characters (e.g. box drawing).
|
|
@@ -51,6 +57,11 @@ their own center parameter.
|
|
|
51
57
|
|
|
52
58
|
Everything else is in plugins. The following plugins are existing for now:
|
|
53
59
|
|
|
60
|
+
* Pic: display graphics in the terminal, with whatever the terminal supports
|
|
61
|
+
(kitty graphics protocol or sixel, kitty if both, nothing if neither):
|
|
62
|
+
`` ```pic,20 name.png``. This is the one to use, it takes the same
|
|
63
|
+
parameters as Sixel (see below). If the detection is wrong, set
|
|
64
|
+
``CHIMP_PIC`` to ``kitty``, ``sixel`` or ``none``.
|
|
54
65
|
* Sixel: display graphics in the terminal: `` ```sixel,20 name.png``.
|
|
55
66
|
* The parameter 20 denotes the size in characters.
|
|
56
67
|
* You can add right or center as an additional parameter to align the
|
|
@@ -62,6 +73,8 @@ Everything else is in plugins. The following plugins are existing for now:
|
|
|
62
73
|
picture instead of beneath. Combined with +++ the next picture replaces the
|
|
63
74
|
current one, which allows for simple animations (see
|
|
64
75
|
examples/sixel_svg.2.txt).
|
|
76
|
+
* Kitty: the same as Sixel, but with the kitty graphics protocol:
|
|
77
|
+
`` ```kitty,20 name.png``. All parameters of the Sixel plugin work.
|
|
65
78
|
* Figlet: display fancy ascii text: `` ```figlet FANCY_TEXT``.
|
|
66
79
|
* You can add right or center as a parameter to align the fancy text.
|
|
67
80
|
* If the fancy text is right aligned, normal text is added on the left of the
|
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.
|
|
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
|
|
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'
|
data/lib/ChimpParser-Grammar.rb
CHANGED
|
@@ -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 '
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
48
|
-
|
|
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.
|
|
57
|
-
when CloseTag then [method("mC" + c.
|
|
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.
|
|
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
|
-
|
|
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
|
|
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 :
|
|
224
|
+
private :render_page, :top, :baseline
|
|
225
225
|
|
|
226
226
|
end
|
|
227
227
|
end
|
data/lib/output/screen.rb
CHANGED
|
@@ -4,7 +4,18 @@ require 'io/console'
|
|
|
4
4
|
|
|
5
5
|
module Window #{{{
|
|
6
6
|
class WinchError < Exception; end
|
|
7
|
+
|
|
8
|
+
def self::sync_begin()
|
|
9
|
+
$stdout << "\e[?2026h"
|
|
10
|
+
$stdout.flush
|
|
11
|
+
end
|
|
12
|
+
def self::sync_end()
|
|
13
|
+
$stdout << "\e[?2026l"
|
|
14
|
+
$stdout.flush
|
|
15
|
+
end
|
|
16
|
+
|
|
7
17
|
def self::init()
|
|
18
|
+
self::sync_begin
|
|
8
19
|
self::clear
|
|
9
20
|
$stdout << "\e[?25l"
|
|
10
21
|
$stdout.flush
|
|
@@ -17,10 +28,11 @@ module Window #{{{
|
|
|
17
28
|
self::clear
|
|
18
29
|
self::set_pos 0, 0
|
|
19
30
|
$stdout << "\e[?25h"
|
|
20
|
-
|
|
31
|
+
self::sync_end
|
|
21
32
|
nil
|
|
22
33
|
end
|
|
23
34
|
def self::getch()
|
|
35
|
+
self::sync_end
|
|
24
36
|
number = nil
|
|
25
37
|
loop do
|
|
26
38
|
ch = $stdin.getch
|
|
@@ -49,6 +61,8 @@ module Window #{{{
|
|
|
49
61
|
end
|
|
50
62
|
end
|
|
51
63
|
end
|
|
64
|
+
ensure
|
|
65
|
+
self::sync_begin
|
|
52
66
|
end
|
|
53
67
|
def self::lines()
|
|
54
68
|
TTY::Screen.lines
|
|
@@ -56,7 +70,13 @@ module Window #{{{
|
|
|
56
70
|
def self::columns()
|
|
57
71
|
TTY::Screen.columns
|
|
58
72
|
end
|
|
73
|
+
#### how often the screen was cleared; plugins check if what they
|
|
74
|
+
#### drew is still there
|
|
75
|
+
def self::cleared()
|
|
76
|
+
@cleared || 0
|
|
77
|
+
end
|
|
59
78
|
def self::clear()
|
|
79
|
+
@cleared = cleared + 1
|
|
60
80
|
$stdout << "\e[2J"
|
|
61
81
|
$stdout.flush
|
|
62
82
|
self
|
|
@@ -132,13 +152,13 @@ module Chimp
|
|
|
132
152
|
#{{{
|
|
133
153
|
@scounter += 1
|
|
134
154
|
@ccounter += 1
|
|
135
|
-
c.
|
|
155
|
+
c.data = @ccounter
|
|
136
156
|
#}}}
|
|
137
157
|
end
|
|
138
158
|
def mOP_SLIDES(c,tree)
|
|
139
159
|
#{{{
|
|
140
160
|
### after a reload, skip the slides before the one we were on
|
|
141
|
-
raise
|
|
161
|
+
raise ReDel::TagSkipError if @goto && c.data <[@goto[0], @scounter].min
|
|
142
162
|
@screen.clear
|
|
143
163
|
lines = @screen.lines
|
|
144
164
|
columns = @screen.columns
|
|
@@ -147,7 +167,7 @@ module Chimp
|
|
|
147
167
|
@screen.print (lines > @size ? ("-"*(columns-1) + "^") : "-"*columns)
|
|
148
168
|
@screen.set_pos 0, lines
|
|
149
169
|
@screen.print @what
|
|
150
|
-
num = "#{c.
|
|
170
|
+
num = "#{c.data}/#{@scounter}"
|
|
151
171
|
@screen.set_pos columns-num.length+1, lines
|
|
152
172
|
@screen.print num
|
|
153
173
|
@screen.set_pos 0, 0
|
|
@@ -159,7 +179,7 @@ module Chimp
|
|
|
159
179
|
@templates << [i+1, c.close-1]
|
|
160
180
|
end
|
|
161
181
|
def mOP_TEMPLATE(data)
|
|
162
|
-
raise
|
|
182
|
+
raise ReDel::TagSkipError
|
|
163
183
|
end
|
|
164
184
|
|
|
165
185
|
def mPP_INCREMENTAL(c,tree,i)
|
|
@@ -168,12 +188,12 @@ module Chimp
|
|
|
168
188
|
def mOP_INCREMENTAL(c,tree)
|
|
169
189
|
@x, @y = @screen.get_pos
|
|
170
190
|
@drawn = []
|
|
171
|
-
c.
|
|
191
|
+
c.data = { :x => @x, :y => @y, :drawn => @drawn }
|
|
172
192
|
end
|
|
173
193
|
#### the slide the incremental closing at i belongs to, which step it is, and how many steps the slide has
|
|
174
194
|
def position(tree,i)
|
|
175
|
-
b = i.downto(0).find { |x| tree[x].class == OpenTag && tree[x].
|
|
176
|
-
steps = tree[b..tree[b].close].select { |t| t.class == CloseTag && t.
|
|
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" }
|
|
177
197
|
[b, steps.index(tree[i]) + 1, steps.length]
|
|
178
198
|
end
|
|
179
199
|
private :position
|
|
@@ -187,7 +207,7 @@ module Chimp
|
|
|
187
207
|
end
|
|
188
208
|
### on the first part of the first slide there is nothing to go back to
|
|
189
209
|
pos = c.open-1
|
|
190
|
-
first = tree[pos].
|
|
210
|
+
first = tree[pos].type == "P_SLIDES" && tree[0...pos].none? { |t| t.class == ReDel::OpenTag && t.type == "P_SLIDES" }
|
|
191
211
|
begin
|
|
192
212
|
if @last == i
|
|
193
213
|
lines = @screen.lines
|
|
@@ -205,22 +225,23 @@ module Chimp
|
|
|
205
225
|
when :goto
|
|
206
226
|
#{{{
|
|
207
227
|
slide = slide.clamp(1, @scounter)
|
|
208
|
-
raise TagMoveEvent, tree.index { |t| t.class == OpenTag && t.
|
|
228
|
+
raise TagMoveEvent, tree.index { |t| t.class == ReDel::OpenTag && t.type == "P_SLIDES" && t.data == slide }
|
|
209
229
|
#}}}
|
|
210
230
|
when :previous
|
|
211
231
|
#{{{
|
|
212
232
|
tag = tree[pos]
|
|
213
|
-
if tag.
|
|
233
|
+
if tag.type == "P_SLIDES"
|
|
214
234
|
raise TagMoveEvent, tree[pos-1].open
|
|
215
235
|
end
|
|
216
|
-
if tag.
|
|
236
|
+
if tag.type == "P_INCREMENTAL"
|
|
217
237
|
### erase only what this step has drawn (pictures next to it stay), then wait at the end of the previous step again
|
|
218
|
-
step = tree[c.open].
|
|
219
|
-
step[:drawn].each do |x1,y1,x2,y2|
|
|
238
|
+
step = tree[c.open].data
|
|
239
|
+
step[:drawn].each do |x1,y1,x2,y2,erase|
|
|
220
240
|
y1.upto(y2) do |y|
|
|
221
241
|
@screen.set_pos x1, y
|
|
222
242
|
@screen.print ' ' * (x2-x1+1)
|
|
223
243
|
end
|
|
244
|
+
erase.call if erase
|
|
224
245
|
end
|
|
225
246
|
@screen.set_pos step[:x], step[:y]
|
|
226
247
|
raise TagMoveEvent, pos
|
|
@@ -230,7 +251,7 @@ module Chimp
|
|
|
230
251
|
#{{{
|
|
231
252
|
### reparse the presentation (it may have changed) and return to the same slide and step
|
|
232
253
|
b, step, steps = position(tree,i)
|
|
233
|
-
raise ReloadEvent, [tree[b].
|
|
254
|
+
raise ReloadEvent, [tree[b].data, step]
|
|
234
255
|
#}}}
|
|
235
256
|
when :exit
|
|
236
257
|
@screen.finish
|
|
@@ -246,13 +267,15 @@ module Chimp
|
|
|
246
267
|
eval('Chimp::Plugin::' + data[:name].upcase).new.prepare(data[:what],data[:parameters],data[:additional])
|
|
247
268
|
end
|
|
248
269
|
|
|
249
|
-
#### plugins may return the area they drew as [x1,y1,x2,y2],
|
|
270
|
+
#### plugins may return the area they drew as [x1,y1,x2,y2],
|
|
271
|
+
#### otherwise the whole lines they printed on count an
|
|
272
|
+
#### optional fifth element is called to erase, e.g., kitty pics
|
|
250
273
|
def process(data)
|
|
251
274
|
require File::dirname(__FILE__) + "/../plugins/#{data[:name]}.rb"
|
|
252
275
|
area = eval('Chimp::Plugin::' + data[:name].upcase).new.process(data[:what],data[:parameters],@screen,data[:additional])
|
|
253
276
|
return unless @drawn
|
|
254
277
|
x, y = @screen.get_pos
|
|
255
|
-
@drawn << (area.is_a?(Array) && area.length
|
|
278
|
+
@drawn << (area.is_a?(Array) && [4, 5].include?(area.length) ? area : [1, @y, @screen.columns, y])
|
|
256
279
|
@x, @y = x, y
|
|
257
280
|
end
|
|
258
281
|
private :process
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
require 'fileutils'
|
|
2
|
+
require 'base64'
|
|
3
|
+
require 'io/console'
|
|
4
|
+
|
|
5
|
+
module Chimp
|
|
6
|
+
module Plugin
|
|
7
|
+
class KITTY < Base
|
|
8
|
+
@@placed = {} # [x,y] => [id, width, screen clears so far, what it replaced], the pictures on the screen
|
|
9
|
+
#### pixel size of a character cell: from the terminal if it knows, else 10x21 as for sixel and the pdf
|
|
10
|
+
def cell_size
|
|
11
|
+
rows, cols, xpix, ypix = [0, 0, 0, 0].pack('S4').then { |buf| $stdout.ioctl(0x5413, buf); buf.unpack('S4') } # TIOCGWINSZ
|
|
12
|
+
return [xpix / cols, ypix / rows] if xpix > 0 && ypix > 0
|
|
13
|
+
[10, 21]
|
|
14
|
+
rescue StandardError
|
|
15
|
+
[10, 21]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# converted images are cached in .PRESENTATIONNAME/ next to the presentation
|
|
19
|
+
def cache_file(what,width,fname)
|
|
20
|
+
dir = File.join(File.dirname(fname),'.' + File.basename(fname,'.*'))
|
|
21
|
+
File.join(dir,"#{what.gsub('/','_')}.#{width}.kitty.png")
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
#### kitty only takes png. the terminal scales it to the width, so it does not depend on the zoom
|
|
25
|
+
#### (which would convert everything again for each zoom). as for sixel 10 pixels per character,
|
|
26
|
+
#### and 5 bits per color, which keeps it small (it goes through the terminal, maybe via ssh)
|
|
27
|
+
def png(what,width,fname)
|
|
28
|
+
src = File.join(File.dirname(fname),what)
|
|
29
|
+
pixels = width * 10
|
|
30
|
+
cache = cache_file(what,width,fname)
|
|
31
|
+
if File.exist?(cache) && File.exist?(src) && File.mtime(cache) >= File.mtime(src)
|
|
32
|
+
return File.binread(cache)
|
|
33
|
+
end
|
|
34
|
+
convert = if what =~ /\.svg$/
|
|
35
|
+
"inkscape -D -d 300 --export-type=png #{src} -o - | magick - -resize #{pixels}x -depth 5 png:-"
|
|
36
|
+
else
|
|
37
|
+
"magick #{src} -resize #{pixels}x -depth 5 png:-"
|
|
38
|
+
end
|
|
39
|
+
result = `#{convert}`
|
|
40
|
+
if $?.success? && !result.empty?
|
|
41
|
+
FileUtils.mkdir_p(File.dirname(cache))
|
|
42
|
+
File.binwrite(cache,result)
|
|
43
|
+
end
|
|
44
|
+
result
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def prepare(what,parameters,additional)
|
|
48
|
+
return if parameters[0] !~ /\d/
|
|
49
|
+
png(what,parameters[0].to_i,additional[:fname])
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def process(what,parameters,screen,additional)
|
|
53
|
+
if parameters[0] !~ /\d/
|
|
54
|
+
screen.print 'Use ```kitty,NUM with NUM beeing the width if the picture in characters.'
|
|
55
|
+
return
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
restore = parameters.include?('animate') || parameters.include?('float')
|
|
59
|
+
width = parameters[0].to_i
|
|
60
|
+
len = screen.columns
|
|
61
|
+
pos = screen.get_pos
|
|
62
|
+
x, y = pos
|
|
63
|
+
### move instead of printing spaces, spaces would erase a picture already on this line
|
|
64
|
+
if parameters.include? 'right'
|
|
65
|
+
x += len-width
|
|
66
|
+
elsif parameters.include? 'center'
|
|
67
|
+
x += (len-width)/2
|
|
68
|
+
end
|
|
69
|
+
screen.set_pos x, y
|
|
70
|
+
if screen.respond_to?(:image) # pdf output
|
|
71
|
+
screen.image what, width, additional[:fname]
|
|
72
|
+
_, bottom = screen.get_pos
|
|
73
|
+
last = bottom
|
|
74
|
+
erase = nil
|
|
75
|
+
else
|
|
76
|
+
data = png(what,width,additional[:fname])
|
|
77
|
+
return if data.empty?
|
|
78
|
+
### the terminal scales the png to the width, which says how many lines it covers
|
|
79
|
+
w, h = data[16,8].unpack('NN')
|
|
80
|
+
cw, ch = cell_size
|
|
81
|
+
bottom = y + (width * cw * h / (w * ch).to_f).ceil
|
|
82
|
+
### bottom is the line after the picture, erasing it would erase what is there (e.g. the footer)
|
|
83
|
+
last = bottom - 1
|
|
84
|
+
id = rand(1...2**31)
|
|
85
|
+
### a picture drawn at the same place as another one replaces it (e.g. for animations). only its placement
|
|
86
|
+
### goes, the terminal keeps the data so going back can show it again. clearing the screen (next slide)
|
|
87
|
+
### removes all pictures, so whatever was placed before that is not there to replace.
|
|
88
|
+
covered = @@placed[[x, y]]
|
|
89
|
+
covered = nil unless covered && covered[2] == screen.cleared
|
|
90
|
+
### all chunks in one write, a flush per chunk stutters, q=2 keeps the terminal from answering
|
|
91
|
+
chunks = Base64.strict_encode64(data).scan(/.{1,4096}/)
|
|
92
|
+
screen.print (covered ? "\e_Ga=d,d=i,i=#{covered[0]},q=2\e\\" : '') + chunks.each_with_index.map { |chunk,i|
|
|
93
|
+
keys = i == 0 ? "a=T,f=100,i=#{id},c=#{width},C=1,q=2," : ''
|
|
94
|
+
"\e_G#{keys}m=#{i < chunks.length-1 ? 1 : 0};#{chunk}\e\\"
|
|
95
|
+
}.join
|
|
96
|
+
@@placed[[x, y]] = [id, width, screen.cleared, covered]
|
|
97
|
+
### pictures are not part of the text, printing spaces does not erase them. bring back what it replaced.
|
|
98
|
+
erase = lambda do
|
|
99
|
+
screen.print "\e_Ga=d,d=I,i=#{id},q=2\e\\"
|
|
100
|
+
if covered
|
|
101
|
+
screen.set_pos x, y
|
|
102
|
+
screen.print "\e_Ga=p,i=#{covered[0]},c=#{covered[1]},C=1,q=2\e\\"
|
|
103
|
+
end
|
|
104
|
+
@@placed[[x, y]] = covered
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
if restore
|
|
108
|
+
screen.set_pos *pos
|
|
109
|
+
else
|
|
110
|
+
screen.set_pos 0, bottom
|
|
111
|
+
end
|
|
112
|
+
### the area the picture covers, so going back can erase exactly that
|
|
113
|
+
[x, y, x+width-1, last, erase].compact
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
data/lib/plugins/pic.rb
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
require 'io/console'
|
|
2
|
+
require_relative 'sixel'
|
|
3
|
+
require_relative 'kitty'
|
|
4
|
+
|
|
5
|
+
module Chimp
|
|
6
|
+
module Plugin
|
|
7
|
+
class PIC < Base
|
|
8
|
+
#### ask the terminal once: a kitty graphics query, then a device attributes query (4 means sixel),
|
|
9
|
+
#### which every terminal answers, so we know when to stop waiting for the kitty answer
|
|
10
|
+
def detect
|
|
11
|
+
return ENV['CHIMP_PIC'].to_sym if %w{kitty sixel none}.include?(ENV['CHIMP_PIC'])
|
|
12
|
+
return :none unless $stdin.tty? && $stdout.tty?
|
|
13
|
+
res = ''
|
|
14
|
+
$stdin.raw do
|
|
15
|
+
$stdout << "\e_Gi=31,s=1,v=1,a=q,t=d,f=24;AAAA\e\\\e[c"
|
|
16
|
+
$stdout.flush
|
|
17
|
+
while IO.select([$stdin], nil, nil, 1) && (c = $stdin.getc)
|
|
18
|
+
res << c
|
|
19
|
+
break if res =~ /\e\[\?[\d;]*c/
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
if res.include?("\e_Gi=31;OK")
|
|
23
|
+
:kitty
|
|
24
|
+
elsif res =~ /\e\[\?([\d;]*)c/ && $1.split(';').include?('4')
|
|
25
|
+
:sixel
|
|
26
|
+
else
|
|
27
|
+
:none
|
|
28
|
+
end
|
|
29
|
+
rescue StandardError
|
|
30
|
+
:none
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def graphics
|
|
34
|
+
@@graphics ||= detect
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def delegate(screen=nil)
|
|
38
|
+
### the pdf does not care, both plugins hand the picture to it
|
|
39
|
+
return SIXEL.new if screen.respond_to?(:image)
|
|
40
|
+
case graphics
|
|
41
|
+
when :kitty then KITTY.new
|
|
42
|
+
when :sixel then SIXEL.new
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def prepare(what,parameters,additional)
|
|
47
|
+
delegate&.prepare(what,parameters,additional)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def process(what,parameters,screen,additional)
|
|
51
|
+
if parameters[0] !~ /\d/
|
|
52
|
+
screen.print 'Use ```pic,NUM with NUM beeing the width if the picture in characters.'
|
|
53
|
+
return
|
|
54
|
+
end
|
|
55
|
+
delegate(screen)&.process(what,parameters,screen,additional)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
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)
|
|
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.
|
|
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
|
|
@@ -72,7 +86,9 @@ files:
|
|
|
72
86
|
- lib/output/pdf.rb
|
|
73
87
|
- lib/output/screen.rb
|
|
74
88
|
- lib/plugins/figlet.rb
|
|
89
|
+
- lib/plugins/kitty.rb
|
|
75
90
|
- lib/plugins/lnums.rb
|
|
91
|
+
- lib/plugins/pic.rb
|
|
76
92
|
- lib/plugins/sixel.rb
|
|
77
93
|
- tools/chimp
|
|
78
94
|
homepage: https://github.com/etm/chimp
|
|
@@ -86,7 +102,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
86
102
|
requirements:
|
|
87
103
|
- - ">="
|
|
88
104
|
- !ruby/object:Gem::Version
|
|
89
|
-
version: 2
|
|
105
|
+
version: '3.2'
|
|
90
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
107
|
requirements:
|
|
92
108
|
- - ">="
|