~reesmichael1/roman

f72a489a00e5342099a2e4e0082550b608cde00a — Michael Rees 8 months ago 85229b4
Return user to post selection after closing post
3 files changed, 22 insertions(+), 11 deletions(-)

M src/romanpkg/feeds.nim
M src/romanpkg/main.nim
M src/romanpkg/termask.nim
M src/romanpkg/feeds.nim => src/romanpkg/feeds.nim +10 -9
@@ 33,15 33,16 @@ proc displayFeed*(feed: var Feed) {.raises: [RomanError, InterruptError].} =
      display[p.title] = p.formatTitle()
      titles.add(p.title)

    let selectedTitle = promptList("Select Post", titles, show = 10,
        displayNames = display)
    if selectedTitle.isNone():
      raise newException(InterruptError, "no feed selected")
    let title = selectedTitle.unsafeGet()
    let post = filter(feed.posts, proc(p: Post): bool = p.title == title)[0]
    displayPost(post)
    post.markAsRead()
    feed.updateUnread()
    while true:
      let selectedTitle = promptList("Select Post", titles, show = 10,
          displayNames = display)
      if selectedTitle.isNone():
        raise newException(InterruptError, "no post selected")
      let title = selectedTitle.unsafeGet()
      let post = filter(feed.posts, proc(p: Post): bool = p.title == title)[0]
      displayPost(post)
      post.markAsRead()
      feed.updateUnread()
  except IOError as e:
    raise newException(RomanError, "could not write to the terminal: " & e.msg)
  except ValueError as e:

M src/romanpkg/main.nim => src/romanpkg/main.nim +6 -1
@@ 48,7 48,12 @@ proc runMainPath() {.raises: [RomanError, InterruptError].} =
      displayFeed(feed)
    else:
      feed = chooseFeed(feeds)
      displayFeed(feed)
      try:
        displayFeed(feed)
      except InterruptError:
        # These errors are coming from declining to select a post
        # Instead of exiting, return to the feed selection
        continue


proc main*(subscribeURL: string = "") {.raises: [].} =

M src/romanpkg/termask.nim => src/romanpkg/termask.nim +6 -1
@@ 116,7 116,9 @@ proc promptList*(question: string, args: openarray[string],

  var currentArgs = argSlices[sliceIx]
  for arg in currentArgs:
    eraseLine()
    stdout.write "\n"
    # cursorDown(stdout)

  cursorUp(stdout, currentArgs.len)
  hideCursor(stdout)


@@ 187,6 189,9 @@ proc promptList*(question: string, args: openarray[string],
        goBackPage(currentArgs, selectedIx, sliceIx, argSlices)
        break
      elif c == conf.quit:
        for _ in (selectedIx mod currentArgs.len)..currentArgs.len:
          cursorDown(stdout)
        echo "\n"
        return none(string)
      elif c == '\3':
        showCursor(stdout)


@@ 195,7 200,7 @@ proc promptList*(question: string, args: openarray[string],
        # on its own line
        for _ in (selectedIx mod currentArgs.len)..currentArgs.len:
          cursorDown(stdout)
        raise newException(ValueError, "no value selected")
        raise newException(ValueError, "keyboard interrupt")
      else: break

  for i in 0..<currentArgs.len: