43 | 43 |
"blue" => 5,
|
44 | 44 |
"cyan" => 6,
|
45 | 45 |
"magenta" => 7,
|
46 | |
"black" => 8,
|
|
46 |
"black" => 8,
|
47 | 47 |
"default" =>-1}
|
48 | 48 |
colors[color]
|
49 | 49 |
end
|
|
94 | 94 |
end # class FileParser
|
95 | 95 |
|
96 | 96 |
|
97 | |
# Represents a page (aka `slide') in TPP. A page consists of a title and one or
|
|
97 |
# Represents a page (aka `slide') in TPP. A page consists of a title and one or
|
98 | 98 |
# more lines.
|
99 | 99 |
class Page
|
100 | 100 |
|
|
144 | 144 |
|
145 | 145 |
|
146 | 146 |
|
147 | |
# Implements a generic visualizer from which all other visualizers need to be
|
148 | |
# derived. If Ruby supported abstract methods, all the do_* methods would be
|
|
147 |
# Implements a generic visualizer from which all other visualizers need to be
|
|
148 |
# derived. If Ruby supported abstract methods, all the do_* methods would be
|
149 | 149 |
# abstract.
|
150 | 150 |
class TppVisualizer
|
151 | 151 |
|
|
153 | 153 |
# nothing
|
154 | 154 |
end
|
155 | 155 |
|
156 | |
# Splits a line into several lines, where each of the result lines is at most
|
157 | |
# _width_ characters long, caring about word boundaries, and returns an array
|
|
156 |
# Splits a line into several lines, where each of the result lines is at most
|
|
157 |
# _width_ characters long, caring about word boundaries, and returns an array
|
158 | 158 |
# of strings.
|
159 | 159 |
def split_lines(text,width)
|
160 | 160 |
lines = []
|
|
189 | 189 |
$stderr.puts "Error: TppVisualizer#do_footer has been called directly."
|
190 | 190 |
Kernel.exit(1)
|
191 | 191 |
end
|
192 | |
|
|
192 |
|
193 | 193 |
def do_header(header_text)
|
194 | 194 |
$stderr.puts "Error: TppVisualizer#do_header has been called directly."
|
195 | 195 |
Kernel.exit(1)
|
196 | 196 |
end
|
197 | 197 |
|
198 | |
|
|
198 |
|
199 | 199 |
def do_refresh
|
200 | 200 |
$stderr.puts "Error: TppVisualizer#do_refresh has been called directly."
|
201 | 201 |
Kernel.exit(1)
|
|
315 | 315 |
$stderr.puts "Error: TppVisualizer#do_command_prompt has been called directly."
|
316 | 316 |
Kernel.exit(1)
|
317 | 317 |
end
|
318 | |
|
|
318 |
|
319 | 319 |
def do_beginslideright
|
320 | 320 |
$stderr.puts "Error: TppVisualizer#do_beginslideright has been called directly."
|
321 | 321 |
Kernel.exit(1)
|
|
376 | 376 |
Kernel.exit(1)
|
377 | 377 |
end
|
378 | 378 |
|
379 | |
# Receives a _line_, parses it if necessary, and dispatches it
|
|
379 |
# Receives a _line_, parses it if necessary, and dispatches it
|
380 | 380 |
# to the correct method which then does the correct processing.
|
381 | 381 |
# It returns whether the controller shall wait for input.
|
382 | 382 |
def visualize(line,eop)
|
|
445 | 445 |
do_huge(figlet_text)
|
446 | 446 |
when /^--footer /
|
447 | 447 |
@footer_txt = line.sub(/^--footer /,"")
|
448 | |
do_footer(@footer_txt)
|
|
448 |
do_footer(@footer_txt)
|
449 | 449 |
when /^--header /
|
450 | 450 |
@header_txt = line.sub(/^--header /,"")
|
451 | |
do_header(@header_txt)
|
|
451 |
do_header(@header_txt)
|
452 | 452 |
when /^--title /
|
453 | 453 |
title = line.sub(/^--title /,"")
|
454 | 454 |
do_title(title)
|
|
546 | 546 |
@withborder = true
|
547 | 547 |
draw_border
|
548 | 548 |
end
|
549 | |
|
|
549 |
|
550 | 550 |
def do_command_prompt()
|
551 | 551 |
message = "Press any key to continue :)"
|
552 | 552 |
cursor_pos = 0
|
|
567 | 567 |
window.move(@termheight/4,1+prompt.length+cursor_pos) # move cursor to the end of code
|
568 | 568 |
ch = window.getch
|
569 | 569 |
case ch
|
570 | |
when Ncurses::KEY_ENTER, ?\n, ?\r
|
|
570 |
when Ncurses::KEY_ENTER, "\n"[0].ord, "\r"[0].ord
|
571 | 571 |
Ncurses.curs_set(0)
|
572 | 572 |
Ncurses.noecho
|
|
573 |
window.move(@termheight/4 + 1,1) # move cursor to the next line
|
|
574 |
window.refresh
|
573 | 575 |
rc = Kernel.system(string)
|
574 | 576 |
if not rc then
|
575 | 577 |
@screen.mvaddstr(@termheight/4+1,1,"Error: exec \"#{string}\" failed with error code #{$?}")
|
576 | 578 |
@screen.mvaddstr(@termheight-2,@termwidth/2-message.length/2,message)
|
|
579 |
ch = Ncurses.getch()
|
|
580 |
@screen.refresh
|
577 | 581 |
end
|
578 | 582 |
if rc then
|
579 | 583 |
@screen.mvaddstr(@termheight-2,@termwidth/2-message.length/2,message)
|
|
581 | 585 |
@screen.refresh
|
582 | 586 |
end
|
583 | 587 |
return
|
584 | |
when Ncurses::KEY_LEFT
|
|
588 |
when Ncurses::KEY_LEFT
|
585 | 589 |
cursor_pos = [0, cursor_pos-1].max # jump one character to the left
|
586 | 590 |
when Ncurses::KEY_RIGHT
|
587 | 591 |
cursor_pos = [0, cursor_pos+1].max # jump one character to the right
|
588 | |
when Ncurses::KEY_BACKSPACE
|
|
592 |
when Ncurses::KEY_BACKSPACE, "\b"[0].ord, 127
|
589 | 593 |
string = string[0...([0, cursor_pos-1].max)] + string[cursor_pos..-1]
|
590 | 594 |
cursor_pos = [0, cursor_pos-1].max
|
591 | |
window.mvaddstr(@termheight/4, 1+prompt.length+string.length, " ")
|
592 | |
when " "[0]..255
|
|
595 |
window.mvaddstr(@termheight/4, 1+prompt.length+string.length, " ")
|
|
596 |
when " "[0].ord..255
|
593 | 597 |
if (cursor_pos < max_len)
|
594 | 598 |
string[cursor_pos,0] = ch.chr
|
595 | 599 |
cursor_pos += 1
|
|
613 | 617 |
(@termwidth-2).times { @screen.addstr("-") }; @screen.addstr("'")
|
614 | 618 |
1.upto(@termheight-3) do |y|
|
615 | 619 |
@screen.move(y,0)
|
616 | |
@screen.addstr("|")
|
|
620 |
@screen.addstr("|")
|
617 | 621 |
end
|
618 | 622 |
1.upto(@termheight-3) do |y|
|
619 | 623 |
@screen.move(y,@termwidth-1)
|
620 | |
@screen.addstr("|")
|
|
624 |
@screen.addstr("|")
|
621 | 625 |
end
|
622 | 626 |
end
|
623 | 627 |
|
|
699 | 703 |
end
|
700 | 704 |
|
701 | 705 |
def show_help_page
|
702 | |
help_text = [ "tpp help",
|
|
706 |
help_text = [ "tpp help",
|
703 | 707 |
"",
|
704 | 708 |
"space bar ............................... display next entry within page",
|
705 | 709 |
"space bar, cursor-down, cursor-right .... display next page",
|
|
774 | 778 |
@screen.move(@termheight - 3, (@termwidth - footer_txt.length)/2)
|
775 | 779 |
@screen.addstr(footer_txt)
|
776 | 780 |
end
|
777 | |
|
|
781 |
|
778 | 782 |
def do_header(header_txt)
|
779 | 783 |
@screen.move(@termheight - @termheight+1, (@termwidth - header_txt.length)/2)
|
780 | 784 |
@screen.addstr(header_txt)
|
|
860 | 864 |
def do_huge(figlet_text)
|
861 | 865 |
output_width = @termwidth - @indent
|
862 | 866 |
output_width -= 2 if @output or @shelloutput
|
863 | |
op = IO.popen("figlet -f #{@figletfont} -w #{output_width} -k \"#{figlet_text}\"","r")
|
|
867 |
op = IO.popen(["figlet", "-f", @figletfont, "-w", output_width.to_s, "-k", figlet_text], "r")
|
864 | 868 |
op.readlines.each do |line|
|
865 | 869 |
print_line(line)
|
866 | 870 |
end
|
|
917 | 921 |
time_to_sleep = 1.to_f / 20
|
918 | 922 |
Kernel.sleep(time_to_sleep)
|
919 | 923 |
xcount -= 1
|
920 | |
end
|
|
924 |
end
|
921 | 925 |
when "right"
|
922 | 926 |
(@termwidth - @indent).times do |pos|
|
923 | 927 |
@screen.move(@cur_line,@termwidth - pos - 1)
|
|
990 | 994 |
@screen.move(line,col*15 + 2)
|
991 | 995 |
if current_page == i then
|
992 | 996 |
@screen.printw("%2d %s <=",i+1,pages[i].title[0..80])
|
993 | |
else
|
|
997 |
else
|
994 | 998 |
@screen.printw("%2d %s",i+1,pages[i].title[0..80])
|
995 | 999 |
end
|
996 | 1000 |
line += 1
|
|
1091 | 1095 |
|
1092 | 1096 |
def do_footer(footer_text)
|
1093 | 1097 |
end
|
1094 | |
|
|
1098 |
|
1095 | 1099 |
def do_header(header_text)
|
1096 | 1100 |
end
|
1097 | 1101 |
|
|
1165 | 1169 |
|
1166 | 1170 |
def do_revon
|
1167 | 1171 |
end
|
1168 | |
|
|
1172 |
|
1169 | 1173 |
def do_command_prompt
|
1170 | 1174 |
end
|
1171 | 1175 |
def do_revoff
|
|
1182 | 1186 |
|
1183 | 1187 |
def do_endslide
|
1184 | 1188 |
end
|
1185 | |
|
|
1189 |
|
1186 | 1190 |
def do_beginslideright
|
1187 | 1191 |
end
|
1188 | 1192 |
|
|
1348 | 1352 |
|
1349 | 1353 |
end
|
1350 | 1354 |
|
1351 | |
# Implements an interactive controller which feeds the visualizer until it is
|
|
1355 |
# Implements an interactive controller which feeds the visualizer until it is
|
1352 | 1356 |
# told to stop, and then reads a key press and executes the appropiate action.
|
1353 | 1357 |
class InteractiveController < TppController
|
1354 | 1358 |
|
|
1395 | 1399 |
loop do
|
1396 | 1400 |
ch = @vis.get_key
|
1397 | 1401 |
case ch
|
1398 | |
when 'q'[0], 'Q'[0] # 'Q'uit
|
|
1402 |
when ?q.ord, ?Q.ord # 'Q'uit
|
1399 | 1403 |
return
|
1400 | |
when 'r'[0], 'R'[0] # 'R'edraw slide
|
|
1404 |
when ?r.ord, ?R.ord # 'R'edraw slide
|
1401 | 1405 |
changed_page = true # @todo: actually implement redraw
|
1402 | |
when 'e'[0], 'E'[0]
|
|
1406 |
when ?e.ord, ?E.ord
|
1403 | 1407 |
@cur_page = @pages.size - 1
|
1404 | 1408 |
break
|
1405 | |
when 's'[0], 'S'[0]
|
|
1409 |
when ?s.ord, ?S.ord
|
1406 | 1410 |
@cur_page = 0
|
1407 | 1411 |
break
|
1408 | |
when 'j'[0], 'J'[0] # 'J'ump to slide
|
|
1412 |
when ?j.ord, ?J.ord # 'J'ump to slide
|
1409 | 1413 |
screen = @vis.store_screen
|
1410 | 1414 |
p = @vis.read_newpage(@pages,@cur_page)
|
1411 | 1415 |
if p >= 0 and p < @pages.size
|
|
1416 | 1420 |
@vis.restore_screen(screen)
|
1417 | 1421 |
end
|
1418 | 1422 |
break
|
1419 | |
when 'l'[0], 'L'[0] # re'l'oad current file
|
|
1423 |
when ?l.ord, ?L.ord # re'l'oad current file
|
1420 | 1424 |
@reload_file = true
|
1421 | 1425 |
return
|
1422 | |
when 'c'[0], 'C'[0] # command prompt
|
|
1426 |
when ?c.ord, ?C.ord # command prompt
|
1423 | 1427 |
screen = @vis.store_screen
|
1424 | 1428 |
@vis.do_command_prompt
|
1425 | 1429 |
@vis.clear
|
1426 | 1430 |
@vis.restore_screen(screen)
|
1427 | |
when '?'[0], 'h'[0]
|
|
1431 |
when ??.ord, ?h.ord
|
1428 | 1432 |
screen = @vis.store_screen
|
1429 | 1433 |
@vis.show_help_page
|
1430 | 1434 |
ch = @vis.get_key
|
1431 | 1435 |
@vis.clear
|
1432 | 1436 |
@vis.restore_screen(screen)
|
1433 | |
when :keyright, :keydown, ' '[0]
|
|
1437 |
when :keyright, :keydown, ' '.ord
|
1434 | 1438 |
if @cur_page + 1 < @pages.size and eop then
|
1435 | 1439 |
@cur_page += 1
|
1436 | 1440 |
@pages[@cur_page].reset_eop
|
1437 | 1441 |
@vis.new_page
|
1438 | 1442 |
end
|
1439 | 1443 |
break
|
1440 | |
when 'b'[0], 'B'[0], :keyleft, :keyup
|
|
1444 |
when ?b.ord, ?B.ord, :keyleft, :keyup
|
1441 | 1445 |
if @cur_page > 0 then
|
1442 | 1446 |
@cur_page -= 1
|
1443 | 1447 |
@pages[@cur_page].reset_eop
|
|
1454 | 1458 |
end
|
1455 | 1459 |
|
1456 | 1460 |
|
1457 | |
# Implements a visualizer which converts TPP source to a nicely formatted text
|
|
1461 |
# Implements a visualizer which converts TPP source to a nicely formatted text
|
1458 | 1462 |
# file which can e.g. be used as handout.
|
1459 | 1463 |
class TextVisualizer < TppVisualizer
|
1460 | 1464 |
|
|
1474 | 1478 |
|
1475 | 1479 |
def do_footer(footer_text)
|
1476 | 1480 |
end
|
1477 | |
|
|
1481 |
|
1478 | 1482 |
def do_header(header_text)
|
1479 | 1483 |
end
|
1480 | 1484 |
|
|
1538 | 1542 |
|
1539 | 1543 |
def do_revon
|
1540 | 1544 |
end
|
1541 | |
|
|
1545 |
|
1542 | 1546 |
def do_command_prompt
|
1543 | 1547 |
end
|
1544 | 1548 |
def do_revoff
|
|
1555 | 1559 |
|
1556 | 1560 |
def do_endslide
|
1557 | 1561 |
end
|
1558 | |
|
|
1562 |
|
1559 | 1563 |
def do_beginslideright
|
1560 | 1564 |
end
|
1561 | 1565 |
|
|
1572 | 1576 |
def do_huge(text)
|
1573 | 1577 |
output_width = @width
|
1574 | 1578 |
output_width -= 2 if @output_env
|
1575 | |
op = IO.popen("figlet -f #{@figletfont} -w @output_width -k \"#{text}\"","r")
|
|
1579 |
op = IO.popen(["figlet", "-f", @figletfont, "-w", output_width.to_s, "-k", text], "r")
|
1576 | 1580 |
op.readlines.each do |line|
|
1577 | 1581 |
print_line(line)
|
1578 | 1582 |
end
|
|
1649 | 1653 |
|
1650 | 1654 |
end
|
1651 | 1655 |
|
1652 | |
# Implements a non-interactive controller to control non-interactive
|
1653 | |
# visualizers (i.e. those that are used for converting TPP source code into
|
|
1656 |
# Implements a non-interactive controller to control non-interactive
|
|
1657 |
# visualizers (i.e. those that are used for converting TPP source code into
|
1654 | 1658 |
# another format)
|
1655 | 1659 |
class ConversionController < TppController
|
1656 | 1660 |
|