Skip to content

Commit a80f121

Browse files
committed
feat: Add std::scan for Windows
1 parent 448cbc9 commit a80f121

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

std/io.sn

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace std {
1616
#[target_os = "windows"]
1717
namespace std {
1818
extern fn WriteConsoleA(i8*, i8*, u64, u64*, void*) : bool;
19+
extern fn ReadConsoleA(i8*, i8*, u64, u64*, void*) : bool;
1920
extern fn GetStdHandle(u64): i8*;
2021

2122
fn print(str: i8*) {
@@ -27,6 +28,20 @@ namespace std {
2728

2829
std::memory::deallocate(count);
2930
}
31+
32+
fn scan() : std::string {
33+
let handle = GetStdHandle(-10);
34+
let ptr = std::memory::allocate<i8>(4096);
35+
36+
let read: u64 = 0;
37+
ReadConsoleA(handle, ptr, 4096, &read, null);
38+
39+
let str = string::new(ptr, read - 1);
40+
41+
std::memory::deallocate(ptr);
42+
43+
return str;
44+
}
3045
}
3146

3247
namespace std {

0 commit comments

Comments
 (0)