Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ IO::Stty - Change and print terminal line settings
# What settings do we have anyway?
print IO::Stty::stty(\*STDIN,'-a');

# Or with no arguments (same as -a):
print IO::Stty::stty(\*STDIN);

# DESCRIPTION

This is the PERL POSIX compliant stty.
Expand Down Expand Up @@ -365,9 +368,11 @@ Linux and 255 on macOS/BSD).

IO::Stty::stty(\*STDIN, @params);

Returns a string for query options (`-a`, `-g`, `-v`), `undef` if
the handle is not a terminal or if the terminal parameters could not be
read, and a true value on success when setting parameters.
When called with no parameters, returns the current terminal settings in
human-readable form (equivalent to `-a`), matching POSIX `stty`
behavior. Returns a string for query options (`-a`, `-g`, `-v`),
`undef` if the handle is not a terminal or if the terminal parameters
could not be read, and a true value on success when setting parameters.

From comments:

Expand Down
21 changes: 16 additions & 5 deletions lib/IO/Stty.pm
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ IO::Stty - Change and print terminal line settings
# What settings do we have anyway?
print IO::Stty::stty(\*STDIN,'-a');

# Or with no arguments (same as -a):
print IO::Stty::stty(\*STDIN);

=head1 DESCRIPTION

This is the PERL POSIX compliant stty.
Expand Down Expand Up @@ -483,9 +486,11 @@ sub _parse_char_value {

IO::Stty::stty(\*STDIN, @params);

Returns a string for query options (C<-a>, C<-g>, C<-v>), C<undef> if
the handle is not a terminal or if the terminal parameters could not be
read, and a true value on success when setting parameters.
When called with no parameters, returns the current terminal settings in
human-readable form (equivalent to C<-a>), matching POSIX C<stty>
behavior. Returns a string for query options (C<-a>, C<-g>, C<-v>),
C<undef> if the handle is not a terminal or if the terminal parameters
could not be read, and a true value on success when setting parameters.

From comments:

Expand All @@ -500,8 +505,6 @@ From comments:
sub stty {
my $tty_handle = shift; # This should be a \*HANDLE

@_ or die("No parameters passed to stty");

# Notice fileno() instead of handle->fileno(). I want it to work with
# normal fhs.
my ($file_num) = fileno($tty_handle);
Expand Down Expand Up @@ -537,6 +540,14 @@ sub stty {

# OK.. we have our crap.

# No arguments: display current settings (POSIX stty behavior).
unless (@_) {
return show_me_the_crap(
$c_cflag, $c_iflag, $ispeed, $c_lflag, $c_oflag,
$ospeed, \%control_chars
);
}

my @parameters;

if ( @_ == 1 ) {
Expand Down
22 changes: 22 additions & 0 deletions t/01-functional.t
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,21 @@ subtest '-a output format' => sub {
like($output, qr/intr\s*=/, '-a shows intr control char');
};

# ── 3b. No-argument display (POSIX stty behavior) ───────────────────

subtest 'no arguments returns current settings' => sub {
my ($pty, $slave) = fresh_pty();
my $output = IO::Stty::stty($slave);
ok(defined $output, 'no-arg stty returns output');
like($output, qr/speed \d+ baud/, 'no-arg output contains speed line');
like($output, qr/echo/, 'no-arg output mentions echo');
like($output, qr/icanon/, 'no-arg output mentions icanon');

# Should be identical to -a output
my $a_output = IO::Stty::stty($slave, '-a');
is($output, $a_output, 'no-arg output matches -a output');
};

# ── 4. Combination settings ──────────────────────────────────────────

subtest 'raw mode' => sub {
Expand Down Expand Up @@ -432,6 +447,13 @@ subtest 'non-tty handle returns undef' => sub {
close $fh;
};

subtest 'non-tty handle with no args returns undef' => sub {
open my $fh, '<', '/dev/null' or die "open /dev/null: $!";
my $result = IO::Stty::stty($fh);
is($result, undef, 'non-tty with no args returns undef (no die)');
close $fh;
};

# ── 9. iexten flag ─────────────────────────────────────────────────────

subtest 'toggle iexten flag' => sub {
Expand Down
Loading