~reesmichael1/roman

6eeb48a309c81e2f23685ee52b9b95159b42fb5a — Michael Rees 8 months ago 9603559
Use pager library to page posts when necessary
3 files changed, 19 insertions(+), 2 deletions(-)

M roman.nimble
M src/romanpkg/feeds.nim
M src/romanpkg/posts.nim
M roman.nimble => roman.nimble +1 -0
@@ 17,6 17,7 @@ requires "fab >= 0.4"
requires "feednim >= 0.2"
requires "nim >= 0.20.0"
requires "nimpy >= 0.1"
requires "https://git.sr.ht/~reesmichael1/nim-pager >= 0.1"




M src/romanpkg/feeds.nim => src/romanpkg/feeds.nim +1 -2
@@ 40,8 40,7 @@ proc displayFeed*(feed: var Feed) {.raises: [RomanError].} =
    let title = promptList("Select Post", titles, show = 10,
        displayNames = display)
    let post = filter(feed.posts, proc(p: Post): bool = p.title == title)[0]
    bold(post.title)
    echo post.content, "\n\n"
    displayPost(post)
    post.markAsRead()
    feed.updateUnread()
  except IOError as e:

M src/romanpkg/posts.nim => src/romanpkg/posts.nim +17 -0
@@ 1,6 1,10 @@
import os
import strutils
import terminal

import fab
import FeedNim / rss
import pager

import errors
import htmlextractor


@@ 38,6 42,19 @@ proc isPostRead(itemGUID: string): bool {.raises: [RomanError].} =
  return itemGUID in collectReadPosts()


proc displayPost*(p: Post) {.raises: [RomanError].} =
  try:
    # Height of the content plus a line and blank line for the title
    if p.content.countLines() + 2 > terminalHeight():
      page(p.title & "\n\n" & p.content)
    else:
      bold(p.title)
      echo p.content
  except IOError, ValueError:
    let msg = getCurrentExceptionMsg()
    raise newException(RomanError, "could not write to the terminal: " & msg)


proc postFromRSSItem*(item: RSSItem): Post {.raises: [
    RomanError].} =
  result.title = item.title