kojote/cmd/linebreak/main.ha
Drew DeVault 9c73c17238 Implement Unicode line breaking algorithm
Signed-off-by: Drew DeVault <sir@cmpwn.com>
2024-04-17 11:13:25 +02:00

33 lines
637 B
Hare

use fmt;
use os;
use unicode;
export fn main() void = {
const input = os::args[1];
fmt::println(input)!;
let ix = 0u;
const lb = unicode::new_line_breaker(input);
for (const (pos, mand) => unicode::next_line_break(&lb)) {
for (ix < pos; ix += 1) {
fmt::print(' ')!;
};
ix += 1;
if (mand) {
fmt::println('|')!;
} else {
fmt::print('^')!;
};
};
fmt::println()!;
fmt::println()!;
fmt::println("Line break opportunities:")!;
const lb = unicode::new_line_breaker(input);
for (const (pos, mand) => unicode::next_line_break(&lb)) {
fmt::printfln("- {} {}", pos, if (mand) "(mandatory)" else "")!;
};
};