diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..aaac325 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,8 @@ +root = true + +[*] +indent_style = tab +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6cf2971 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +term-size.exe diff --git a/build.bat b/build.bat new file mode 100644 index 0000000..2fb1724 --- /dev/null +++ b/build.bat @@ -0,0 +1,7 @@ +@echo off + +set filename=term-size + +windres --codepage=65001 meta.rc meta.o +gcc "%filename%".c meta.o -municode -O2 -s -o "%filename%".exe -std=c99 +del meta.o diff --git a/license b/license new file mode 100644 index 0000000..654d0bf --- /dev/null +++ b/license @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) Sindre Sorhus (sindresorhus.com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/meta.rc b/meta.rc new file mode 100644 index 0000000..0a560d4 --- /dev/null +++ b/meta.rc @@ -0,0 +1,23 @@ +#define VERSION 0,1,0 +#define VERSION_STR "0.1.0" + +1 VERSIONINFO +FILEVERSION VERSION +PRODUCTVERSION VERSION +{ + BLOCK "StringFileInfo" { + BLOCK "040904E4" { + VALUE "CompanyName", "https://sindresorhus.com" + VALUE "FileDescription", "Get the terminal window size" + VALUE "FileVersion", VERSION_STR + VALUE "InternalName", "term-size" + VALUE "LegalCopyright", "MIT Licence © Sindre Sorhus" + VALUE "OriginalFilename", "term-size.exe" + VALUE "ProductName", "term-size" + VALUE "ProductVersion", VERSION_STR + } + } + BLOCK "VarFileInfo" { + VALUE "Translation", 0x0409, 1200 + } +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..c3a3ecb --- /dev/null +++ b/readme.md @@ -0,0 +1,40 @@ +# win-term-size + +> Get the terminal window size on Windows + +Works even when run [non-interactively](http://www.tldp.org/LDP/abs/html/intandnonint.html), for example, in a child process or when piped. + + +## Install + +[Download](https://github.com/sindresorhus/win-term-size/releases/latest) the binary and put it somewhere in your [`%path%`](http://stackoverflow.com/a/28778358/64949). + + +## Usage + +``` +$ term-size +143 +24 +``` + +Where `143` are number of columns and `24` are the number of rows. + + +## Build + +Install [`MinGW-w64`](https://sourceforge.net/projects/mingw-w64/) and run: + +``` +$ build +``` + + +## Related + +- [term-size](https://github.com/sindresorhus/term-size) - Get the terminal window size - cross-platform + + +## License + +MIT © [Sindre Sorhus](https://sindresorhus.com) diff --git a/term-size.c b/term-size.c new file mode 100644 index 0000000..37234ef --- /dev/null +++ b/term-size.c @@ -0,0 +1,20 @@ +#include +#include + +int wmain() { + CONSOLE_SCREEN_BUFFER_INFO info; + + HANDLE tmpConsole = CreateConsoleScreenBuffer(GENERIC_READ, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL); + + // can't use `GetStdHandle(STD_OUTPUT_HANDLE)` as it doesn't work when output is redirected + GetConsoleScreenBufferInfo(tmpConsole, &info); + + CloseHandle(tmpConsole); + + int columns = info.dwMaximumWindowSize.X; + int rows = info.dwMaximumWindowSize.Y; + + printf("%d\n%d\n", columns, rows); + + return 0; +}