How does cls work under the hood? (windows)
Native Windows programs use the Console API to interact with console windows (although it is also slowly getting ANSI/xterm terminal protocol support in Windows 10).
There is Microsoft documentation page Clearing the Screen which describes how to clear a console:
- Use GetConsoleScreenBufferInfo to get buffer information;
- Use FillConsoleOutputCharacter to fill the buffer with spaces;
- Use FillConsoleOutputAttribute to reset the colors;
- Use SetConsoleCursorPosition to move the cursor to (0, 0).