Skip to content

Instantly share code, notes, and snippets.

@ugexe
Created March 7, 2023 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ugexe/639b25784e4a933206f5069faa182273 to your computer and use it in GitHub Desktop.
Save ugexe/639b25784e4a933206f5069faa182273 to your computer and use it in GitHub Desktop.
use v6.d;
use NativeCall;
class winsize is repr('CStruct') {
has uint16 $.rows;
has uint16 $.cols;
has uint16 $.xpixels;
has uint16 $.ypixels;
method gist() {
return "rows={self.rows} cols={self.cols} {self.xpixels}x{self.ypixels}"
}
}
# copied from my `/usr/include/asm-generic/ioctls.h`
constant TIOCGWINSZ = 0x5413;
sub term-size(--> winsize) {
sub ioctl(int32 $fd, int32 $cmd, winsize $winsize) is native {*}
my winsize $winsize .= new;
ioctl(0,TIOCGWINSZ,$winsize);
return $winsize;
}
say term-size();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment