~reesmichael1/roman

3784df6eb213fc0ccd683ed396d42645e1bca718 — Michael Rees 5 months ago 71c0459
Fix crash when displaying very long link in post
1 files changed, 6 insertions(+), 2 deletions(-)

M src/romanpkg/posts.nim
M src/romanpkg/posts.nim => src/romanpkg/posts.nim +6 -2
@@ 74,6 74,7 @@ proc displayLinks(p: Post) {.raises: [RomanError].} =

  proc shortenURL(url: string, text: string): string =
    # 3 for ' ()', 4 for '>   <'

    let availableWidth = terminalWidth() - text.runeLen() - 7
    if url.runeLen() > availableWidth:
      # Remove three more characters for the ellipsis


@@ 84,8 85,11 @@ proc displayLinks(p: Post) {.raises: [RomanError].} =
    var displayNames = initTable[PostLink, string]()
    for link in links:
      if link.text.len > 0:
        displayNames[link] = link.text & " (" & shortenURL(link.url,
            link.text) & ")"
        let text = if link.text.len > (terminalWidth() div 2):
          link.text[0..<(terminalWidth() div 2)]
        else:
          link.text
        displayNames[link] = text & " (" & shortenURL(link.url, text) & ")"
      else:
        displayNames[link] = shortenURL(link.url, "")
    # Move down one line in case we're at the END line already