deal with carriage return when getting a number from stdin

This commit is contained in:
Folkert 2022-10-29 21:13:28 +02:00
parent a9d36431ba
commit b3f151fd53
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
3 changed files with 9 additions and 6 deletions

View file

@ -1,5 +1,6 @@
const std = @import("std");
const str = @import("str");
const builtin = @import("builtin");
const RocStr = str.RocStr;
const testing = std.testing;
const expectEqual = testing.expectEqual;
@ -15,7 +16,6 @@ comptime {
// -fcompiler-rt in link.rs instead of doing this. Note that this
// workaround is present in many host.zig files, so make sure to undo
// it everywhere!
const builtin = @import("builtin");
if (builtin.os.tag == .macos) {
_ = @import("compiler_rt");
}
@ -210,7 +210,8 @@ fn roc_fx_getInt_help() !i64 {
const stdin = std.io.getStdIn().reader();
var buf: [40]u8 = undefined;
const line: []u8 = (try stdin.readUntilDelimiterOrEof(&buf, '\n')) orelse "";
const delimiter = if (builtin.os.tag == .windows) '\r' else '\n';
const line: []u8 = (try stdin.readUntilDelimiterOrEof(&buf, delimiter)) orelse "";
return std.fmt.parseInt(i64, line, 10);
}