summaryrefslogtreecommitdiff
path: root/bucky2/t/browser.pl
diff options
context:
space:
mode:
Diffstat (limited to 'bucky2/t/browser.pl')
-rwxr-xr-xbucky2/t/browser.pl113
1 files changed, 113 insertions, 0 deletions
diff --git a/bucky2/t/browser.pl b/bucky2/t/browser.pl
new file mode 100755
index 0000000..1f3c87a
--- /dev/null
+++ b/bucky2/t/browser.pl
@@ -0,0 +1,113 @@
+#!/usr/bin/perl
+use lib "../lib";
+use Bucky;
+use Data::Dumper;
+my $bucky = new Bucky(); # "carbon");
+my $keywords = $bucky->db->select("keyword");
+my $threads = $bucky->db->select("thread");
+my $files = $bucky->db->select("file");
+my $comments = $bucky->db->select("comment");
+
+event_loop();
+
+my $commands;
+sub event_loop
+ {
+ my $command = "index";
+ my $index_i = 0;
+ while (1)
+ {
+ if ($command =~ /^\d+$/)
+ {
+ do_this($commands->{$command})
+ or print "bad index!" . "\n";
+ }
+ elsif ($command eq "index")
+ { $index_i = show_index(0) }
+ else
+ { $index_i = show_index($index_i) }
+ print "> ";
+ $command = line_in();
+ last if $command eq "exit";
+ }
+ }
+
+#[keyword,thread,file,comment]
+#select * from family where keyword=id
+#select thread from family where keyword=id
+
+sub do_this
+ {
+ my ($command) = @_;
+ return unless $command;
+ my ($sub, @object) = @$command;
+ return &$sub(@object);
+ }
+sub show_index
+ {
+ my ($min) = @_;
+ my $max = $min + 24;
+ my $i = 0;
+ foreach my $thread (@$threads)
+ {
+ next if $min > $i++;
+ last if $max == $i;
+ $commands->{$i} = [ \&show_thread, $thread ];
+ printf " T%02d %-70s\n", $i, $thread->{"title"};
+ }
+ return $max - 1;
+ }
+sub show_thread
+ {
+ my ($thread) = @_;
+ print $thread->{'title'} . "\n";
+ print $thread->{'username'} . " // " . show_date($thread->{createdate}) . "\n";
+ my $i = 0;
+ foreach my $comment (@$comments)
+ {
+ next if ($comment->{'thread'} != $thread->{'id'});
+ $commands->{++$i} = [ \&show_comment, $comment ];
+ printf " c%02d %-10s %-60s\n", $i, $comment->{"username"}, first_line($comment->{"comment"});
+ }
+ foreach my $file (@$files)
+ {
+ next if ($file->{'thread'} != $thread->{'id'});
+ printf " f%02d %-10s %-60s\n", ++$i, $file->{'username'}, $file->{'filename'};
+ }
+ return 1;
+ }
+sub show_comment
+ {
+ my ($comment) = @_;
+ print $comment->{'username'} . " // " . show_date($comment->{date}) . "\n";
+ my @lines = split "\n", $comment->{'comment'};
+ for (my $i = 0; $i < scalar(@lines); $i++)
+ {
+ print $lines[$i] . "\n";
+ last if $i == 24;
+ }
+ return 1;
+ }
+sub show_date
+ {
+ return scalar localtime(shift);
+ }
+sub line_in
+ {
+ return trim(scalar <STDIN>);
+ }
+sub trim
+ {
+ my $s = shift;
+ $s =~ s/^\s+//;
+ $s =~ s/\s+$//;
+ return $s;
+ }
+sub first_line
+ {
+ my $s = shift;
+ $s =~ s/^\s+//;
+ $s =~ s/\n//g;
+ return substr($s,0,70);
+ }
+