Linux console dimensions

Share your advanced PureBasic knowledge/code with the community.
Fruity
New User
New User
Posts: 5
Joined: Tue Aug 15, 2023 4:04 am

Linux console dimensions

Post by Fruity »

Maybe someone need it.

Code: Select all

Structure winsize
  ws_row.w    ; rows
  ws_col.w    ; columns
EndStructure

#STDIN_FILENO = 0 ; file descriptor of standard input
#TIOCGWINSZ = $5413 ; IOCTL request to get terminal window sizes

OpenConsole()

ws.winsize

If ioctl_(#STDIN_FILENO, #TIOCGWINSZ, @ws) = 0
  PrintN("Text console sizes:")
  PrintN("Rows: " + Str(ws\ws_row))
  PrintN("Columns: " + Str(ws\ws_col))  
Else
  PrintN("Error getting console sizes.")
EndIf

Input()