diff --git a/src/View.roc b/src/View.roc index 098ed8e..8f7e519 100644 --- a/src/View.roc +++ b/src/View.roc @@ -75,6 +75,33 @@ buildControlPromptStr = \actions, promptsDict -> |> List.dropIf (\str -> Str.isEmpty str) |> Str.joinWith " | " +## Render a multi-line text with word wrapping +renderMultiLineText : List Str, { startCol: I32, startRow: I32, maxCol: I32, wrapCol: I32, wordDelim ? Str, fg ? Core.Color } -> List Core.DrawFn +renderMultiLineText = \words, { startCol, startRow, maxCol, wrapCol, wordDelim ? " ", fg ? Standard White } -> + firstLineWidth = maxCol - startCol + consecutiveWidths = maxCol - wrapCol + delims = List.repeat wordDelim (List.len words - 1) |> List.append "" + wordsWithDelims = List.map2 words delims \word, delim -> Str.concat word delim + lineList = + List.walk wordsWithDelims [] \lines, word -> + when lines is + [line] -> + if Num.toI32 (Str.countUtf8Bytes line + Str.countUtf8Bytes word) <= firstLineWidth then + [Str.concat line word] + else + [line, word] + [.. as prevLines, line] -> + if Num.toI32 (Str.countUtf8Bytes line + Str.countUtf8Bytes word) <= consecutiveWidths then + List.concat prevLines [Str.concat line word] + else + List.concat prevLines [line, word] + [] -> [word] + List.mapWithIndex lineList \line, idx -> + if idx == 0 then + Core.drawText line { r: startRow, c: startCol, fg } + else + Core.drawText line { r: startRow + (Num.toI32 idx), c: wrapCol, fg } + ## Generate the list of functions to draw the platform select page. renderPlatformSelect : Model -> List Core.DrawFn renderPlatformSelect = \model -> @@ -169,8 +196,15 @@ renderConfirmation = \model -> Core.drawText "Platform:" { r: model.menuRow + 1, c: 2, fg: Standard Magenta }, Core.drawText config.platform { r: model.menuRow + 1, c: 12, fg: Standard White }, Core.drawText "Packages:" { r: model.menuRow + 2, c: 2, fg: Standard Magenta }, - Core.drawText (config.packages |> Str.joinWith ", ") { r: model.menuRow + 2, c: 12, fg: Standard White }, ], + renderMultiLineText config.packages { + startCol: 12, + startRow: (model.menuRow + 2), + maxCol: (model.screen.width - 1), + wrapCol: 2, + wordDelim: ", ", + fg: (Standard White) + }, ] _ -> []