Terminal control/Dimensions: Difference between revisions
Content added Content deleted
(Tidy up, remove non-implemented languages) |
(→{{header|PureBasic}}: Added PureBasic) |
||
Line 1: | Line 1: | ||
{{draft task}} |
{{draft task}} |
||
Determine the height and width of the terminal, and store this information into variables for subsequent use. |
Determine the height and width of the terminal, and store this information into variables for subsequent use. |
||
=={{header|PureBasic}}== |
|||
PureBasic does not have native functions for reading the size of this window, but supports API-functions that allows this. |
|||
This code is for Windows only. |
|||
<lang PureBasic>Macro ConsoleHandle() |
|||
GetStdHandle_( #STD_OUTPUT_HANDLE ) |
|||
EndMacro |
|||
Procedure ConsoleWidth() |
|||
Protected CBI.CONSOLE_SCREEN_BUFFER_INFO |
|||
Protected hConsole = ConsoleHandle() |
|||
GetConsoleScreenBufferInfo_( hConsole, @CBI ) |
|||
ProcedureReturn CBI\srWindow\right - CBI\srWindow\left + 1 |
|||
EndProcedure |
|||
Procedure ConsoleHeight() |
|||
Protected CBI.CONSOLE_SCREEN_BUFFER_INFO |
|||
Protected hConsole = ConsoleHandle() |
|||
GetConsoleScreenBufferInfo_( hConsole, @CBI ) |
|||
ProcedureReturn CBI\srWindow\bottom - CBI\srWindow\top + 1 |
|||
EndProcedure |
|||
If OpenConsole() |
|||
x$=Str(ConsoleWidth()) |
|||
y$=Str(ConsoleHeight()) |
|||
PrintN("This window is "+x$+"x"+y$+ " chars.") |
|||
; |
|||
Print(#CRLF$+"Press ENTER to exit"):Input() |
|||
EndIf</lang> |
|||
=={{header|UNIX Shell}}== |
=={{header|UNIX Shell}}== |
Revision as of 16:12, 6 October 2010
Terminal control/Dimensions is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
Determine the height and width of the terminal, and store this information into variables for subsequent use.
PureBasic
PureBasic does not have native functions for reading the size of this window, but supports API-functions that allows this.
This code is for Windows only. <lang PureBasic>Macro ConsoleHandle()
GetStdHandle_( #STD_OUTPUT_HANDLE )
EndMacro
Procedure ConsoleWidth()
Protected CBI.CONSOLE_SCREEN_BUFFER_INFO Protected hConsole = ConsoleHandle() GetConsoleScreenBufferInfo_( hConsole, @CBI ) ProcedureReturn CBI\srWindow\right - CBI\srWindow\left + 1
EndProcedure
Procedure ConsoleHeight()
Protected CBI.CONSOLE_SCREEN_BUFFER_INFO Protected hConsole = ConsoleHandle() GetConsoleScreenBufferInfo_( hConsole, @CBI ) ProcedureReturn CBI\srWindow\bottom - CBI\srWindow\top + 1
EndProcedure
If OpenConsole()
x$=Str(ConsoleWidth()) y$=Str(ConsoleHeight()) PrintN("This window is "+x$+"x"+y$+ " chars.") ; Print(#CRLF$+"Press ENTER to exit"):Input()
EndIf</lang>
UNIX Shell
<lang bash>#!/bin/bash WIDTH=`tput cols` HEIGHT=`tput lines` echo "The terminal is $WIDTH characters wide and has $HEIGHT lines"</lang>