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. -----