Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 58 lines (50 sloc) 1.36 KB
#!/usr/bin/env perl
use strict;
use warnings;
use Lingua::JP::Kanjidic;
use Lingua::JA::Heisig -learned, 'heisig_number';
use Encode 'decode_utf8';
my $dic = Lingua::JP::Kanjidic->new("$ENV{HOME}/.kanjidic");
binmode(\*STDOUT, ':utf8');
for my $kanji (grep { /\p{Han}/ } split //, decode_utf8("@ARGV")) {
my $definition = $dic->lookup($kanji);
my $heisig = heisig_number($kanji);
print $kanji;
if ($definition) {
my $skip = $definition->skip;
print ' (';
print $definition->strokes;
print ' ' if $heisig || $skip;
if ($heisig) {
if (-t STDOUT) {
print is_learned($kanji) ? "\e[1;32m" : "\e[1;31m";
print $heisig;
print "\e[m";
}
else {
print $heisig;
}
}
print ' ' if $heisig && $skip;
print $skip if $skip;
print ')';
print ': ';
print join(', ', @{ $definition->meaning || ["???"] });
}
else {
if ($heisig) {
print " (";
if (-t STDOUT) {
print is_learned($kanji) ? "\e[1;32m" : "\e[1;31m";
print $heisig;
print "\e[m";
}
else {
print $heisig;
}
print ")";
}
print ': ???';
}
print "\n";
}