<commit_before>#!/usr/bin/env perl6

#
# Example from
# http://software.gellyfish.co.uk/2015/10/learning-perl-6-from-bad-perl-5-code.html
#
use v6;

use lib 'lib';
use NCurses;

constant numstars  = 100;
constant screen-x  =  80;
constant screen-y  =  24;
constant max-speed =   4;

class Star {
    has Int $.x;
    has Int $.y;
    has Int $.s;

    submethod BUILD {
        $!x = (^screen-x).pick;
        $!y = (^screen-y).pick;
        $!s = (1 .. max-speed).pick;
    }

    method move {
        $!x = ($!x >= $!s)
          ?? $!x - $!s
          !! screen-x;
    }
}

my Star @stars = gather { take Star.new for ^numstars };

my $win = initscr;
die "Failed to initialize ncurses\n" unless $win.defined;

curs_set( 0 );

repeat {
    clear;
    for @stars -> $star {
        $star.move;
        mvaddstr( $star.y, $star.x, '.' )
    }
    nc_refresh;
    sleep( .05 );
} while getch() < 0;

endwin;
<commit_msg>Add true non-blocking getch() in starfield example<commit_after>#!/usr/bin/env perl6

#
# Example from
# http://software.gellyfish.co.uk/2015/10/learning-perl-6-from-bad-perl-5-code.html
#
use v6;

use lib 'lib';
use NCurses;

constant numstars  = 100;
constant screen-x  =  80;
constant screen-y  =  24;
constant max-speed =   4;

class Star {
    has Int $.x;
    has Int $.y;
    has Int $.s;

    submethod BUILD {
        $!x = (^screen-x).pick;
        $!y = (^screen-y).pick;
        $!s = (1 .. max-speed).pick;
    }

    method move {
        $!x = ($!x >= $!s)
          ?? $!x - $!s
          !! screen-x;
    }
}

my Star @stars = gather { take Star.new for ^numstars };

my $win = initscr;
die "Failed to initialize ncurses\n" unless $win.defined;

curs_set( 0 );
timeout( 0 );
repeat {
    clear;
    for @stars -> $star {
        $star.move;
        mvaddstr( $star.y, $star.x, '.' )
    }
    nc_refresh;
    sleep( .05 );
} while getch() < 0;

endwin;

{'fraction_non_alphanumeric': 0.1746031746031746, 'fraction_numerical': 0.02486772486772487, 'mean_word_length': 2.0698051948051948, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '3790119', 'n_tokens_mistral': 796, 'n_tokens_neox': 747, 'n_words': 184}