Created
May 22, 2013 13:09
-
-
Save yteraoka/5627419 to your computer and use it in GitHub Desktop.
CR (Carriage Return) で Cinnamon が期待通りに動作しない件
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
register_read_type line => sub { | |
my ($self, $cb, $eol) = @_; | |
if (@_ < 3) { | |
# this is more than twice as fast as the generic code below | |
sub { | |
$_[0]{rbuf} =~ s/^([^\015\012]*)(\015?\012)// or return; | |
$cb->($_[0], "$1", "$2"); | |
1 | |
} | |
} else { | |
$eol = quotemeta $eol unless ref $eol; | |
$eol = qr|^(.*?)($eol)|s; | |
sub { | |
$_[0]{rbuf} =~ s/$eol// or return; | |
$cb->($_[0], "$1", "$2"); | |
1 | |
} | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub start_async_read { | |
my ($self) = @_; | |
my $handle_container = $self->{handle_container} or return; | |
my $cv = AnyEvent->condvar; | |
my $handles = []; | |
for my $name (keys %$handle_container) { | |
my $info = $handle_container->{$name}; | |
$cv->begin; | |
my $handle; $handle = AnyEvent::Handle->new( | |
fh => $info->{fh}, | |
on_read => sub { | |
$handle->push_read(line => sub { | |
my $line = $_[1]; | |
push @{$info->{output_lines}}, $line; | |
log info => sprintf "[%s :: %s] %s", | |
$self->{host}, $name, $line; | |
}); | |
}, | |
on_eof => sub { | |
$cv->end; | |
}, | |
on_error => sub { | |
my $msg = $_[2]; | |
log error => sprintf "[%s :: %s] %s", $self->{host}, $name, $msg | |
unless $! == POSIX::EPIPE; | |
$cv->end; | |
}, | |
); | |
push @$handles, $handle; | |
} | |
$cv->recv; | |
for my $h (@$handles) { | |
$h->destroy; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for my $i (0 .. 10) { | |
my $percent = sprintf "\r%3d%%", $i * 10; | |
syswrite(STDOUT, $percent, length($percent)); | |
sleep 1; | |
} | |
print "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment