<commit_before>use strict;
use warnings;

package AngelPS1::Plugin::Term::Size;

our $VERSION = $AngelPS1::VERSION;

use Exporter 5.57 ();
our @ISA = 'Exporter';
our @EXPORT = qw($LINES $COLUMNS);

our ($LINES, $COLUMNS);

# Get the ioctl number
my $TIOCGWINSZ =
    # Shortcut static table
    {
        # $^O => ioctl TIOCGWINSZ constant
        linux => 0x5413,
    }->{$^O}
||
    # Fallback: get the constant from ioctl.ph
    eval {
        package AngelPS1::Plugin::Term::Size::ioctl;
        require 'sys/ioctl.ph';
        delete $INC{'sys/ioctl.ph'};
        \&TIOCGWINSZ
    };


my $_WINSZ = pack('S4');

sub _update_from_ioctl
{
    ioctl(STDERR, $TIOCGWINSZ, $_WINSZ);
    ($LINES, $COLUMNS) = unpack('S2', $_WINSZ);
}

my $TTYNAME;
sub _update_from_stty
{
    my $line = `stty -F $TTYNAME size`;
    chomp $line;
    ($LINES, $COLUMNS) = split / /, $line;
}

# TODO If sys/ioctl.ph is not available, try:
# - Term::Size
# - Term::ReadKey
# - stty size
# - hardcoded value of TIOCGWINSZ based on $^O
# See also perlfaq8: How do I get the screen size?


sub import
{
    # Avoid multiple install due to multiple import from different packages
    unless ($SIG{WINCH}) {
        if (defined $TIOCGWINSZ) {
            # Terminal size change
            $SIG{WINCH} = \&_update_from_ioctl;
        } else {
            require POSIX;<commit_msg>darwin: fix Plugin::Term::Size::_update_from_stty<commit_after>use strict;
use warnings;

package AngelPS1::Plugin::Term::Size;

our $VERSION = $AngelPS1::VERSION;

use Exporter 5.57 ();
our @ISA = 'Exporter';
our @EXPORT = qw($LINES $COLUMNS);

our ($LINES, $COLUMNS);

# Get the ioctl number
my $TIOCGWINSZ =
    # Shortcut static table
    {
        # $^O => ioctl TIOCGWINSZ constant
        linux => 0x5413,
    }->{$^O}
||
    # Fallback: get the constant from ioctl.ph
    eval {
        package AngelPS1::Plugin::Term::Size::ioctl;
        require 'sys/ioctl.ph';
        delete $INC{'sys/ioctl.ph'};
        \&TIOCGWINSZ
    };


my $_WINSZ = pack('S4');

sub _update_from_ioctl
{
    ioctl(STDERR, $TIOCGWINSZ, $_WINSZ);
    ($LINES, $COLUMNS) = unpack('S2', $_WINSZ);
}

my $TTYNAME;
sub _update_from_stty
{
    my $line = $^O eq 'linux'
        ? `stty -F "$TTYNAME" size`
        # darwin, *BSD have '-f', Solaris has neither
        : `stty size <"$TTYNAME"`;
    chomp($line);
    ($LINES, $COLUMNS) = split / /, $line;
}

# TODO If sys/ioctl.ph is not available, try:
# - Term::Size
# - Term::ReadKey
# - stty size
# - hardcoded value of TIOCGWINSZ based on $^O
# See also perlfaq8: How do I get the screen size?


sub import
{
    # Avoid multiple install due to multiple import from different packages
    unless ($SIG{WINCH}) {
        if (defined $TIOCGWINSZ) {
            # Terminal size change
            $SIG{WINCH} = \&_update_from_ioctl;
        } else {
            require POSIX;
{'fraction_non_alphanumeric': 0.14315642458100558, 'fraction_numerical': 0.009776536312849162, 'mean_word_length': 2.784676354029062, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1762667', 'n_tokens_mistral': 1095, 'n_tokens_neox': 1045, 'n_words': 279}