diff --git a/Changelog b/Changelog index 195f8ef..e51dd34 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,8 @@ +1.42: + +Better tabluar output (better column calc). However, russian +grapheme length is still wrong. + 1.41: Generalized lang parsing and passing to dict.leo.org, which diff --git a/Org.pm b/Org.pm index 48a6427..460ea5c 100644 --- a/Org.pm +++ b/Org.pm @@ -7,7 +7,7 @@ # or service marks of their respective holders. package WWW::Dict::Leo::Org; -$WWW::Dict::Leo::Org::VERSION = "1.41"; +$WWW::Dict::Leo::Org::VERSION = "1.42"; use strict; use warnings; @@ -260,6 +260,7 @@ Accept-Language: en_US, en\r\n); sub hdr { + # HTML::TableParser header callback my ( $this, $tbl_id, $line_no, $data, $udata ) = @_; if ($data->[1] && $data->[0] eq $data->[1]) { $this->debug("Probable start of a new section: $data->[1]"); @@ -274,6 +275,7 @@ sub hdr { } sub row { + # HTML::TableParser data row callback # # divide rows into titles and lang data. # we get 2 items (left and right column), if they @@ -282,10 +284,10 @@ sub row { # are forumposts and ignored as well as rows with # empty left cells. my ( $this, $tbl_id, $line_no, $data, $udata ) = @_; - + my $len = length($data->[0]); if ($data->[1] && $data->[0] && $data->[0] ne $data->[1] && $data->[0] !~ /\d{2}:\d{2}$/) { - if (length($data->[0]) > $this->{Maxsize}) { - $this->{Maxsize} = length($data->[0]); + if ($len > $this->{Maxsize}) { + $this->{Maxsize} = $len; } $this->debug("line: $line_no, left: $data->[0], right: $data->[1]"); push @{$this->{section}}, { left => $data->[0], right => $data->[1] }; @@ -293,6 +295,12 @@ sub row { } } +sub grapheme_length { + my($this, $str) = @_; + my $count = 0; + while ($str =~ /\X/g) { $count++ }; + return $count; +} sub maxsize { my($this) = @_; @@ -534,6 +542,6 @@ Please don't forget to add debugging output! =head1 VERSION -1.41 +1.42 =cut diff --git a/leo b/leo index e232592..c82116a 100755 --- a/leo +++ b/leo @@ -14,7 +14,6 @@ # or service marks of their respective holders. #use lib qw(blib/lib); -#use Org; use utf8; @@ -35,7 +34,7 @@ my $default_c = "\033[0m"; # reset default terminal color my $bold_c = "\033[0;34m"; # blue color my $copy_c = "\033[0;35m"; # copyright message color (green) -my $version = "1.41"; +my $version = "1.42"; my $config = $ENV{HOME} . "/.leo"; my $cache = $ENV{HOME} . "/.leo-CACHE.db"; @@ -267,6 +266,10 @@ if(! @match) { $maxsize += 5; print "Found $lines matches for '$string' on dict.leo.org:\n"; +my $fmt; +my $c = "\$fmt = \" %-${maxsize}s %s\n\""; +eval $c; + # # print it out in a formated manner, keep the order of dict.leo.org # @@ -281,7 +284,6 @@ foreach my $section (@match) { } foreach my $entry (@{$section->{data}}) { - $entry->{left} =~ s/^(.*)$/$1 . " " x ($maxsize - length($1))/e; if ($conf{use_latin}) { utf8::decode($entry->{left}); utf8::decode($entry->{right}); @@ -290,7 +292,7 @@ foreach my $section (@match) { $entry->{left} =~ s/(\Q$string\E)/$bold_c . $1 . $default_c/ei; $entry->{right} =~ s/(\Q$string\E)/$bold_c . $1 . $default_c/ei; } - print " $entry->{left}$entry->{right}\n"; + printf $fmt, $entry->{left}, $entry->{right}; } } @@ -667,6 +669,6 @@ browser, what is not prohibited. At least not today. =head1 VERSION -This is the manpage for B version B<1.41>. +This is the manpage for B version B<1.42>. =cut