I am creating a terminal game which has a border on the top consisting of the ┌┐─│└┘ characters. I generate the border with this code:
fn hBorders(top: bool, num_cols: usize, piece_size: usize) error{OutOfMemory}![]u16 {
var len: usize = (num_cols + 2) * piece_size;
const border: []u16 = try allocator.alloc(u16, len);
if (top) {
border[0] = '┌';
border[len - 1] = '┐';
} else {
border[0] = '└';
border[len - 1] = '┘';
}
for (border[1 .. len - 1]) |*c| {
c.* = '─';
}
return border;
}
When I use the type of []u8 in border I get this error:
error: type 'u8' cannot represent integer value '9484'
border[0] = '┌';
When I use u16 I can no longer read the data as a string. And if I user {any} it just prints the character values. I believe this should be possible as I can print the desired characters like this,
try buf_wrtr.print("{s}", .{"┌┐─│└┘"});
Just fine. I am not sure how to save that character in a variable though.
I also tried using
border[0] = '\xe2\x94\x8c';
But that has a syntax error: expected expression, found 'invalid bytes' (expected_expr)