import std.io
import std.typeset {
BreakCluster, BreakPolicy, BreakMode, KinsokuRules, BreakOpportunity, Paragraph, Item,
Box, Penalty, BreakRule, DistanceGrid, CostModel, LineGeometry, JustificationPolicy,
JustificationMode, KnuthPlassPolicy, ParagraphPlan, PlanLine, classifyBreaks,
breakParagraph,
}
let sentence = "문단 전체를 보고 줄을 나누면 마지막 줄이 짧게 남지 않고 줄마다 길이가 고르게 됩니다."
let clusters = sentence.scalars().map(cluster)
let result = classifyBreaks(clusters, koreanRules(clusters))
.flatMap((breaks: Array<BreakOpportunity>) => breakParagraph(paragraph(clusters, breaks)))
match result {
case Ok(plans) => {
io.writeLine("Whole paragraph\n{linesOf(clusters, plans.optimized)}\n")
io.writeLine("Line by line\n{linesOf(clusters, plans.greedy)}")
}
case Err(error) => io.writeLine("{error}")
}