Created
March 7, 2023 17:24
-
-
Save ugexe/639b25784e4a933206f5069faa182273 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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