@@ -89,6 +89,63 @@ ARGON_FUNCTION(os_chdir, chdir,
89
89
return (ArObject *) IncRef (Nil);
90
90
}
91
91
92
+ ARGON_FUNCTION (os_cls, cls,
93
+ " Clear the console screen.\n "
94
+ " \n "
95
+ " This function clears the console screen." ,
96
+ nullptr , false , false ) {
97
+ #ifdef _ARGON_PLATFORM_WINDOWS
98
+ HANDLE hConsole = GetStdHandle (STD_OUTPUT_HANDLE);
99
+ CONSOLE_SCREEN_BUFFER_INFO csbi;
100
+ DWORD count;
101
+ DWORD cellCount;
102
+ COORD homeCoords = {0 , 0 };
103
+
104
+ if (!GetConsoleScreenBufferInfo (hConsole, &csbi)) {
105
+ ErrorFromWinErr ();
106
+
107
+ return nullptr ;
108
+ }
109
+
110
+ cellCount = csbi.dwSize .X * csbi.dwSize .Y ;
111
+
112
+ if (!FillConsoleOutputCharacter (hConsole, (TCHAR)' ' , cellCount, homeCoords, &count)) {
113
+ ErrorFromWinErr ();
114
+
115
+ return nullptr ;
116
+ }
117
+
118
+ if (!FillConsoleOutputAttribute (hConsole, csbi.wAttributes , cellCount, homeCoords, &count)) {
119
+ ErrorFromWinErr ();
120
+
121
+ return nullptr ;
122
+ }
123
+
124
+ SetConsoleCursorPosition (hConsole, homeCoords);
125
+ #else
126
+ const char *clearScreen = " \033 [2J" ; // Clear entire screen
127
+ const char *moveCursor = " \033 [H" ; // Move cursor to home position
128
+
129
+ if (isatty (STDOUT_FILENO)) {
130
+ if (write (STDOUT_FILENO, clearScreen, 4 ) == -1 ||
131
+ write (STDOUT_FILENO, moveCursor, 3 ) == -1 ) {
132
+ ErrorFromErrno (errno);
133
+
134
+ return nullptr ;
135
+ }
136
+ } else {
137
+ // If not a terminal, just print a form feed character
138
+ if (write (STDOUT_FILENO, " \f " , 1 ) == -1 ) {
139
+ ErrorFromErrno (errno);
140
+
141
+ return nullptr ;
142
+ }
143
+ }
144
+ #endif
145
+
146
+ return ARGON_NIL_VALUE;
147
+ }
148
+
92
149
ARGON_FUNCTION (os_dup, dup,
93
150
" Duplicate or reassigns a file descriptor.\n "
94
151
" \n "
@@ -1140,6 +1197,7 @@ const ModuleEntry os_entries[] = {
1140
1197
#endif
1141
1198
1142
1199
MODULE_EXPORT_FUNCTION (os_chdir),
1200
+ MODULE_EXPORT_FUNCTION (os_cls),
1143
1201
#ifdef _ARGON_PLATFORM_WINDOWS
1144
1202
MODULE_EXPORT_FUNCTION (os_createprocess),
1145
1203
#endif
0 commit comments