diff --git a/kernel/src/fs/devices/ConsoleDevice.cpp b/kernel/src/fs/devices/ConsoleDevice.cpp index bf34fa76..9f8affe5 100644 --- a/kernel/src/fs/devices/ConsoleDevice.cpp +++ b/kernel/src/fs/devices/ConsoleDevice.cpp @@ -198,6 +198,13 @@ Result ConsoleDevice::ioctl(int request, void* arg) if (!MemoryManager::copy_to_user_typed((pid_t*)arg, &pgid)) return err(EFAULT); return 0; } + case TIOCGWINSZ: { + struct winsize window; + window.ws_col = TextConsole::cols(); + window.ws_row = TextConsole::rows(); + if (!MemoryManager::copy_to_user_typed((struct winsize*)arg, &window)) return err(EFAULT); + return 0; + } default: return err(EINVAL); } } diff --git a/kernel/src/video/TextConsole.cpp b/kernel/src/video/TextConsole.cpp index ae1547a6..033941fd 100644 --- a/kernel/src/video/TextConsole.cpp +++ b/kernel/src/video/TextConsole.cpp @@ -207,4 +207,14 @@ namespace TextConsole va_end(ap); return rc; } + + u16 rows() + { + return Framebuffer::height() / FONT_HEIGHT; + } + + u16 cols() + { + return Framebuffer::width() / FONT_WIDTH; + } } diff --git a/kernel/src/video/TextConsole.h b/kernel/src/video/TextConsole.h index 6db8fe88..6e6f5287 100644 --- a/kernel/src/video/TextConsole.h +++ b/kernel/src/video/TextConsole.h @@ -19,4 +19,7 @@ namespace TextConsole Result println(const char* str); void wprintln(const wchar_t* str); Result printf(const char* format, ...) _format(1, 2); + + u16 rows(); + u16 cols(); } diff --git a/libc/include/bits/termios.h b/libc/include/bits/termios.h index 311de6ed..fd022569 100644 --- a/libc/include/bits/termios.h +++ b/libc/include/bits/termios.h @@ -11,6 +11,14 @@ struct termios tcflag_t c_lflag; }; +struct winsize +{ + u16 ws_row; + u16 ws_col; + u16 ws_xpixel; + u16 ws_ypixel; +}; + // Values for c_lflag. #define ECHO 1 #define TOSTOP 2 @@ -20,5 +28,6 @@ struct termios #define TCSETS 1 #define TIOCSPGRP 2 #define TIOCGPGRP 3 +#define TIOCGWINSZ 4 #endif