-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcurses.pl
More file actions
executable file
·41 lines (36 loc) · 951 Bytes
/
curses.pl
File metadata and controls
executable file
·41 lines (36 loc) · 951 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env perl
use v5.32;
use warnings;
use feature 'signatures';
no warnings 'experimental::signatures';
use open ':std', ':encoding(UTF-8)';
use Data::Printer;
use Curses;
my ( $r, $c, $nrows, $ncols ) = ( 0, 0, 0, 0 );
my $win = initscr();
cbreak();
noecho();
getmaxyx( $win, $nrows, $ncols );
clear();
refresh();
while (1) {
my $d = getch(); # curses call to input from keyboard
last if $d eq 'q';
draw($d); # draw the character
}
endwin();
sub draw($dc) {
move( $r, $c ); # curses call to move cursor to row r, column c
delch();
insch($dc); # curses calls to replace character under cursor by dc
refresh(); # curses call to update screen
$r++; # go to next row
# check for need to shift right or wrap around
if ( $r == $nrows ) {
$r = 0;
$c++;
if ( $c == $ncols ) {
$c = 0;
}
}
}