kernel: Implement querying the terminal window size
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
apio 2023-07-12 22:09:28 +02:00
parent 78ea5dc352
commit efd5bae7a5
Signed by: apio
GPG Key ID: B8A7D06E42258954
4 changed files with 29 additions and 0 deletions

View File

@ -198,6 +198,13 @@ Result<u64> ConsoleDevice::ioctl(int request, void* arg)
if (!MemoryManager::copy_to_user_typed((pid_t*)arg, &pgid)) return err(EFAULT); if (!MemoryManager::copy_to_user_typed((pid_t*)arg, &pgid)) return err(EFAULT);
return 0; 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); default: return err(EINVAL);
} }
} }

View File

@ -207,4 +207,14 @@ namespace TextConsole
va_end(ap); va_end(ap);
return rc; return rc;
} }
u16 rows()
{
return Framebuffer::height() / FONT_HEIGHT;
}
u16 cols()
{
return Framebuffer::width() / FONT_WIDTH;
}
} }

View File

@ -19,4 +19,7 @@ namespace TextConsole
Result<void> println(const char* str); Result<void> println(const char* str);
void wprintln(const wchar_t* str); void wprintln(const wchar_t* str);
Result<usize> printf(const char* format, ...) _format(1, 2); Result<usize> printf(const char* format, ...) _format(1, 2);
u16 rows();
u16 cols();
} }

View File

@ -11,6 +11,14 @@ struct termios
tcflag_t c_lflag; tcflag_t c_lflag;
}; };
struct winsize
{
u16 ws_row;
u16 ws_col;
u16 ws_xpixel;
u16 ws_ypixel;
};
// Values for c_lflag. // Values for c_lflag.
#define ECHO 1 #define ECHO 1
#define TOSTOP 2 #define TOSTOP 2
@ -20,5 +28,6 @@ struct termios
#define TCSETS 1 #define TCSETS 1
#define TIOCSPGRP 2 #define TIOCSPGRP 2
#define TIOCGPGRP 3 #define TIOCGPGRP 3
#define TIOCGWINSZ 4
#endif #endif