Perl でプレゼンテーションツール
Shibuya.js とかでは、JavaScript とかでプレゼンツールを自作しているのに、Perl でプレゼンツールを自作している奴は、見たことがない。
YAPC::ASIA 2007 の LT 向けに、ターミナルを使った高橋メソッドなプレゼンをやろうと思って、Perl で適当に書いてみた。
→、↓、[PgDn] でページを進む。
←、↑、[PgUp] でページを戻る。
[Home] で先頭ページへ。
[End]、C-c、C-d でプレゼン終了。
でも、ターミナルだと表現力が足りなさすぎてなんか面白くないからやめた。
そもそも Term::* 系ってほとんど使ったことがないから、よくわからないまんま作ってみて、微妙すぎて、これ以上手を加える気が失せた。
まずいないでしょうが、もし誰か使いたいっていう奇特な方がいたら、どうぞご勝手に。
#!/usr/local/bin/perl # $Id$ # nipotan <nipotan at nipotan.org> package Presentation::PageParser; use base qw(Class::Accessor::Fast); use Term::Size qw(chars); __PACKAGE__->mk_accessors(qw(lines position x y)); sub parse { my($self, $page) = @_; my @lines = split /\n/, $page; my($x, $y) = chars(); $self->x($x); $self->y($y); $self->lines(\@lines); my @position = (); my $pos_y = int(($y - scalar(@lines)) / 2); $pos_y = $pos_y < 0 ? 0 : $pos_y; for my $line (@lines) { my $pos_x = int(($x - length($line)) / 2); $pos_x = $pos_x < 0 ? 0 : $pos_x; push @position, [$pos_y++, $pos_x]; } $self->position(\@position); } package main; use strict; use Term::Screen; my @pages = split /\s+-{5}\s+/, join('', <DATA>); my $pre = Presentation::PageParser->new; my $scr = Term::Screen->new; sub _prev { $_[0]-- } sub _next { $_[0]++ } sub _home { $_[0] = 0 } sub _end { $_[0] = 99999 } my %keybind = ( ku => \&_prev, kd => \&_next, kl => \&_prev, kr => \&_prev, kh => \&_home, pgup => \&_prev, pgdn => \&_next, "\x03" => \&_end, "\x04" => \&_end, "\x1b" => \&_end, ); for (my $i = 0; $i < @pages; ) { my $page = $pages[$i]; $scr->clrscr(); $pre->parse($page); my $lines = $pre->lines; for (my $i = 0; $i < @$lines; $i++) { $scr->at(@{$pre->position->[$i]})->puts($lines->[$i]); } my $c; while ($c = $scr->at($pre->y, $pre->x)->getch) { if ($c =~ /^(?:k[udlrh]|pg(?:up|dn)|[\x03\x04\x1b])$/) { $keybind{$c}->($i); last; } } last if $i < 0; } $scr->clrscr(); __DATA__ Terminal Presentation by nipotan ----- Takahashi Method Perl version using Term::Size Term::Screen ----- This is the Takahashi Method. ----- It is a technique of producing slides for presentations. ----- It is similar to ----- The Lessig Method ----- It is credited to Mr. Masayoshi Takahashi. ----- Compared to a more typical presentation, ----- much fewer words are ----- used rather than sentences. -----