/
SystemInfo.pm6
37 lines (31 loc) · 1.09 KB
/
SystemInfo.pm6
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
unit module Zef::Utils::SystemInfo;
our $MAX-TERM-COLS is export = GET-TERM-COLUMNS();
our sub signal-ignore($) { Supply.new }
our $signal-handler := &::("signal") ~~ Failure ?? &::("signal-ignore") !! &::("signal");
our $sig-resize := ::("Signal::SIGWINCH");
try $signal-handler.($sig-resize).act: { $MAX-TERM-COLS = GET-TERM-COLUMNS() }
# Get terminal width
sub GET-TERM-COLUMNS is export {
if $*DISTRO.is-win {
# Windowsy
my $default = 80 - 1;
my $r = shell("mode", :out);
my $line = $r.out.lines.join("\n");
return $default unless $line;
if $line ~~ /'CON:' \n <.ws> '-'+ \n .*? \n \N+? $<cols>=[<.digit>+]/ {
my $cols = $/<cols>.comb(/\d/).join;
return +$cols - 1 if try { +$cols }
}
return $default;
}
else {
# Linuxy
my $default = 120 - 1;
my $tput = run("tput", "cols", :out);
if $tput.out.get ~~ /$<cols>=<.digit>+/ {
my $cols = ~$/<cols>.comb(/\d/).join;
return +$cols - 1 if try { +$cols }
}
return $default;
}
}