Something went wrong. Try again.
A rewrite of the Plan 9 rc shell in Goose for UNIX-like systems and with structured CLI args
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849import grapheme;import platform;import terminal_text;
struct TextPosition { row: i64 = 0, column: i64 = 0 }enum TextMode { Literal, Styled }const DEFAULT_COLUMNS = 80;const EMOJI_VARIATION = 0xfe0f;const EMOJI_CELL_WIDTH = 2;fn cluster_width(s: u8[:]) -> i64 { var width = 0; var at = 0; while at < s.len { let code, end = rune(s, at); width = max(width, native_width(code)); if code == EMOJI_VARIATION || break_property(code) == BreakProperty.RI { width = max(width, EMOJI_CELL_WIDTH); } at = end; } return width;}fn advance_cells(position: TextPosition, cells: i64, columns: i64) -> TextPosition { var result = position; if cells == 0 { return result; } let count = min(cells, columns); if result.column + count > columns { result.row += 1; result.column = 0; } result.column += count; return result;}fn text_advance(position: TextPosition, s: u8[:], columns: i64, mode: TextMode = TextMode.Literal) -> TextPosition { var result = position; var at = 0; while at < s.len { if mode == TextMode.Styled { let end = sgr_end(s, at); if end > at { at = end; continue; } } let end = next_cluster(s, at); if s[at] == '\n' { result.row += 1; result.column = 0; } else { result = advance_cells(result, cluster_width(s[at..end]), columns); } at = end; } return result;}fn text_position(s: u8[:], columns: i64) -> TextPosition { var result = text_advance(TextPosition {}, s, columns); if result.column == columns { result.row += 1; result.column = 0; } return result;}