0 | 0 |
#!/usr/bin/env ruby
|
1 | 1 |
|
2 | |
begin
|
|
2 |
begin
|
3 | 3 |
require "ncurses"
|
4 | 4 |
include Ncurses
|
5 | |
|
6 | 5 |
rescue LoadError
|
7 | 6 |
$stderr.print <<EOF
|
8 | 7 |
There is no Ncurses-Ruby package installed which is needed by TPP.
|
|
10 | 9 |
EOF
|
11 | 10 |
Kernel.exit(1)
|
12 | 11 |
end
|
|
12 |
|
13 | 13 |
class ColorMap
|
14 | 14 |
|
15 | 15 |
def ColorMap.get_color(color)
|
|
20 | 20 |
"blue" => COLOR_BLUE,
|
21 | 21 |
"cyan" => COLOR_CYAN,
|
22 | 22 |
"magenta" => COLOR_MAGENTA,
|
23 | |
"black" => COLOR_BLACK }
|
|
23 |
"black" => COLOR_BLACK,
|
|
24 |
"default" => -1 }
|
24 | 25 |
colors[color]
|
25 | 26 |
end
|
26 | 27 |
|
|
32 | 33 |
"blue" => 5,
|
33 | 34 |
"cyan" => 6,
|
34 | 35 |
"magenta" => 7,
|
35 | |
"black" => 8 }
|
|
36 |
"black" => 8,
|
|
37 |
"default" =>-1}
|
36 | 38 |
colors[color]
|
37 | 39 |
end
|
38 | 40 |
|
39 | 41 |
end
|
40 | 42 |
|
41 | |
class Page
|
42 | |
|
43 | |
def initialize(name)
|
44 | |
@lines = []
|
45 | |
@name = name
|
46 | |
end
|
47 | |
|
48 | |
def name
|
49 | |
@name
|
50 | |
end
|
51 | |
|
52 | |
def set_name(n)
|
53 | |
@name = n
|
54 | |
end
|
55 | |
|
56 | |
def lines=(l)
|
57 | |
@lines = l
|
58 | |
end
|
59 | |
|
60 | |
def add_line(l)
|
61 | |
@lines << l
|
62 | |
end
|
63 | |
|
64 | |
def set_lines(l)
|
65 | |
@lines = l
|
66 | |
end
|
67 | |
|
68 | |
def lines
|
69 | |
@lines
|
70 | |
end
|
71 | |
|
72 | |
def print
|
73 | |
@lines.each do |l|
|
74 | |
puts l
|
75 | |
end
|
76 | |
end
|
77 | |
|
78 | |
end
|
79 | |
|
80 | |
|
81 | |
|
82 | |
class LatexGenerator
|
83 | |
|
84 | |
def initialize(pages,title,author,date)
|
85 | |
@pages = pages
|
86 | |
@title = title
|
87 | |
@author = author
|
88 | |
@date = date
|
89 | |
|
90 | |
@cur_item = ""
|
91 | |
@itemize_open = false
|
92 | |
@output = false
|
93 | |
end
|
94 | |
|
95 | |
def generate_output(fn)
|
96 | |
@fh = File.new(fn,"w+") or begin
|
97 | |
$stderr.puts "error: couldn't open #{fn} for writing!\n"
|
98 | |
Kernel.exit(1)
|
99 | |
end
|
100 | |
|
101 | |
print_frontpage
|
102 | |
@pages.each_index do |i|
|
103 | |
print_page(i)
|
104 | |
end
|
105 | |
print_footer
|
106 | |
end
|
107 | |
|
108 | |
def print_frontpage
|
109 | |
@fh.puts "\\documentclass[slifonts,a4,landscape]{powersem}
|
110 | |
|
111 | |
\\usepackage[display,slifonts]{texpower}
|
112 | |
|
113 | |
\\usepackage[T1]{fontenc}
|
114 | |
\\usepackage{umlaut}
|
115 | |
\\usepackage[german]{babel}
|
116 | |
\\usepackage{pslatex}
|
117 | |
\\usepackage{fixseminar}
|
118 | |
\\title{#{@title}}
|
119 | |
\\author{#{@author}}
|
120 | |
\\date{#{@date}}
|
121 | |
|
122 | |
\\begin{document}
|
123 | |
|
124 | |
\\thispagestyle{plain}
|
125 | |
\\maketitle
|
126 | |
"
|
127 | |
|
128 | |
end
|
129 | |
|
130 | |
def print_footer
|
131 | |
@fh.puts '\end{document}'
|
132 | |
end
|
133 | |
|
134 | |
def print_line(l)
|
135 | |
if not @output then # only do substitutions when not in verbatim mode
|
136 | |
l.gsub!(/_/,'\_') # needs to be escaped
|
137 | |
l.gsub!(/#/,'\#') # needs to be escaped, too
|
138 | |
l.gsub!(/->/,'$\rightarrow$') # a real arrow looks better than '->'
|
139 | |
l.gsub!(/"/,'\'\'') # replace " so that "A really prints ''A and not Ä
|
140 | |
l.gsub!(/%/,'\%') # % are LaTeX comments and must be escaped
|
141 | |
end
|
142 | |
case l
|
143 | |
when /^--heading /
|
144 | |
heading = l.sub(/^--heading /,"")
|
145 | |
@fh.puts "\\section*{#{heading}}"
|
146 | |
when /^--center /
|
147 | |
text = l.sub(/^--center /,"")
|
148 | |
@fh.puts "\\begin{center}#{text}\\end{center}"
|
149 | |
when /^--right /
|
150 | |
text = l.sub(/^--right /,"")
|
151 | |
@fh.puts "\\begin{right}#{text}\\end{right}"
|
152 | |
when /^---/,/^--sleep/,/--beginslide/,/--endslide/,/^--color/
|
153 | |
# do nothing
|
154 | |
when /^--beginoutput/,/^--beginshelloutput/
|
155 | |
@fh.puts '\begin{verbatim}'
|
156 | |
@output = true
|
157 | |
when /^--endoutput/,/--endshelloutput/
|
158 | |
@fh.puts '\end{verbatim}'
|
159 | |
@output = false
|
160 | |
when /^--boldon/
|
161 | |
@fh.puts '{\bf '
|
162 | |
when /^--horline/
|
163 | |
@fh.puts '\hline '
|
164 | |
when /^--revon/,/^--ulon/
|
165 | |
@fh.puts '{\it '
|
166 | |
when /^--boldoff/,/^--revoff/,/^--uloff/
|
167 | |
@fh.puts '}'
|
168 | |
when /^--huge /
|
169 | |
text = l.sub(/^--huge /,"")
|
170 | |
@fh.puts "{\\huge #{text}}"
|
171 | |
else
|
172 | |
# TODO: add better itemize handling, including multi-line items and nested items
|
173 | |
if l =~ /^ *\*/ then
|
174 | |
if @itemize_open then
|
175 | |
@fh.puts("\\item #{@cur_item}")
|
176 | |
else
|
177 | |
@fh.puts('\begin{itemize}')
|
178 | |
@itemize_open = true
|
179 | |
end
|
180 | |
@cur_item = l.sub(/^ *\*/,"")
|
181 | |
elsif l =~ /^ +/ then
|
182 | |
if @itemize_open then
|
183 | |
if @cur_item =~ /-$/ then # hack to keep with - separated words and phrases together
|
184 | |
@cur_item += l.strip
|
185 | |
else
|
186 | |
@cur_item += " " + l.strip
|
187 | |
end
|
188 | |
else
|
189 | |
@fh.puts("#{l}")
|
190 | |
end
|
191 | |
else
|
192 | |
if @itemize_open then
|
193 | |
@itemize_open = false
|
194 | |
@fh.puts("\\item #{@cur_item}")
|
195 | |
@fh.puts('\end{itemize}')
|
196 | |
end
|
197 | |
@fh.puts("#{l}")
|
198 | |
end
|
199 | |
end
|
200 | |
end
|
201 | |
|
202 | |
def print_page(i)
|
203 | |
if i == 0 then
|
204 | |
@fh.puts '\begin{abstract}'
|
205 | |
@pages[i].lines.each do |l|
|
206 | |
print_line(l)
|
207 | |
end
|
208 | |
@fh.puts '\end{abstract}'
|
209 | |
else
|
210 | |
@pages[i].lines.each do |l|
|
211 | |
print_line(l)
|
212 | |
end
|
213 | |
end
|
214 | |
if @itemize_open then
|
215 | |
@fh.puts("\\item #{@cur_item}")
|
216 | |
@fh.puts('\end{itemize}')
|
217 | |
@itemize_open = false
|
218 | |
end
|
219 | |
@fh.puts '\newpage'
|
220 | |
end
|
221 | |
end
|
222 | |
|
223 | |
|
|
43 |
# FileParser
|
|
44 |
# opens a tpp source file, and splits it into the different pages
|
|
45 |
# methods:
|
|
46 |
# * initialize(filename): constructor
|
|
47 |
# * get_pages: returns the parsed pages
|
224 | 48 |
class FileParser
|
225 | 49 |
|
226 | 50 |
def initialize(filename)
|
227 | 51 |
@filename = filename
|
228 | |
@pages = [ nil ]
|
229 | |
@bgcolor = "black"
|
230 | |
@fgcolor = "white"
|
231 | |
end
|
232 | |
|
233 | |
def do_work(output_latex)
|
234 | |
f = File.open(@filename)
|
235 | |
|
236 | |
if not f then
|
237 | |
$stderr.puts "Couldn't open #{@filename}."
|
|
52 |
@pages = []
|
|
53 |
end
|
|
54 |
|
|
55 |
def get_pages
|
|
56 |
begin
|
|
57 |
f = File.open(@filename)
|
|
58 |
rescue
|
|
59 |
$stderr.puts "Error: couldn't open file: #{$!}"
|
238 | 60 |
Kernel.exit(1)
|
239 | 61 |
end
|
240 | 62 |
|
241 | |
cur_page = nil
|
242 | |
|
243 | |
@title = ""
|
244 | |
@author = ""
|
245 | |
@date = ""
|
246 | |
abstract = []
|
247 | |
|
248 | 63 |
number_pages = 0
|
|
64 |
|
|
65 |
cur_page = Page.new("slide " + (number_pages + 1).to_s)
|
249 | 66 |
|
250 | 67 |
f.each_line do |line|
|
251 | 68 |
line.chomp!
|
252 | 69 |
case line
|
253 | |
#comment
|
254 | |
when /--##/
|
255 | |
when /^--title / # store title
|
256 | |
@title = line.sub(/^--title /,"")
|
257 | |
when /^--author / # store author
|
258 | |
@author = line.sub(/^--author /,"")
|
259 | |
when /^--date / # store date
|
260 | |
@date = line.sub(/^--date /,"")
|
261 | |
if @date == "today" then
|
262 | |
@date = Time.now.strftime("%b %d %Y")
|
263 | |
elsif @date =~ /^today / then
|
264 | |
@date = Time.now.strftime(@date.sub(/^today /,""))
|
265 | |
end
|
266 | |
when /^--bgcolor /
|
267 | |
tmp_bgcolor = line.sub(/^--bgcolor /,"")
|
268 | |
@bgcolor = tmp_bgcolor.strip
|
269 | |
when /^--fgcolor /
|
270 | |
tmp_fgcolor = line.sub(/^--fgcolor /,"")
|
271 | |
@fgcolor = tmp_fgcolor.strip
|
|
70 |
when /--##/ # ignore comments
|
272 | 71 |
when /^--newpage/
|
273 | |
if cur_page then
|
274 | |
@pages << cur_page
|
275 | |
end
|
|
72 |
@pages << cur_page
|
276 | 73 |
number_pages += 1
|
277 | 74 |
name = line.sub(/^--newpage/,"")
|
278 | 75 |
if name == "" then
|
279 | |
name = "slide " + (number_pages+1).to_s
|
|
76 |
name = "slide " + (number_pages+1).to_s
|
280 | 77 |
else
|
281 | 78 |
name.strip!
|
282 | 79 |
end
|
283 | 80 |
cur_page = Page.new(name)
|
284 | 81 |
else
|
285 | |
if number_pages == 0 then
|
286 | |
abstract << line # lines before the first page are the abstract
|
287 | |
else
|
288 | |
cur_page.add_line(line)
|
289 | |
end
|
290 | |
end
|
291 | |
end
|
292 | |
|
293 | |
if cur_page and cur_page.lines.size > 0 then
|
294 | |
@pages << cur_page
|
295 | |
end
|
296 | |
|
297 | |
front_page = Page.new("#{@title}")
|
298 | |
if output_latex then
|
299 | |
fp_lines = [] # "--title #{@title}",
|
300 | |
#"--author #{@author}",
|
301 | |
#"--date #{@date}"
|
302 | |
#]
|
|
82 |
cur_page.add_line(line)
|
|
83 |
end # case
|
|
84 |
end # each
|
|
85 |
@pages << cur_page
|
|
86 |
end
|
|
87 |
end # class FileParser
|
|
88 |
|
|
89 |
|
|
90 |
# class Page
|
|
91 |
# represents a page in tpp. A page contains of one or more lines and a title.
|
|
92 |
# methods:
|
|
93 |
# * initialize(title): constructor
|
|
94 |
# * add_line(line): appends a line to the current page
|
|
95 |
# * next_line: returns the next line. If there are not more lines, it returns nil, and eop is set to true
|
|
96 |
# * eop?: returns whether we reached the end of the page
|
|
97 |
# * reset_eop: reesets the end of page flag and sets the current line to the first line.
|
|
98 |
# * lines: returns all lines as array
|
|
99 |
# * name: returns the title of the page
|
|
100 |
class Page
|
|
101 |
|
|
102 |
def initialize(title)
|
|
103 |
@lines = []
|
|
104 |
@title = title
|
|
105 |
@cur_line = 0
|
|
106 |
@eop = false
|
|
107 |
end
|
|
108 |
|
|
109 |
def add_line(line)
|
|
110 |
@lines << line if line
|
|
111 |
end
|
|
112 |
|
|
113 |
def next_line
|
|
114 |
line = @lines[@cur_line]
|
|
115 |
@cur_line += 1
|
|
116 |
if @cur_line >= @lines.size then
|
|
117 |
@eop = true
|
|
118 |
end
|
|
119 |
return line
|
|
120 |
end
|
|
121 |
|
|
122 |
def eop?
|
|
123 |
@eop
|
|
124 |
end
|
|
125 |
|
|
126 |
def reset_eop
|
|
127 |
@cur_line = 0
|
|
128 |
@eop = false
|
|
129 |
end
|
|
130 |
|
|
131 |
def lines
|
|
132 |
@lines
|
|
133 |
end
|
|
134 |
|
|
135 |
def name
|
|
136 |
@title
|
|
137 |
end
|
|
138 |
end
|
|
139 |
|
|
140 |
|
|
141 |
|
|
142 |
# class TppVisualizer
|
|
143 |
# generic class from which all visualizers need to be derived
|
|
144 |
# all the methods are only implemented because there are no pure virtual functions in ruby
|
|
145 |
class TppVisualizer
|
|
146 |
|
|
147 |
def initialize
|
|
148 |
# nothing
|
|
149 |
end
|
|
150 |
|
|
151 |
def do_footer(footer_text)
|
|
152 |
$stderr.puts "Error: TppVisualizer#do_footer has been called directly."
|
|
153 |
Kernel.exit(1)
|
|
154 |
end
|
|
155 |
|
|
156 |
def do_header(header_text)
|
|
157 |
$stderr.puts "Error: TppVisualizer#do_header has been called directly."
|
|
158 |
Kernel.exit(1)
|
|
159 |
end
|
|
160 |
|
|
161 |
|
|
162 |
def do_refresh
|
|
163 |
$stderr.puts "Error: TppVisualizer#do_refresh has been called directly."
|
|
164 |
Kernel.exit(1)
|
|
165 |
end
|
|
166 |
|
|
167 |
def new_page
|
|
168 |
$stderr.puts "Error: TppVisualizer#new_page has been called directly."
|
|
169 |
Kernel.exit(1)
|
|
170 |
end
|
|
171 |
|
|
172 |
def do_heading(text)
|
|
173 |
$stderr.puts "Error: TppVisualizer#do_heading has been called directly."
|
|
174 |
Kernel.exit(1)
|
|
175 |
end
|
|
176 |
|
|
177 |
def do_withborder
|
|
178 |
$stderr.puts "Error: TppVisualizer#do_withborder has been called directly."
|
|
179 |
Kernel.exit(1)
|
|
180 |
end
|
|
181 |
|
|
182 |
def do_horline
|
|
183 |
$stderr.puts "Error: TppVisualizer#do_horline has been called directly."
|
|
184 |
Kernel.exit(1)
|
|
185 |
end
|
|
186 |
|
|
187 |
def do_color(text)
|
|
188 |
$stderr.puts "Error: TppVisualizer#do_color has been called directly."
|
|
189 |
Kernel.exit(1)
|
|
190 |
end
|
|
191 |
|
|
192 |
def do_center(text)
|
|
193 |
$stderr.puts "Error: TppVisualizer#do_center has been called directly."
|
|
194 |
Kernel.exit(1)
|
|
195 |
end
|
|
196 |
|
|
197 |
def do_right(text)
|
|
198 |
$stderr.puts "Error: TppVisualizer#do_right has been called directly."
|
|
199 |
Kernel.exit(1)
|
|
200 |
end
|
|
201 |
|
|
202 |
def do_exec(cmdline)
|
|
203 |
$stderr.puts "Error: TppVisualizer#do_exec has been called directly."
|
|
204 |
Kernel.exit(1)
|
|
205 |
end
|
|
206 |
|
|
207 |
def do_wait
|
|
208 |
$stderr.puts "Error: TppVisualizer#do_wait has been called directly."
|
|
209 |
Kernel.exit(1)
|
|
210 |
end
|
|
211 |
|
|
212 |
def do_beginoutput
|
|
213 |
$stderr.puts "Error: TppVisualizer#do_beginoutput has been called directly."
|
|
214 |
Kernel.exit(1)
|
|
215 |
end
|
|
216 |
|
|
217 |
def do_beginshelloutput
|
|
218 |
$stderr.puts "Error: TppVisualizer#do_beginshelloutput has been called directly."
|
|
219 |
Kernel.exit(1)
|
|
220 |
end
|
|
221 |
|
|
222 |
def do_endoutput
|
|
223 |
$stderr.puts "Error: TppVisualizer#do_endoutput has been called directly."
|
|
224 |
Kernel.exit(1)
|
|
225 |
end
|
|
226 |
|
|
227 |
def do_endshelloutput
|
|
228 |
$stderr.puts "Error: TppVisualizer#do_endshelloutput has been called directly."
|
|
229 |
Kernel.exit(1)
|
|
230 |
end
|
|
231 |
|
|
232 |
def do_sleep(time2sleep)
|
|
233 |
$stderr.puts "Error: TppVisualizer#do_sleep has been called directly."
|
|
234 |
Kernel.exit(1)
|
|
235 |
end
|
|
236 |
|
|
237 |
def do_boldon
|
|
238 |
$stderr.puts "Error: TppVisualizer#do_boldon has been called directly."
|
|
239 |
Kernel.exit(1)
|
|
240 |
end
|
|
241 |
|
|
242 |
def do_boldoff
|
|
243 |
$stderr.puts "Error: TppVisualizer#do_boldoff has been called directly."
|
|
244 |
Kernel.exit(1)
|
|
245 |
end
|
|
246 |
|
|
247 |
def do_revon
|
|
248 |
$stderr.puts "Error: TppVisualizer#do_revon has been called directly."
|
|
249 |
Kernel.exit(1)
|
|
250 |
end
|
|
251 |
|
|
252 |
def do_revoff
|
|
253 |
$stderr.puts "Error: TppVisualizer#do_revoff has been called directly."
|
|
254 |
Kernel.exit(1)
|
|
255 |
end
|
|
256 |
|
|
257 |
def do_ulon
|
|
258 |
$stderr.puts "Error: TppVisualizer#do_ulon has been called directly."
|
|
259 |
Kernel.exit(1)
|
|
260 |
end
|
|
261 |
|
|
262 |
def do_uloff
|
|
263 |
$stderr.puts "Error: TppVisualizer#do_uloff has been called directly."
|
|
264 |
Kernel.exit(1)
|
|
265 |
end
|
|
266 |
|
|
267 |
def do_beginslideleft
|
|
268 |
$stderr.puts "Error: TppVisualizer#do_beginslideleft has been called directly."
|
|
269 |
Kernel.exit(1)
|
|
270 |
end
|
|
271 |
|
|
272 |
def do_endslide
|
|
273 |
$stderr.puts "Error: TppVisualizer#do_endslide has been called directly."
|
|
274 |
Kernel.exit(1)
|
|
275 |
end
|
|
276 |
|
|
277 |
def do_command_prompt
|
|
278 |
$stderr.puts "Error: TppVisualizer#do_command_prompt has been called directly."
|
|
279 |
Kernel.exit(1)
|
|
280 |
end
|
|
281 |
|
|
282 |
def do_beginslideright
|
|
283 |
$stderr.puts "Error: TppVisualizer#do_beginslideright has been called directly."
|
|
284 |
Kernel.exit(1)
|
|
285 |
end
|
|
286 |
|
|
287 |
def do_beginslidetop
|
|
288 |
$stderr.puts "Error: TppVisualizer#do_beginslidetop has been called directly."
|
|
289 |
Kernel.exit(1)
|
|
290 |
end
|
|
291 |
|
|
292 |
def do_beginslidebottom
|
|
293 |
$stderr.puts "Error: TppVisualizer#do_beginslidebottom has been called directly."
|
|
294 |
Kernel.exit(1)
|
|
295 |
end
|
|
296 |
|
|
297 |
def do_sethugefont
|
|
298 |
$stderr.puts "Error: TppVisualizer#do_sethugefont has been called directly."
|
|
299 |
Kernel.exit(1)
|
|
300 |
end
|
|
301 |
|
|
302 |
def do_huge(text)
|
|
303 |
$stderr.puts "Error: TppVisualizer#do_huge has been called directly."
|
|
304 |
Kernel.exit(1)
|
|
305 |
end
|
|
306 |
|
|
307 |
def print_line(line)
|
|
308 |
$stderr.puts "Error: TppVisualizer#print_line has been called directly."
|
|
309 |
Kernel.exit(1)
|
|
310 |
end
|
|
311 |
|
|
312 |
def do_title(title)
|
|
313 |
$stderr.puts "Error: TppVisualizer#do_title has been called directly."
|
|
314 |
Kernel.exit(1)
|
|
315 |
end
|
|
316 |
|
|
317 |
def do_author(author)
|
|
318 |
$stderr.puts "Error: TppVisualizer#do_author has been called directly."
|
|
319 |
Kernel.exit(1)
|
|
320 |
end
|
|
321 |
|
|
322 |
def do_date(date)
|
|
323 |
$stderr.puts "Error: TppVisualizer#do_date has been called directly."
|
|
324 |
Kernel.exit(1)
|
|
325 |
end
|
|
326 |
|
|
327 |
def do_bgcolor(color)
|
|
328 |
$stderr.puts "Error: TppVisualizer#do_bgcolor has been called directly."
|
|
329 |
Kernel.exit(1)
|
|
330 |
end
|
|
331 |
|
|
332 |
def do_fgcolor(color)
|
|
333 |
$stderr.puts "Error: TppVisualizer#do_fgcolor has been called directly."
|
|
334 |
Kernel.exit(1)
|
|
335 |
end
|
|
336 |
|
|
337 |
def do_color(color)
|
|
338 |
$stderr.puts "Error: TppVisualizer#do_color has been called directly."
|
|
339 |
Kernel.exit(1)
|
|
340 |
end
|
|
341 |
|
|
342 |
# visualize receives a line, parses it if necessary, and dispatches it
|
|
343 |
# to the correct method when then does the correct processing
|
|
344 |
# returns whether the controller shall wait for input
|
|
345 |
def visualize(line,eop)
|
|
346 |
case line
|
|
347 |
when /^--heading /
|
|
348 |
text = line.sub(/^--heading /,"")
|
|
349 |
do_heading(text)
|
|
350 |
when /^--withborder/
|
|
351 |
do_withborder
|
|
352 |
when /^--horline/
|
|
353 |
do_horline
|
|
354 |
when /^--color /
|
|
355 |
text = line.sub(/^--color /,"")
|
|
356 |
text.strip!
|
|
357 |
do_color(text)
|
|
358 |
when /^--center /
|
|
359 |
text = line.sub(/^--center /,"")
|
|
360 |
do_center(text)
|
|
361 |
when /^--right /
|
|
362 |
text = line.sub(/^--right /,"")
|
|
363 |
do_right(text)
|
|
364 |
when /^--exec /
|
|
365 |
cmdline = line.sub(/^--exec /,"")
|
|
366 |
do_exec(cmdline)
|
|
367 |
when /^---/
|
|
368 |
do_wait
|
|
369 |
return true
|
|
370 |
when /^--beginoutput/
|
|
371 |
do_beginoutput
|
|
372 |
when /^--beginshelloutput/
|
|
373 |
do_beginshelloutput
|
|
374 |
when /^--endoutput/
|
|
375 |
do_endoutput
|
|
376 |
when /^--endshelloutput/
|
|
377 |
do_endshelloutput
|
|
378 |
when /^--sleep /
|
|
379 |
time2sleep = line.sub(/^--sleep /,"")
|
|
380 |
do_sleep(time2sleep)
|
|
381 |
when /^--boldon/
|
|
382 |
do_boldon
|
|
383 |
when /^--boldoff/
|
|
384 |
do_boldoff
|
|
385 |
when /^--revon/
|
|
386 |
do_revon
|
|
387 |
when /^--revoff/
|
|
388 |
do_revoff
|
|
389 |
when /^--ulon/
|
|
390 |
do_ulon
|
|
391 |
when /^--uloff/
|
|
392 |
do_uloff
|
|
393 |
when /^--beginslideleft/
|
|
394 |
do_beginslideleft
|
|
395 |
when /^--endslideleft/, /^--endslideright/, /^--endslidetop/, /^--endslidebottom/
|
|
396 |
do_endslide
|
|
397 |
when /^--beginslideright/
|
|
398 |
do_beginslideright
|
|
399 |
when /^--beginslidetop/
|
|
400 |
do_beginslidetop
|
|
401 |
when /^--beginslidebottom/
|
|
402 |
do_beginslidebottom
|
|
403 |
when /^--sethugefont /
|
|
404 |
params = line.sub(/^--sethugefont /,"")
|
|
405 |
do_sethugefont(params.strip)
|
|
406 |
when /^--huge /
|
|
407 |
figlet_text = line.sub(/^--huge /,"")
|
|
408 |
do_huge(figlet_text)
|
|
409 |
when /^--footer /
|
|
410 |
@footer_txt = line.sub(/^--footer /,"")
|
|
411 |
do_footer(@footer_txt)
|
|
412 |
when /^--header /
|
|
413 |
@header_txt = line.sub(/^--header /,"")
|
|
414 |
do_header(@header_txt)
|
|
415 |
when /^--title /
|
|
416 |
title = line.sub(/^--title /,"")
|
|
417 |
do_title(title)
|
|
418 |
when /^--author /
|
|
419 |
author = line.sub(/^--author /,"")
|
|
420 |
do_author(author)
|
|
421 |
when /^--date /
|
|
422 |
date = line.sub(/^--date /,"")
|
|
423 |
if date == "today" then
|
|
424 |
date = Time.now.strftime("%b %d %Y")
|
|
425 |
elsif date =~ /^today / then
|
|
426 |
date = Time.now.strftime(date.sub(/^today /,""))
|
|
427 |
end
|
|
428 |
do_date(date)
|
|
429 |
when /^--bgcolor /
|
|
430 |
color = line.sub(/^--bgcolor /,"").strip
|
|
431 |
do_bgcolor(color)
|
|
432 |
when /^--fgcolor /
|
|
433 |
color = line.sub(/^--fgcolor /,"").strip
|
|
434 |
do_fgcolor(color)
|
|
435 |
when /^--color /
|
|
436 |
color = line.sub(/^--color /,"").strip
|
|
437 |
do_color(color)
|
303 | 438 |
else
|
304 | |
fp_lines = ["--color #{@fgcolor}",
|
305 | |
"--heading #{@title}",
|
306 | |
"",
|
307 | |
"--center #{@author}",
|
308 | |
"--center #{@date}",
|
309 | |
"" ]
|
310 | |
end
|
311 | |
abstract.each { |al| fp_lines << al }
|
312 | |
front_page.set_lines(fp_lines)
|
313 | |
@pages[0] = front_page
|
314 | |
end
|
315 | |
|
316 | |
def get_title
|
317 | |
@title
|
318 | |
end
|
319 | |
|
320 | |
def get_author
|
321 | |
@author
|
322 | |
end
|
323 | |
|
324 | |
def get_date
|
325 | |
@date
|
326 | |
end
|
327 | |
|
328 | |
def get_bgcolor
|
329 | |
if @bgcolor then
|
330 | |
@bgcolor
|
331 | |
else
|
332 | |
"black"
|
333 | |
end
|
334 | |
end
|
335 | |
|
336 | |
def get_pages
|
337 | |
@pages
|
|
439 |
print_line(line)
|
|
440 |
end
|
|
441 |
|
|
442 |
return false
|
|
443 |
end
|
|
444 |
|
|
445 |
def close
|
|
446 |
# nothing
|
338 | 447 |
end
|
339 | 448 |
|
340 | 449 |
end
|
341 | 450 |
|
342 | |
|
343 | |
class Pager
|
344 | |
|
345 | |
def initialize(pages,bgcolor)
|
346 | |
@pages = pages
|
347 | |
@figletfont ="standard"
|
|
451 |
# class NcursesVisualizer
|
|
452 |
# a TppVisualizer for ncurses output
|
|
453 |
# methods:
|
|
454 |
# * initialize: initializes ncurses and sets several default values
|
|
455 |
# * split_lines: split a line on word boundaries, takes a maximum line length,
|
|
456 |
# returns an array of strings guaranteed shorter to be shorter
|
|
457 |
# or as long as the maximum length
|
|
458 |
class NcursesVisualizer < TppVisualizer
|
|
459 |
|
|
460 |
def initialize
|
|
461 |
@figletfont = "standard"
|
348 | 462 |
Ncurses.initscr
|
349 | 463 |
Ncurses.curs_set(0)
|
350 | 464 |
Ncurses.cbreak # unbuffered input
|
351 | 465 |
Ncurses.noecho # turn off input echoing
|
352 | 466 |
Ncurses.stdscr.intrflush(false)
|
353 | 467 |
Ncurses.stdscr.keypad(true)
|
|
468 |
@screen = Ncurses.stdscr
|
|
469 |
setsizes
|
354 | 470 |
Ncurses.start_color()
|
355 | |
@bgcolor = ColorMap.get_color(bgcolor) or COLOR_BLACK
|
356 | |
Ncurses.init_pair(1, COLOR_WHITE, @bgcolor)
|
357 | |
Ncurses.init_pair(2, COLOR_YELLOW, @bgcolor)
|
358 | |
Ncurses.init_pair(3, COLOR_RED, @bgcolor)
|
359 | |
Ncurses.init_pair(4, COLOR_GREEN, @bgcolor)
|
360 | |
Ncurses.init_pair(5, COLOR_BLUE, @bgcolor)
|
361 | |
Ncurses.init_pair(6, COLOR_CYAN, @bgcolor)
|
362 | |
Ncurses.init_pair(7, COLOR_MAGENTA, @bgcolor)
|
363 | |
Ncurses.init_pair(8, COLOR_BLACK, @bgcolor)
|
364 | |
Ncurses.bkgd(Ncurses.COLOR_PAIR(1));
|
365 | |
@current_page = 0
|
366 | |
@current_color_pair = 1
|
367 | |
@number_pages = @pages.size
|
368 | |
@indent = 5
|
369 | |
@voffset = 3
|
370 | |
@screen = Ncurses.stdscr
|
371 | |
set_sizes
|
372 | |
end
|
373 | |
|
374 | |
def close
|
375 | |
Ncurses.nocbreak
|
376 | |
Ncurses.endwin
|
377 | |
end
|
378 | |
|
379 | |
def set_sizes(sig = nil)
|
|
471 |
Ncurses.use_default_colors()
|
|
472 |
do_bgcolor("black")
|
|
473 |
#do_fgcolor("white")
|
|
474 |
@fgcolor = ColorMap.get_color_pair("white")
|
|
475 |
@voffset = 5
|
|
476 |
@indent = 3
|
|
477 |
@cur_line = @voffset
|
|
478 |
@output = @shelloutput = false
|
|
479 |
end
|
|
480 |
|
|
481 |
def clear
|
|
482 |
@screen.clear
|
|
483 |
@screen.refresh
|
|
484 |
end
|
|
485 |
|
|
486 |
def split_lines(text,width)
|
|
487 |
lines = []
|
|
488 |
if text then
|
|
489 |
begin
|
|
490 |
i = width
|
|
491 |
if text.length <= i then # text length is OK -> add it to array and stop splitting
|
|
492 |
lines << text
|
|
493 |
text = ""
|
|
494 |
else
|
|
495 |
# search for word boundary (space actually)
|
|
496 |
while i > 0 and text[i] != ' '[0] do
|
|
497 |
i -= 1
|
|
498 |
end
|
|
499 |
# if we can't find any space character, simply cut it off at the maximum width
|
|
500 |
if i == 0 then
|
|
501 |
i = width
|
|
502 |
end
|
|
503 |
# extract line
|
|
504 |
x = text[0..i-1]
|
|
505 |
# remove extracted line
|
|
506 |
text = text[i+1..-1]
|
|
507 |
# added line to array
|
|
508 |
lines << x
|
|
509 |
end
|
|
510 |
end while text.length > 0
|
|
511 |
end
|
|
512 |
return lines
|
|
513 |
end
|
|
514 |
|
|
515 |
def setsizes
|
380 | 516 |
@termwidth = Ncurses.getmaxx(@screen)
|
381 | 517 |
@termheight = Ncurses.getmaxy(@screen)
|
382 | 518 |
end
|
383 | 519 |
|
384 | |
def read_newpage()
|
385 | |
page = []
|
386 | |
@screen.clear()
|
387 | |
col = 0
|
388 | |
line = 2
|
389 | |
@pages.each_index do |i|
|
390 | |
@screen.move(line,col*15 + 2)
|
391 | |
if @current_page == i then
|
392 | |
@screen.printw("%2d %s <=",i+1,@pages[i].name[0..10])
|
393 | |
else
|
394 | |
@screen.printw("%2d %s",i+1,@pages[i].name[0..10])
|
395 | |
end
|
396 | |
line += 1
|
397 | |
if line >= @termheight - 3 then
|
398 | |
line = 2
|
399 | |
col += 1
|
400 | |
end
|
401 | |
end
|
402 | |
prompt = "jump to slide: "
|
403 | |
prompt_indent = 12
|
404 | |
@screen.move(@termheight - 2, @indent + prompt_indent)
|
405 | |
@screen.addstr(prompt)
|
406 | |
# @screen.refresh();
|
407 | |
Ncurses.echo
|
408 | |
@screen.scanw("%d",page)
|
409 | |
Ncurses.noecho
|
410 | |
@screen.move(@termheight - 2, @indent + prompt_indent)
|
411 | |
(prompt.length + page[0].to_s.length).times { @screen.addstr(" ") }
|
412 | |
if page[0] then
|
413 | |
return page[0] - 1
|
414 | |
end
|
415 | |
return -1 # invalid page
|
|
520 |
def do_refresh
|
|
521 |
@screen.refresh
|
|
522 |
end
|
|
523 |
|
|
524 |
def do_withborder
|
|
525 |
@withborder = true
|
|
526 |
draw_border
|
416 | 527 |
end
|
417 | 528 |
|
418 | |
def draw_slidenum
|
419 | |
@screen.move(@termheight - 2, @indent)
|
420 | |
#@screen.attroff(Ncurses.COLOR_PAIR(@current_color_pair))
|
421 | |
@screen.attroff(Ncurses::A_BOLD) # this is bad
|
422 | |
@screen.addstr("[slide #{@current_page+1}/#{@number_pages}]")
|
423 | |
end
|
424 | |
|
425 | |
def draw_eop_marker
|
426 | |
@screen.move(@termheight - 2, @indent - 1)
|
427 | |
@screen.attron(A_BOLD)
|
428 | |
@screen.addstr("*")
|
429 | |
@screen.attroff(A_BOLD)
|
430 | |
end
|
431 | |
|
432 | |
def draw_border
|
433 | |
@screen.move(0,0)
|
434 | |
@screen.addstr(".")
|
435 | |
(@termwidth-2).times { @screen.addstr("-") }; @screen.addstr(".")
|
436 | |
@screen.move(@termheight-2,0)
|
437 | |
@screen.addstr("`")
|
438 | |
(@termwidth-2).times { @screen.addstr("-") }; @screen.addstr("'")
|
439 | |
1.upto(@termheight-3) do |y|
|
440 | |
@screen.move(y,0)
|
441 | |
@screen.addstr("|")
|
442 | |
end
|
443 | |
1.upto(@termheight-3) do |y|
|
444 | |
@screen.move(y,@termwidth-1)
|
445 | |
@screen.addstr("|")
|
446 | |
end
|
447 | |
end
|
448 | |
|
449 | |
def type_line(l)
|
450 | |
l.each_byte do |x|
|
451 | |
@screen.addstr(x.chr)
|
452 | |
@screen.refresh()
|
453 | |
r = rand(20)
|
454 | |
time_to_sleep = (5 + r).to_f / 250;
|
455 | |
# puts "#{time_to_sleep} #{r}"
|
456 | |
Kernel.sleep(time_to_sleep)
|
457 | |
end
|
458 | |
end
|
459 | |
def command_prompt()
|
|
529 |
def do_command_prompt()
|
460 | 530 |
message = "Press any key to continue :)"
|
461 | 531 |
cursor_pos = 0
|
462 | 532 |
max_len = 50
|
|
474 | 544 |
loop do
|
475 | 545 |
window.mvaddstr(@termheight/4,1+prompt.length,string) # add the code
|
476 | 546 |
window.move(@termheight/4,1+prompt.length+cursor_pos) # move cursor to the end of code
|
477 | |
|
478 | 547 |
ch = window.getch
|
479 | 548 |
case ch
|
480 | |
when Ncurses::KEY_LEFT
|
481 | |
cursor_pos = [0, cursor_pos-1].max # jump one character to the left
|
482 | |
when Ncurses::KEY_RIGHT
|
483 | |
cursor_pos = [0, cursor_pos+1].max # jump one character to the right
|
484 | 549 |
when Ncurses::KEY_ENTER, ?\n, ?\r
|
485 | 550 |
Ncurses.curs_set(0)
|
486 | 551 |
Ncurses.noecho
|
|
491 | 556 |
end
|
492 | 557 |
if rc then
|
493 | 558 |
@screen.mvaddstr(@termheight-2,@termwidth/2-message.length/2,message)
|
|
559 |
ch = Ncurses.getch()
|
|
560 |
@screen.refresh
|
494 | 561 |
end
|
495 | |
ch = Ncurses.getch()
|
496 | 562 |
return
|
|
563 |
when Ncurses::KEY_LEFT
|
|
564 |
cursor_pos = [0, cursor_pos-1].max # jump one character to the left
|
|
565 |
when Ncurses::KEY_RIGHT
|
|
566 |
cursor_pos = [0, cursor_pos+1].max # jump one character to the right
|
497 | 567 |
when Ncurses::KEY_BACKSPACE
|
498 | 568 |
string = string[0...([0, cursor_pos-1].max)] + string[cursor_pos..-1]
|
499 | 569 |
cursor_pos = [0, cursor_pos-1].max
|
|
511 | 581 |
end
|
512 | 582 |
end
|
513 | 583 |
|
|
584 |
def draw_border
|
|
585 |
@screen.move(0,0)
|
|
586 |
@screen.addstr(".")
|
|
587 |
(@termwidth-2).times { @screen.addstr("-") }; @screen.addstr(".")
|
|
588 |
@screen.move(@termheight-2,0)
|
|
589 |
@screen.addstr("`")
|
|
590 |
(@termwidth-2).times { @screen.addstr("-") }; @screen.addstr("'")
|
|
591 |
1.upto(@termheight-3) do |y|
|
|
592 |
@screen.move(y,0)
|
|
593 |
@screen.addstr("|")
|
|
594 |
end
|
|
595 |
1.upto(@termheight-3) do |y|
|
|
596 |
@screen.move(y,@termwidth-1)
|
|
597 |
@screen.addstr("|")
|
|
598 |
end
|
|
599 |
end
|
|
600 |
|
|
601 |
def new_page
|
|
602 |
@cur_line = @voffset
|
|
603 |
@output = @shelloutput = false
|
|
604 |
setsizes
|
|
605 |
@screen.clear
|
|
606 |
end
|
|
607 |
|
|
608 |
def do_heading(line)
|
|
609 |
@screen.attron(Ncurses::A_BOLD)
|
|
610 |
print_heading(line)
|
|
611 |
@screen.attroff(Ncurses::A_BOLD)
|
|
612 |
end
|
|
613 |
|
|
614 |
def do_horline
|
|
615 |
@screen.attron(Ncurses::A_BOLD)
|
|
616 |
@termwidth.times do |x|
|
|
617 |
@screen.move(@cur_line,x)
|
|
618 |
@screen.addstr("-")
|
|
619 |
end
|
|
620 |
@screen.attroff(Ncurses::A_BOLD)
|
|
621 |
end
|
|
622 |
|
|
623 |
def print_heading(text)
|
|
624 |
width = @termwidth - 2*@indent
|
|
625 |
lines = split_lines(text,width)
|
|
626 |
lines.each do |l|
|
|
627 |
@screen.move(@cur_line,@indent)
|
|
628 |
x = (@termwidth - l.length)/2
|
|
629 |
@screen.move(@cur_line,x)
|
|
630 |
@screen.addstr(l)
|
|
631 |
@cur_line += 1
|
|
632 |
end
|
|
633 |
end
|
|
634 |
|
|
635 |
def do_center(text)
|
|
636 |
width = @termwidth - 2*@indent
|
|
637 |
if @output or @shelloutput then
|
|
638 |
width -= 2
|
|
639 |
end
|
|
640 |
lines = split_lines(text,width)
|
|
641 |
lines.each do |l|
|
|
642 |
@screen.move(@cur_line,@indent)
|
|
643 |
if @output or @shelloutput then
|
|
644 |
@screen.addstr("| ")
|
|
645 |
end
|
|
646 |
x = (@termwidth - l.length)/2
|
|
647 |
@screen.move(@cur_line,x)
|
|
648 |
@screen.addstr(l)
|
|
649 |
@cur_line += 1
|
|
650 |
end
|
|
651 |
end
|
|
652 |
|
|
653 |
def do_right(text)
|
|
654 |
width = @termwidth - 2*@indent
|
|
655 |
if @output or @shelloutput then
|
|
656 |
width -= 2
|
|
657 |
end
|
|
658 |
lines = split_lines(text,width)
|
|
659 |
lines.each do |l|
|
|
660 |
@screen.move(@cur_line,@indent)
|
|
661 |
if @output or @shelloutput then
|
|
662 |
@screen.addstr("| ")
|
|
663 |
end
|
|
664 |
x = (@termwidth - l.length - 2)
|
|
665 |
@screen.move(@cur_line,x)
|
|
666 |
@screen.addstr(l)
|
|
667 |
@cur_line += 1
|
|
668 |
end
|
|
669 |
end
|
|
670 |
|
|
671 |
def show_help_page
|
|
672 |
help_text = [ "tpp help",
|
|
673 |
"",
|
|
674 |
"space bar ............................... display next entry within page",
|
|
675 |
"space bar, cursor-down, cursor-right .... display next page",
|
|
676 |
"b, cursor-up, cursor-left ............... display previous page",
|
|
677 |
"q, Q .................................... quit tpp",
|
|
678 |
"j, J .................................... jump directly to page",
|
|
679 |
"l, L .................................... reload current file",
|
|
680 |
"s, S .................................... jump to the first page",
|
|
681 |
"e, E .................................... jump to the last page",
|
|
682 |
"c, C .................................... start command line",
|
|
683 |
"?, h .................................... this help screen" ]
|
|
684 |
@screen.clear
|
|
685 |
y = @voffset
|
|
686 |
help_text.each do |line|
|
|
687 |
@screen.move(y,@indent)
|
|
688 |
@screen.addstr(line)
|
|
689 |
y += 1
|
|
690 |
end
|
|
691 |
@screen.move(@termheight - 2, @indent)
|
|
692 |
@screen.addstr("Press any key to return to slide")
|
|
693 |
@screen.refresh
|
|
694 |
end
|
|
695 |
|
|
696 |
def do_exec(cmdline)
|
|
697 |
rc = Kernel.system(cmdline)
|
|
698 |
if not rc then
|
|
699 |
# @todo: add error message
|
|
700 |
end
|
|
701 |
end
|
|
702 |
|
|
703 |
def do_wait
|
|
704 |
# nothing
|
|
705 |
end
|
|
706 |
|
|
707 |
def do_beginoutput
|
|
708 |
@screen.move(@cur_line,@indent)
|
|
709 |
@screen.addstr(".")
|
|
710 |
((@termwidth - @indent)/2).times { @screen.addstr("-") }
|
|
711 |
@output = true
|
|
712 |
@cur_line += 1
|
|
713 |
end
|
|
714 |
|
|
715 |
def do_beginshelloutput
|
|
716 |
@screen.move(@cur_line,@indent)
|
|
717 |
@screen.addstr(".")
|
|
718 |
((@termwidth - @indent)/2).times { @screen.addstr("-") }
|
|
719 |
@shelloutput = true
|
|
720 |
@cur_line += 1
|
|
721 |
end
|
|
722 |
|
|
723 |
def do_endoutput
|
|
724 |
if @output then
|
|
725 |
@screen.move(@cur_line,@indent)
|
|
726 |
@screen.addstr("`")
|
|
727 |
((@termwidth - @indent)/2).times { @screen.addstr("-") }
|
|
728 |
@output = false
|
|
729 |
@cur_line += 1
|
|
730 |
end
|
|
731 |
end
|
|
732 |
|
|
733 |
def do_title(title)
|
|
734 |
do_boldon
|
|
735 |
do_center(title)
|
|
736 |
do_boldoff
|
|
737 |
do_center("")
|
|
738 |
end
|
|
739 |
|
|
740 |
def do_footer(footer_txt)
|
|
741 |
@screen.move(@termheight - 3, (@termwidth - footer_txt.length)/2)
|
|
742 |
@screen.addstr(footer_txt)
|
|
743 |
end
|
|
744 |
|
|
745 |
def do_header(header_txt)
|
|
746 |
@screen.move(@termheight - @termheight+1, (@termwidth - header_txt.length)/2)
|
|
747 |
@screen.addstr(header_txt)
|
|
748 |
end
|
|
749 |
|
|
750 |
def do_author(author)
|
|
751 |
do_center(author)
|
|
752 |
do_center("")
|
|
753 |
end
|
|
754 |
|
|
755 |
def do_date(date)
|
|
756 |
do_center(date)
|
|
757 |
do_center("")
|
|
758 |
end
|
|
759 |
|
|
760 |
def do_endshelloutput
|
|
761 |
if @shelloutput then
|
|
762 |
@screen.move(@cur_line,@indent)
|
|
763 |
@screen.addstr("`")
|
|
764 |
((@termwidth - @indent)/2).times { @screen.addstr("-") }
|
|
765 |
@shelloutput = false
|
|
766 |
@cur_line += 1
|
|
767 |
end
|
|
768 |
end
|
|
769 |
|
|
770 |
def do_sleep(time2sleep)
|
|
771 |
Kernel.sleep(time2sleep.to_i)
|
|
772 |
end
|
|
773 |
|
|
774 |
def do_boldon
|
|
775 |
@screen.attron(Ncurses::A_BOLD)
|
|
776 |
end
|
|
777 |
|
|
778 |
def do_boldoff
|
|
779 |
@screen.attroff(Ncurses::A_BOLD)
|
|
780 |
end
|
|
781 |
|
|
782 |
def do_revon
|
|
783 |
@screen.attron(Ncurses::A_REVERSE)
|
|
784 |
end
|
|
785 |
|
|
786 |
def do_revoff
|
|
787 |
@screen.attroff(Ncurses::A_REVERSE)
|
|
788 |
end
|
|
789 |
|
|
790 |
def do_ulon
|
|
791 |
@screen.attron(Ncurses::A_UNDERLINE)
|
|
792 |
end
|
|
793 |
|
|
794 |
def do_uloff
|
|
795 |
@screen.attroff(Ncurses::A_UNDERLINE)
|
|
796 |
end
|
|
797 |
|
|
798 |
def do_beginslideleft
|
|
799 |
@slideoutput = true
|
|
800 |
@slidedir = "left"
|
|
801 |
end
|
|
802 |
|
|
803 |
def do_endslide
|
|
804 |
@slideoutput = false
|
|
805 |
end
|
|
806 |
|
|
807 |
def do_beginslideright
|
|
808 |
@slideoutput = true
|
|
809 |
@slidedir = "right"
|
|
810 |
end
|
|
811 |
|
|
812 |
def do_beginslidetop
|
|
813 |
@slideoutput = true
|
|
814 |
@slidedir = "top"
|
|
815 |
end
|
|
816 |
|
|
817 |
def do_beginslidebottom
|
|
818 |
@slideoutput = true
|
|
819 |
@slidedir = "bottom"
|
|
820 |
end
|
|
821 |
|
|
822 |
def do_sethugefont(params)
|
|
823 |
@figletfont = params
|
|
824 |
end
|
|
825 |
|
|
826 |
def do_huge(figlet_text)
|
|
827 |
output_width = @termwidth - @indent
|
|
828 |
output_width -= 2 if @output or @shelloutput
|
|
829 |
op = IO.popen("figlet -f #{@figletfont} -w #{output_width} -k \"#{figlet_text}\"","r")
|
|
830 |
op.readlines.each do |line|
|
|
831 |
print_line(line)
|
|
832 |
end
|
|
833 |
op.close
|
|
834 |
end
|
|
835 |
|
|
836 |
def do_bgcolor(color)
|
|
837 |
bgcolor = ColorMap.get_color(color) or COLOR_BLACK
|
|
838 |
Ncurses.init_pair(1, COLOR_WHITE, bgcolor)
|
|
839 |
Ncurses.init_pair(2, COLOR_YELLOW, bgcolor)
|
|
840 |
Ncurses.init_pair(3, COLOR_RED, bgcolor)
|
|
841 |
Ncurses.init_pair(4, COLOR_GREEN, bgcolor)
|
|
842 |
Ncurses.init_pair(5, COLOR_BLUE, bgcolor)
|
|
843 |
Ncurses.init_pair(6, COLOR_CYAN, bgcolor)
|
|
844 |
Ncurses.init_pair(7, COLOR_MAGENTA, bgcolor)
|
|
845 |
Ncurses.init_pair(8, COLOR_BLACK, bgcolor)
|
|
846 |
if @fgcolor then
|
|
847 |
Ncurses.bkgd(Ncurses.COLOR_PAIR(@fgcolor))
|
|
848 |
else
|
|
849 |
Ncurses.bkgd(Ncurses.COLOR_PAIR(1))
|
|
850 |
end
|
|
851 |
end
|
|
852 |
|
|
853 |
def do_fgcolor(color)
|
|
854 |
@fgcolor = ColorMap.get_color_pair(color)
|
|
855 |
Ncurses.attron(Ncurses.COLOR_PAIR(@fgcolor))
|
|
856 |
end
|
|
857 |
|
|
858 |
def do_color(color)
|
|
859 |
num = ColorMap.get_color_pair(color)
|
|
860 |
Ncurses.attron(Ncurses.COLOR_PAIR(num))
|
|
861 |
end
|
|
862 |
|
|
863 |
def type_line(l)
|
|
864 |
l.each_byte do |x|
|
|
865 |
@screen.addstr(x.chr)
|
|
866 |
@screen.refresh()
|
|
867 |
r = rand(20)
|
|
868 |
time_to_sleep = (5 + r).to_f / 250;
|
|
869 |
# puts "#{time_to_sleep} #{r}"
|
|
870 |
Kernel.sleep(time_to_sleep)
|
|
871 |
end
|
|
872 |
end
|
514 | 873 |
|
515 | 874 |
def slide_text(l)
|
516 | 875 |
return if l == ""
|
517 | |
if @slidedir == "left" then
|
|
876 |
case @slidedir
|
|
877 |
when "left"
|
518 | 878 |
xcount = l.length-1
|
519 | 879 |
while xcount >= 0
|
520 | 880 |
@screen.move(@cur_line,@indent)
|
|
524 | 884 |
Kernel.sleep(time_to_sleep)
|
525 | 885 |
xcount -= 1
|
526 | 886 |
end
|
527 | |
elsif @slidedir == "right" then
|
|
887 |
when "right"
|
528 | 888 |
(@termwidth - @indent).times do |pos|
|
529 | 889 |
@screen.move(@cur_line,@termwidth - pos - 1)
|
530 | 890 |
@screen.clrtoeol()
|
|
534 | 894 |
time_to_sleep = 1.to_f / 20
|
535 | 895 |
Kernel.sleep(time_to_sleep)
|
536 | 896 |
end # do
|
537 | |
elsif @slidedir == "top" then
|
|
897 |
when "top"
|
538 | 898 |
# ycount = @cur_line
|
539 | 899 |
new_scr = @screen.dupwin
|
540 | 900 |
1.upto(@cur_line) do |i|
|
|
544 | 904 |
@screen.refresh()
|
545 | 905 |
Kernel.sleep(1.to_f / 10)
|
546 | 906 |
end
|
547 | |
elsif @slidedir == "bottom" then
|
|
907 |
when "bottom"
|
548 | 908 |
new_scr = @screen.dupwin
|
549 | 909 |
(@termheight-1).downto(@cur_line) do |i|
|
550 | 910 |
Ncurses.overwrite(new_scr,@screen)
|
|
556 | 916 |
end
|
557 | 917 |
end
|
558 | 918 |
|
559 | |
def draw_page(page)
|
560 | |
@output = false
|
561 | |
@shelloutput = false
|
562 | |
@slideoutput = false
|
563 | |
@with_border = false
|
564 | |
@cur_line = @voffset
|
|
919 |
def print_line(line)
|
|
920 |
width = @termwidth - 2*@indent
|
|
921 |
if @output or @shelloutput then
|
|
922 |
width -= 2
|
|
923 |
end
|
|
924 |
lines = split_lines(line,width)
|
|
925 |
lines.each do |l|
|
|
926 |
@screen.move(@cur_line,@indent)
|
|
927 |
if @output or @shelloutput then
|
|
928 |
@screen.addstr("| ")
|
|
929 |
end
|
|
930 |
if @shelloutput and (l =~ /^\$/ or l=~ /^%/ or l =~ /^#/) then # allow sh and csh style prompts
|
|
931 |
type_line(l)
|
|
932 |
elsif @slideoutput then
|
|
933 |
slide_text(l)
|
|
934 |
else
|
|
935 |
@screen.addstr(l)
|
|
936 |
end
|
|
937 |
@cur_line += 1
|
|
938 |
end
|
|
939 |
end
|
|
940 |
|
|
941 |
def close
|
|
942 |
Ncurses.nocbreak
|
|
943 |
Ncurses.endwin
|
|
944 |
end
|
|
945 |
|
|
946 |
def read_newpage(pages,current_page)
|
|
947 |
page = []
|
565 | 948 |
@screen.clear()
|
566 | |
draw_slidenum
|
567 | |
page.lines.each do |l|
|
568 | |
case l
|
569 | |
when /^--heading /
|
570 | |
@screen.move(@cur_line,@indent)
|
571 | |
text = l.sub(/^--heading /,"")
|
572 | |
x = (@termwidth - text.length)/2
|
573 | |
@screen.move(@cur_line,x)
|
574 | |
@screen.attron(Ncurses::A_BOLD)
|
575 | |
@screen.addstr(text)
|
576 | |
@screen.attroff(Ncurses::A_BOLD) # this is bad
|
577 | |
@cur_line += 1
|
578 | |
when /^--withborder/
|
579 | |
draw_border()
|
580 | |
@with_border = true
|
581 | |
when /^--horline/
|
582 | |
@screen.attron(Ncurses::A_BOLD)
|
583 | |
(@termwidth).times do |x|
|
584 | |
@screen.move(@cur_line,x)
|
585 | |
@screen.addstr("-")
|
|
949 |
col = 0
|
|
950 |
line = 2
|
|
951 |
pages.each_index do |i|
|
|
952 |
@screen.move(line,col*15 + 2)
|
|
953 |
if current_page == i then
|
|
954 |
@screen.printw("%2d %s <=",i+1,pages[i].name[0..80])
|
|
955 |
else
|
|
956 |
@screen.printw("%2d %s",i+1,pages[i].name[0..80])
|
|
957 |
end
|
|
958 |
line += 1
|
|
959 |
if line >= @termheight - 3 then
|
|
960 |
line = 2
|
|
961 |
col += 1
|
|
962 |
end
|
|
963 |
end
|
|
964 |
prompt = "jump to slide: "
|
|
965 |
prompt_indent = 12
|
|
966 |
@screen.move(@termheight - 2, @indent + prompt_indent)
|
|
967 |
@screen.addstr(prompt)
|
|
968 |
# @screen.refresh();
|
|
969 |
Ncurses.echo
|
|
970 |
@screen.scanw("%d",page)
|
|
971 |
Ncurses.noecho
|
|
972 |
@screen.move(@termheight - 2, @indent + prompt_indent)
|
|
973 |
(prompt.length + page[0].to_s.length).times { @screen.addstr(" ") }
|
|
974 |
if page[0] then
|
|
975 |
return page[0] - 1
|
|
976 |
end
|
|
977 |
return -1 # invalid page
|
|
978 |
end
|
|
979 |
|
|
980 |
def store_screen
|
|
981 |
@screen.dupwin
|
|
982 |
end
|
|
983 |
|
|
984 |
def restore_screen(s)
|
|
985 |
Ncurses.overwrite(s,@screen)
|
|
986 |
end
|
|
987 |
|
|
988 |
def draw_slidenum(cur_page,max_pages,eop)
|
|
989 |
@screen.move(@termheight - 2, @indent)
|
|
990 |
@screen.attroff(Ncurses::A_BOLD) # this is bad
|
|
991 |
@screen.addstr("[slide #{cur_page}/#{max_pages}]")
|
|
992 |
if @footer_txt.to_s.length > 0 then
|
|
993 |
do_footer(@footer_txt)
|
|
994 |
end
|
|
995 |
if @header_txt.to_s.length > 0 then
|
|
996 |
do_header(@header_txt)
|
|
997 |
end
|
|
998 |
|
|
999 |
if eop then
|
|
1000 |
draw_eop_marker
|
|
1001 |
end
|
|
1002 |
end
|
|
1003 |
|
|
1004 |
def draw_eop_marker
|
|
1005 |
@screen.move(@termheight - 2, @indent - 1)
|
|
1006 |
@screen.attron(A_BOLD)
|
|
1007 |
@screen.addstr("*")
|
|
1008 |
@screen.attroff(A_BOLD)
|
|
1009 |
end
|
|
1010 |
|
|
1011 |
end
|
|
1012 |
|
|
1013 |
|
|
1014 |
# class LinuxdocVisualizer
|
|
1015 |
# converts tpp source to LinuxDoc SGML
|
|
1016 |
class LinuxdocVisualizer < TppVisualizer
|
|
1017 |
|
|
1018 |
def initialize(outputfile)
|
|
1019 |
@filename = outputfile
|
|
1020 |
begin
|
|
1021 |
@f = File.open(@filename,"w+")
|
|
1022 |
rescue
|
|
1023 |
$stderr.print "Error: couldn't open file: #{$!}"
|
|
1024 |
Kernel.exit(1)
|
|
1025 |
end
|
|
1026 |
@f.puts "<!doctype linuxdoc system>\n<article>"
|
|
1027 |
@need_p = true
|
|
1028 |
@verb = false
|
|
1029 |
@had_sect = false
|
|
1030 |
@itemize_open = false
|
|
1031 |
end
|
|
1032 |
|
|
1033 |
def do_footer(footer_text)
|
|
1034 |
end
|
|
1035 |
|
|
1036 |
def do_header(header_text)
|
|
1037 |
end
|
|
1038 |
|
|
1039 |
def do_refresh
|
|
1040 |
end
|
|
1041 |
|
|
1042 |
def new_page
|
|
1043 |
end
|
|
1044 |
|
|
1045 |
def do_heading(text)
|
|
1046 |
if not @need_p then
|
|
1047 |
if @had_sect then
|
|
1048 |
#@f.puts "</p>"
|
|
1049 |
else
|
|
1050 |
@f.puts "</abstract>"
|
|
1051 |
end
|
|
1052 |
@need_p = true
|
|
1053 |
end
|
|
1054 |
@f.puts "<sect>#{text}"
|
|
1055 |
@had_sect = true
|
|
1056 |
end
|
|
1057 |
|
|
1058 |
def do_withborder
|
|
1059 |
end
|
|
1060 |
|
|
1061 |
def do_horline
|
|
1062 |
end
|
|
1063 |
|
|
1064 |
def do_color(text)
|
|
1065 |
end
|
|
1066 |
|
|
1067 |
def do_center(text)
|
|
1068 |
end
|
|
1069 |
|
|
1070 |
def do_right(text)
|
|
1071 |
end
|
|
1072 |
|
|
1073 |
def do_exec(cmdline)
|
|
1074 |
end
|
|
1075 |
|
|
1076 |
def do_wait
|
|
1077 |
end
|
|
1078 |
|
|
1079 |
def do_beginoutput
|
|
1080 |
@f.puts "<p><tscreen><verb>"
|
|
1081 |
@verb_mode = true
|
|
1082 |
end
|
|
1083 |
|
|
1084 |
def do_beginshelloutput
|
|
1085 |
@f.puts "<p><tscreen><verb>"
|
|
1086 |
@verb_mode = true
|
|
1087 |
end
|
|
1088 |
|
|
1089 |
def do_endoutput
|
|
1090 |
@f.puts "</verb></tscreen>"
|
|
1091 |
@verb_mode = false
|
|
1092 |
end
|
|
1093 |
|
|
1094 |
def do_endshelloutput
|
|
1095 |
@f.puts "</verb></tscreen>"
|
|
1096 |
@verb_mode = false
|
|
1097 |
end
|
|
1098 |
|
|
1099 |
def do_sleep(time2sleep)
|
|
1100 |
end
|
|
1101 |
|
|
1102 |
def do_boldon
|
|
1103 |
@f.puts "<bf>"
|
|
1104 |
end
|
|
1105 |
|
|
1106 |
def do_boldoff
|
|
1107 |
@f.puts "</bf>"
|
|
1108 |
end
|
|
1109 |
|
|
1110 |
def do_revon
|
|
1111 |
end
|
|
1112 |
|
|
1113 |
def do_command_prompt
|
|
1114 |
end
|
|
1115 |
def do_revoff
|
|
1116 |
end
|
|
1117 |
|
|
1118 |
def do_ulon
|
|
1119 |
end
|
|
1120 |
|
|
1121 |
def do_uloff
|
|
1122 |
end
|
|
1123 |
|
|
1124 |
def do_beginslideleft
|
|
1125 |
end
|
|
1126 |
|
|
1127 |
def do_endslide
|
|
1128 |
end
|
|
1129 |
|
|
1130 |
def do_beginslideright
|
|
1131 |
end
|
|
1132 |
|
|
1133 |
def do_beginslidetop
|
|
1134 |
end
|
|
1135 |
|
|
1136 |
def do_beginslidebottom
|
|
1137 |
end
|
|
1138 |
|
|
1139 |
def do_sethugefont(text)
|
|
1140 |
end
|
|
1141 |
|
|
1142 |
def do_huge(text)
|
|
1143 |
end
|
|
1144 |
|
|
1145 |
def print_line(line)
|
|
1146 |
if not @verb_mode then
|
|
1147 |
if @need_p then
|
|
1148 |
if line.strip != "" then
|
|
1149 |
if @had_sect then
|
|
1150 |
@f.print "<p>"
|
|
1151 |
else
|
|
1152 |
@f.print "<abstract>"
|
586 | 1153 |
end
|
587 | |
@screen.attroff(Ncurses::A_BOLD)
|
588 | |
@cur_line += 1
|
589 | |
when /^--color /
|
590 | |
text = l.sub(/^--color /,"")
|
591 | |
text.strip!
|
592 | |
num = ColorMap.get_color_pair(text)
|
593 | |
Ncurses.attron(Ncurses.COLOR_PAIR(num))
|
594 | |
@current_color_pair = num
|
595 | |
when /^--center /
|
596 | |
@screen.move(@cur_line,@indent)
|
597 | |
if @output or @shelloutput then
|
598 | |
@screen.addstr("| ")
|
599 | |
end
|
600 | |
text = l.sub(/^--center /,"")
|
601 | |
x = (@termwidth - text.length)/2
|
602 | |
@screen.move(@cur_line,x)
|
603 | |
@screen.addstr(text)
|
604 | |
@cur_line += 1
|
605 | |
when /^--right /
|
606 | |
@screen.move(@cur_line,@indent)
|
607 | |
if @output or @shelloutput then
|
608 | |
@screen.addstr("| ")
|
609 | |
end
|
610 | |
text = l.sub(/^--right /,"")
|
611 | |
x = (@termwidth - text.length - 2)
|
612 | |
@screen.move(@cur_line,x)
|
613 | |
@screen.addstr(text)
|
614 | |
@cur_line += 1
|
615 | |
when /^--exec /
|
616 | |
cmdline = l.sub(/^--exec /,"")
|
617 | |
rc = Kernel.system(cmdline)
|
618 | |
if not rc then
|
619 | |
print_line("Error: exec \"#{cmdline}\" failed with error code #{$?}")
|
620 | |
end
|
621 | |
when /^---/
|
622 | |
while true do
|
623 | |
x = @screen.getch()
|
624 | |
case x
|
625 | |
when ' '[0]
|
626 | |
break
|
627 | |
when 'q'[0], 'Q'[0], 'j'[0], 'J'[0], 's'[0], 'S'[0], 'e'[0], 'E'[0], 'c'[0], 'C'[0], Ncurses::KEY_LEFT, Ncurses::KEY_RIGHT, Ncurses::KEY_UP, Ncurses::KEY_DOWN
|
628 | |
if [ Ncurses::KEY_DOWN, Ncurses::KEY_RIGHT ].include?(x) then
|
629 | |
return x if not on_last_page?
|
630 | |
elsif [ Ncurses::KEY_UP, Ncurses::KEY_LEFT].include?(x) then
|
631 | |
return x if not on_first_page?
|
632 | |
else
|
633 | |
return x
|
634 | |
end
|
635 | |
end # case
|
636 | |
end # while
|
637 | |
# @screen.refresh()
|
638 | |
when /^--beginoutput/
|
639 | |
@screen.move(@cur_line,@indent)
|
640 | |
@screen.addstr(".")
|
641 | |
((@termwidth - @indent)/2).times { @screen.addstr("-") }
|
642 | |
@output = true
|
643 | |
@cur_line += 1
|
644 | |
when /^--beginshelloutput/
|
645 | |
@screen.move(@cur_line,@indent)
|
646 | |
@screen.addstr(".")
|
647 | |
((@termwidth - @indent)/2).times { @screen.addstr("-") }
|
648 | |
@shelloutput = true
|
649 | |
@cur_line += 1
|
650 | |
when /^--endoutput/
|
651 | |
if @output then
|
652 | |
@screen.move(@cur_line,@indent)
|
653 | |
@screen.addstr("`")
|
654 | |
((@termwidth - @indent)/2).times { @screen.addstr("-") }
|
655 | |
@output = false
|
656 | |
@cur_line += 1
|
657 | |
end
|
658 | |
when /^--endshelloutput/
|
659 | |
if @shelloutput then
|
660 | |
@screen.move(@cur_line,@indent)
|
661 | |
@screen.addstr("`")
|
662 | |
((@termwidth - @indent)/2).times { @screen.addstr("-") }
|
663 | |
@shelloutput = false
|
664 | |
@cur_line += 1
|
665 | |
end
|
666 | |
when /^--sleep /
|
667 | |
time2sleep = l.sub(/^--sleep /,"")
|
668 | |
Kernel.sleep(time2sleep.to_i)
|
669 | |
when /^--boldon/
|
670 | |
@screen.attron(Ncurses::A_BOLD)
|
671 | |
when /^--boldoff/
|
672 | |
@screen.attroff(Ncurses::A_BOLD)
|
673 | |
when /^--revon/
|
674 | |
@screen.attron(Ncurses::A_REVERSE)
|
675 | |
when /^--revoff/
|
676 | |
@screen.attroff(Ncurses::A_REVERSE)
|
677 | |
when /^--ulon/
|
678 | |
@screen.attron(Ncurses::A_UNDERLINE)
|
679 | |
when /^--uloff/
|
680 | |
@screen.attroff(Ncurses::A_UNDERLINE)
|
681 | |
when /^--beginslideleft/
|
682 | |
@slideoutput = true
|
683 | |
@slidedir = "left"
|
684 | |
when /^--endslideleft/, /^--endslideright/, /^--endslidetop/, /^--endslidebottom/
|
685 | |
@slideoutput = false
|
686 | |
when /^--beginslideright/
|
687 | |
@slideoutput = true
|
688 | |
@slidedir = "right"
|
689 | |
when /^--beginslidetop/
|
690 | |
@slideoutput = true
|
691 | |
@slidedir = "top"
|
692 | |
when /^--beginslidebottom/
|
693 | |
@slideoutput = true
|
694 | |
@slidedir = "bottom"
|
695 | |
when /^--sethugefont /
|
696 | |
params = l.sub(/^--sethugefont /,"")
|
697 | |
@figletfont = params.strip
|
698 | |
when /^--huge /
|
699 | |
figlet_text = l.sub(/^--huge /,"")
|
700 | |
output_width = @termwidth - @indent
|
701 | |
output_width -= 2 if @output or @shelloutput
|
702 | |
op = IO.popen("figlet -f #{@figletfont} -w #{output_width} -k \"#{figlet_text}\"","r")
|
703 | |
op.readlines.each do |line|
|
704 | |
print_line(line)
|
705 | |
end
|
706 | |
op.close
|
|
1154 |
@need_p = false
|
|
1155 |
end
|
|
1156 |
end
|
|
1157 |
end
|
|
1158 |
if line =~ /^ *\*/ then
|
|
1159 |
line.sub!(/^ *\*/,"")
|
|
1160 |
if @itemize_open then
|
|
1161 |
@f.puts "<item> #{line}"
|
707 | 1162 |
else
|
708 | |
print_line(l)
|
709 | |
end
|
710 | |
end
|
711 | |
|
712 | |
if @output or @shelloutput then # forgot --endoutput or --endshelloutput
|
713 | |
@screen.move(@cur_line,@indent)
|
714 | |
@screen.addstr("`")
|
715 | |
((@termwidth - @indent)/2).times { @screen.addstr("-") }
|
716 | |
end
|
717 | |
end
|
718 | |
|
719 | |
def print_line(line)
|
720 | |
@screen.move(@cur_line,@indent)
|
721 | |
if @output or @shelloutput then
|
722 | |
@screen.addstr("| ")
|
723 | |
end
|
724 | |
if @shelloutput and (line =~ /^\$/ or line=~ /^%/) then # allow sh and csh style prompts
|
725 | |
type_line(line)
|
726 | |
elsif @slideoutput then
|
727 | |
slide_text(line)
|
|
1163 |
@f.puts "<itemize> <item> #{line}"
|
|
1164 |
@itemize_open = true
|
|
1165 |
end
|
728 | 1166 |
else
|
729 | |
@screen.addstr(line)
|
730 | |
end
|
731 | |
@cur_line += 1
|
732 | |
end
|
733 | |
|
734 | |
def show_helpscreen
|
735 | |
help_text = [ "tpp help",
|
736 | |
"",
|
737 | |
"space bar ............................... display next entry within page",
|
738 | |
"space bar, cursor-down, cursor-right .... display next page",
|
739 | |
"b, cursor-up, cursor-left ............... display previous page",
|
740 | |
"q, Q .................................... quit tpp",
|
741 | |
"j, J .................................... jump directly to page",
|
742 | |
"s, S .................................... jump to the first page",
|
743 | |
"e, E .................................... jump to the last page",
|
744 | |
"c, C .................................... start command line",
|
745 | |
"? ....................................... this help screen" ]
|
746 | |
@screen.clear
|
747 | |
y = @voffset
|
748 | |
help_text.each do |line|
|
749 | |
@screen.move(y,@indent)
|
750 | |
@screen.addstr(line)
|
751 | |
y += 1
|
752 | |
end
|
753 | |
@screen.move(@termheight - 2, @indent)
|
754 | |
@screen.addstr("Press any key to return to slide")
|
755 | |
@screen.refresh()
|
756 | |
@screen.getch()
|
|
1167 |
if @itemize_open then
|
|
1168 |
@itemize_open = false
|
|
1169 |
@f.puts "</itemize>"
|
|
1170 |
end
|
|
1171 |
@f.puts "#{line}"
|
|
1172 |
end
|
|
1173 |
if not @verb_mode then
|
|
1174 |
if line.strip == "" and not @need_p then
|
|
1175 |
if @had_sect then
|
|
1176 |
#@f.puts "</p>"
|
|
1177 |
else
|
|
1178 |
@f.puts "</abstract>"
|
|
1179 |
end
|
|
1180 |
@need_p = true
|
|
1181 |
end
|
|
1182 |
end
|
|
1183 |
end
|
|
1184 |
|
|
1185 |
def do_title(title)
|
|
1186 |
@f.puts "<title>#{title}"
|
|
1187 |
end
|
|
1188 |
|
|
1189 |
def do_author(author)
|
|
1190 |
@f.puts "<author>#{author}"
|
|
1191 |
end
|
|
1192 |
|
|
1193 |
def do_date(date)
|
|
1194 |
@f.puts "<date>#{date}"
|
|
1195 |
end
|
|
1196 |
|
|
1197 |
def do_bgcolor(color)
|
|
1198 |
end
|
|
1199 |
|
|
1200 |
def do_fgcolor(color)
|
|
1201 |
end
|
|
1202 |
|
|
1203 |
def do_color(color)
|
|
1204 |
end
|
|
1205 |
|
|
1206 |
def close
|
|
1207 |
@f.puts "</article>"
|
|
1208 |
@f.close
|
|
1209 |
end
|
|
1210 |
|
|
1211 |
end
|
|
1212 |
|
|
1213 |
|
|
1214 |
# class TppController
|
|
1215 |
# generic controller that does nothing
|
|
1216 |
class TppController
|
|
1217 |
|
|
1218 |
def initialize
|
|
1219 |
$stderr.puts "Error: TppController.initialize has been called directly!"
|
|
1220 |
Kernel.exit(1)
|
|
1221 |
end
|
|
1222 |
|
|
1223 |
def close
|
|
1224 |
$stderr.puts "Error: TppController.close has been called directly!"
|
|
1225 |
Kernel.exit(1)
|
757 | 1226 |
end
|
758 | 1227 |
|
759 | 1228 |
def run
|
760 | |
changed_page = true
|
761 | |
jumped_out = false
|
762 | |
x = ""
|
763 | |
while true do
|
764 | |
if changed_page then
|
765 | |
x = draw_page(@pages[@current_page])
|
766 | |
jump_out_chars = [ 'q'[0],'j'[0],'Q'[0],'J'[0],'e'[0],'E'[0],'s'[0],'S'[0],'c'[0],'C'[0],'?'[0], Ncurses::KEY_LEFT, Ncurses::KEY_RIGHT, Ncurses::KEY_UP, Ncurses::KEY_DOWN ]
|
767 | |
jumped_out = true if jump_out_chars.include?(x)
|
768 | |
# jumped_out = true if x == 'q'[0] or x == 'j'[0] or x == 'Q'[0] or x == 'J'[0] or x == 'e'[0] or x == 'E'[0] or x == 's'[0] or x == 'S'[0] or x == 'c' or x == 'C'[0]
|
769 | |
draw_slidenum # draw slidenum to bring cursor down
|
770 | |
@screen.refresh()
|
771 | |
end
|
772 | |
if not jumped_out then
|
773 | |
draw_eop_marker
|
774 | |
draw_slidenum
|
775 | |
@screen.refresh()
|
776 | |
x = @screen.getch()
|
777 | |
end
|
778 | |
changed_page = false
|
779 | |
jumped_out = false
|
780 | |
case x
|
781 | |
when 'q'[0], 'Q'[0] # 'Q'uit
|
782 | |
return
|
783 | |
when 'r'[0], 'R'[0] # 'R'edraw slide
|
784 | |
changed_page = true
|
785 | |
when 'j'[0], 'J'[0] # 'J'ump to slide
|
786 | |
p = read_newpage
|
787 | |
if p >=0 and p < @number_pages then
|
788 | |
@current_page = p
|
789 | |
end
|
790 | |
changed_page = true
|
791 | |
draw_slidenum
|
792 | |
when '?'[0] # show a help screen explaining all important commands
|
793 | |
new_scr = @screen.dupwin
|
794 | |
show_helpscreen
|
795 | |
Ncurses.overwrite(new_scr,@screen)
|
796 | |
@screen.refresh()
|
797 | |
draw_slidenum
|
798 | |
when 'e'[0], 'E'[0] # jump to end
|
799 | |
@current_page=@number_pages-1
|
800 | |
changed_page = true
|
801 | |
when 's'[0], 'S'[0] # jump to start
|
802 | |
@current_page = 0
|
803 | |
changed_page = true
|
804 | |
when Ncurses::KEY_RIGHT, Ncurses::KEY_DOWN, ' '[0] # next slide
|
805 | |
if @current_page + 1 < @number_pages then
|
806 | |
@current_page += 1
|
807 | |
changed_page = true
|
808 | |
end
|
809 | |
when 'b'[0], 'B'[0], Ncurses::KEY_LEFT, Ncurses::KEY_UP # previous slide
|
810 | |
if @current_page > 0 then
|
811 | |
@current_page -= 1
|
812 | |
changed_page = true
|
813 | |
end
|
814 | |
when 'c'[0], 'C'[0] # commandprompt
|
815 | |
command_prompt()
|
816 | |
changed_page = true
|
817 | |
when Ncurses::KEY_RESIZE # WINCH signal (ugly!)
|
818 | |
set_sizes
|
819 | |
end # case
|
820 | |
@screen.refresh()
|
821 | |
end # while
|
822 | |
end
|
823 | |
|
824 | |
def on_first_page?
|
825 | |
@current_page == 0
|
826 | |
end
|
827 | |
|
828 | |
def on_last_page?
|
829 | |
@current_page == (@number_pages - 1)
|
|
1229 |
$stderr.puts "Error: TppController.run has been called directly!"
|
|
1230 |
Kernel.exit(1)
|
830 | 1231 |
end
|
831 | 1232 |
|
832 | 1233 |
end
|
833 | 1234 |
|
834 | |
filename = nil
|
835 | |
output_latex = false
|
836 | |
latex_filename = nil
|
|
1235 |
# class NcursesController
|
|
1236 |
# controls both the keyboard input and what needs to be printed
|
|
1237 |
class NcursesController < TppController
|
|
1238 |
|
|
1239 |
def initialize(filename)
|
|
1240 |
@filename = filename
|
|
1241 |
@vis = NcursesVisualizer.new
|
|
1242 |
@cur_page = 0
|
|
1243 |
end
|
|
1244 |
|
|
1245 |
def close
|
|
1246 |
@vis.close
|
|
1247 |
end
|
|
1248 |
|
|
1249 |
def run
|
|
1250 |
begin
|
|
1251 |
@reload_file = false
|
|
1252 |
parser = FileParser.new(@filename)
|
|
1253 |
@pages = parser.get_pages
|
|
1254 |
if @cur_page >= @pages.size then
|
|
1255 |
@cur_page = @pages.size - 1
|
|
1256 |
end
|
|
1257 |
@vis.clear
|
|
1258 |
@vis.new_page
|
|
1259 |
do_run
|
|
1260 |
end while @reload_file
|
|
1261 |
end
|
|
1262 |
|
|
1263 |
def do_run
|
|
1264 |
window = Ncurses.stdscr
|
|
1265 |
loop do
|
|
1266 |
wait = false
|
|
1267 |
@vis.draw_slidenum(@cur_page + 1, @pages.size, false)
|
|
1268 |
# read and visualize lines until the visualizer says "stop" or we reached end of page
|
|
1269 |
begin
|
|
1270 |
line = @pages[@cur_page].next_line
|
|
1271 |
eop = @pages[@cur_page].eop?
|
|
1272 |
wait = @vis.visualize(line,eop)
|
|
1273 |
end while not wait and not eop
|
|
1274 |
# draw slide number on the bottom left and redraw:
|
|
1275 |
@vis.draw_slidenum(@cur_page + 1, @pages.size, eop)
|
|
1276 |
@vis.do_refresh
|
|
1277 |
|
|
1278 |
# read a character from the keyboard
|
|
1279 |
# a "break" in the when means that it breaks the loop, i.e. goes on with visualizing lines
|
|
1280 |
loop do
|
|
1281 |
ch = window.getch
|
|
1282 |
case ch
|
|
1283 |
when 'q'[0], 'Q'[0] # 'Q'uit
|
|
1284 |
return
|
|
1285 |
when 'r'[0], 'R'[0] # 'R'edraw slide
|
|
1286 |
changed_page = true # @todo: actually implement redraw
|
|
1287 |
when 'e'[0], 'E'[0]
|
|
1288 |
@cur_page = @pages.size - 1
|
|
1289 |
break
|
|
1290 |
when 's'[0], 'S'[0]
|
|
1291 |
@cur_page = 0
|
|
1292 |
break
|
|
1293 |
when 'j'[0], 'J'[0] # 'J'ump to slide
|
|
1294 |
screen = @vis.store_screen
|
|
1295 |
p = @vis.read_newpage(@pages,@cur_page)
|
|
1296 |
if p >= 0 and p < @pages.size
|
|
1297 |
@cur_page = p
|
|
1298 |
@pages[@cur_page].reset_eop
|
|
1299 |
@vis.new_page
|
|
1300 |
else
|
|
1301 |
@vis.restore_screen(screen)
|
|
1302 |
end
|
|
1303 |
break
|
|
1304 |
when 'l'[0], 'L'[0] # re'l'oad current file
|
|
1305 |
@reload_file = true
|
|
1306 |
return
|
|
1307 |
when 'c'[0], 'C'[0] # command prompt
|
|
1308 |
screen = @vis.store_screen
|
|
1309 |
@vis.do_command_prompt
|
|
1310 |
#ch = window.getch
|
|
1311 |
@vis.clear
|
|
1312 |
@vis.restore_screen(screen)
|
|
1313 |
when '?'[0], 'h'[0]
|
|
1314 |
screen = @vis.store_screen
|
|
1315 |
@vis.show_help_page
|
|
1316 |
ch = window.getch
|
|
1317 |
@vis.clear
|
|
1318 |
@vis.restore_screen(screen)
|
|
1319 |
when Ncurses::KEY_RIGHT, Ncurses::KEY_DOWN, ' '[0]
|
|
1320 |
if @cur_page + 1 < @pages.size and eop then
|
|
1321 |
@cur_page += 1
|
|
1322 |
@pages[@cur_page].reset_eop
|
|
1323 |
@vis.new_page
|
|
1324 |
end
|
|
1325 |
break
|
|
1326 |
when 'b'[0], 'B'[0], Ncurses::KEY_LEFT, Ncurses::KEY_UP
|
|
1327 |
if @cur_page > 0 then
|
|
1328 |
@cur_page -= 1
|
|
1329 |
@pages[@cur_page].reset_eop
|
|
1330 |
@vis.new_page
|
|
1331 |
end
|
|
1332 |
break
|
|
1333 |
when Ncurses::KEY_RESIZE
|
|
1334 |
@vis.setsizes
|
|
1335 |
end
|
|
1336 |
end
|
|
1337 |
end # loop
|
|
1338 |
end
|
|
1339 |
|
|
1340 |
end
|
|
1341 |
|
|
1342 |
|
|
1343 |
class LinuxdocController
|
|
1344 |
|
|
1345 |
def initialize(input,output)
|
|
1346 |
parser = FileParser.new(input)
|
|
1347 |
@pages = parser.get_pages
|
|
1348 |
@vis = LinuxdocVisualizer.new(output)
|
|
1349 |
end
|
|
1350 |
|
|
1351 |
def run
|
|
1352 |
@pages.each do |p|
|
|
1353 |
begin
|
|
1354 |
line = p.next_line
|
|
1355 |
eop = p.eop?
|
|
1356 |
@vis.visualize(line,eop)
|
|
1357 |
end while not eop
|
|
1358 |
end
|
|
1359 |
end
|
|
1360 |
|
|
1361 |
def close
|
|
1362 |
@vis.close
|
|
1363 |
end
|
|
1364 |
|
|
1365 |
end
|
|
1366 |
|
|
1367 |
|
|
1368 |
def usage
|
|
1369 |
$stderr.puts "usage: #{$0} [-t <type> -o <file>] <file>\n"
|
|
1370 |
$stderr.puts "\t -t <type>\t\tset filetype <type> as output format"
|
|
1371 |
$stderr.puts "\t -o <file>\t\twrite output to file <file>"
|
|
1372 |
$stderr.puts "\t --version\t\tprint the version"
|
|
1373 |
$stderr.puts "\t --help\t\t\tprint this help"
|
|
1374 |
$stderr.puts "\n\t currently available types: ncurses (default), linuxdoc"
|
|
1375 |
Kernel.exit(1)
|
|
1376 |
end
|
|
1377 |
|
|
1378 |
input = nil
|
|
1379 |
output = nil
|
|
1380 |
type = "ncurses"
|
|
1381 |
|
837 | 1382 |
skip_next = false
|
838 | |
version_number = "1.1.1"
|
|
1383 |
|
839 | 1384 |
ARGV.each_index do |i|
|
840 | 1385 |
if skip_next then
|
841 | 1386 |
skip_next = false
|
842 | 1387 |
else
|
843 | |
if ARGV[i] == "-l" or ARGV[i] == "--latex" then
|
844 | |
output_latex = true
|
845 | |
latex_filename = ARGV[i+1]
|
|
1388 |
if ARGV[i] == '-v' or ARGV[i] == '--version' then
|
|
1389 |
printf "tpp - text presentation program %s\n", version_number
|
|
1390 |
elsif ARGV[i] == '-h' or ARGV[i] == '--help' then
|
|
1391 |
usage
|
|
1392 |
elsif ARGV[i] == '-t' then
|
|
1393 |
type = ARGV[i+1]
|
846 | 1394 |
skip_next = true
|
847 | |
elsif ARGV[i] == "-h" or ARGV[i] == "--help" then
|
848 | |
printf "tpp - text presentation program %s\n", version_number
|
849 | |
elsif ARGV[i] == "-v" or ARGV[i] == "--version" then
|
850 | |
printf "tpp - text presentation program %s\n", version_number
|
851 | |
Kernel.exit(1)
|
852 | |
elsif filename == nil then
|
853 | |
filename = ARGV[i]
|
854 | |
end
|
|
1395 |
elsif ARGV[i] == '-o' then
|
|
1396 |
output = ARGV[i+1]
|
|
1397 |
skip_next = true
|
|
1398 |
elsif input == nil then
|
|
1399 |
input = ARGV[i]
|
|
1400 |
end
|
|
1401 |
if output==input then
|
|
1402 |
$stderr.puts "Don't use the input file name as the output filename to prevent overwrinting it. \n"
|
|
1403 |
Kernel.exit(1)
|
|
1404 |
end
|
855 | 1405 |
end
|
856 | 1406 |
end
|
857 | 1407 |
|
858 | |
|
859 | |
if filename == nil then
|
860 | |
$stderr.puts "usage: #{$0} [options] <file>"
|
861 | |
$stderr.puts "\nOptions: -l <outputfile> <file> convert presentation to latex"
|
862 | |
$stderr.puts "\t --version\t\tprints this help"
|
863 | |
$stderr.puts "\t --help\t\t\tprints this help"
|
864 | |
Kernel.exit(1)
|
|
1408 |
if input == nil then
|
|
1409 |
usage
|
865 | 1410 |
end
|
866 | 1411 |
|
867 | |
parser = FileParser.new(filename)
|
868 | |
parser.do_work(output_latex)
|
869 | |
|
870 | |
pages = parser.get_pages
|
871 | |
bgcolor = parser.get_bgcolor
|
872 | |
|
873 | |
if output_latex then
|
874 | |
if latex_filename == nil then
|
875 | |
$stderr.puts "error: no filename supplied to -l"
|
876 | |
Kernel.exit(1)
|
877 | |
end
|
878 | |
gen = LatexGenerator.new(pages,parser.get_title,parser.get_author,parser.get_date)
|
879 | |
gen.generate_output(latex_filename)
|
|
1412 |
ctrl = nil
|
|
1413 |
|
|
1414 |
case type
|
|
1415 |
when "linuxdoc"
|
|
1416 |
if output == nil then
|
|
1417 |
usage
|
|
1418 |
else
|
|
1419 |
ctrl = LinuxdocController.new(input,output)
|
|
1420 |
end
|
|
1421 |
when "ncurses"
|
|
1422 |
ctrl = NcursesController.new(input)
|
880 | 1423 |
else
|
881 | |
pager = Pager.new(pages,bgcolor)
|
882 | |
pager.run
|
883 | |
pager.close
|
884 | |
end
|
|
1424 |
usage
|
|
1425 |
end # case
|
|
1426 |
|
|
1427 |
ctrl.run
|
|
1428 |
ctrl.close
|