use wordrows; use viewportion; fn nuthatch_finite(values: vector) -> bool { let mut i = 0; while i < len(values) { let value = at(values, i); if !(value - value == 0.0) { return false; } i += 1; } true } fn nuthatch_counts(values: vector) -> bool { let mut i = 0; while i < len(values) { let value = at(values, i); if !(value >= 0.0 && value <= 9007199254740991.0 && value % 1.0 == 0.0) { return false; } i += 1; } true } fn nuthatch_compute(widths: vector, columns: f64, start: f64, height: f64) -> vector { let flow = wordrows_measure(widths, columns); if len(flow) == 0 { return []; } let view = viewportion_slice(at(flow, 0), start, height); if len(view) == 0 { return []; } [at(flow, 0), at(view, 0), at(view, 1), at(flow, 1)] } // Wrap a message and preserve a valid scroll position after resizing a terminal. // Returns [wrapped line count, first visible line, exclusive end, last line width]. The host supplies display-cell widths for its font. pub fn nuthatch_layout(widths: vector, columns: f64, start: f64, height: f64) -> vector { if !nuthatch_counts(widths) { return []; } if !(columns >= 1.0 && columns <= 9007199254740991.0 && columns % 1.0 == 0.0) { return []; } if !(start >= 0.0 && start <= 9007199254740991.0 && start % 1.0 == 0.0) { return []; } if !(height >= 1.0 && height <= 9007199254740991.0 && height % 1.0 == 0.0) { return []; } let result = nuthatch_compute(widths, columns, start, height); if !nuthatch_finite(result) { return []; } result }