~reesmichael1/roman

027978a6a87d081a4d6d2cab7cbd147c7b4aa378 — Michael Rees 2 days ago d4936b5 master
Add mark all as read command
M config/config => config/config +2 -1
@@ 8,7 8,8 @@ previous=p
quit=q
top=g
bottom=G
toggle-read=R
toggle-read=r
mark-all-read=R

[Posts]
# The maximum width for wrapping the posts

M src/romanpkg/config.nim => src/romanpkg/config.nim +2 -1
@@ 50,8 50,9 @@ proc mustLoadConfig*(): RomanConfig {.raises: [].} =
    result.goToTop = strToChar(dict, "Keyboard", "top")
    result.goToBottom = strToChar(dict, "Keyboard", "bottom")
    result.toggleRead = strToChar(dict, "Keyboard", "toggle-read")
    result.allRead = strToChar(dict, "Keyboard", "mark-all-read")
    result.postWidth = strToInt(dict, "Posts", "max-width")
    result.extractLInks = strToChar(dict, "Posts", "extract-links")
    result.extractLinks = strToChar(dict, "Posts", "extract-links")
  except:
    echo "error loading config file: " & getCurrentExceptionMsg()
    quit(1)

M src/romanpkg/feeds.nim => src/romanpkg/feeds.nim +23 -0
@@ 94,8 94,31 @@ proc displayFeed*(feed: var Feed) {.raises: [RomanError, InterruptError].} =
        titles[index][] = post.formatTitle()
        display[titles[index]] = titles[index]

    proc markAllRead(posts: seq[Post]): proc(index: int) {.closure, gcSafe.} =
      return proc(index: int) {.closure, gcSafe.} =
        stdout.write("Really mark all posts as read? [y/n] ")
        defer: stdout.eraseLine()
        while true:
          showCursor(stdout)
          let confirm = getch()
          hideCursor(stdout)
          if confirm == 'n':
            return
          elif confirm == 'y':
            break
          else:
            stdout.eraseLine()
            stdout.write("Invalid input, please enter 'y' or 'n': ")
            continue
        for ix in 0..posts.high:
          var post = posts[ix]
          post.markAsRead()
          titles[ix][] = post.formatTitle()
          display[titles[ix]] = titles[ix]

    var callbacks = newTable[char, proc(index: int) {.closure, gcSafe.}]()
    callbacks[conf.toggleRead] = toggleRead(feed.posts)
    callbacks[conf.allRead] = markAllRead(feed.posts)

    while true:
      display = initTable[ref string, ref string]()

M src/romanpkg/termask.nim => src/romanpkg/termask.nim +7 -0
@@ 236,7 236,14 @@ proc promptList*[T, U](question: string, args: openarray[T],
        raise newException(ValueError, "keyboard interrupt")
      elif callbacks != nil and c in callbacks:
        try:
          # Move the cursor down so any output printed by the callback
          # is shown on its own line
          # Callbacks are responsible for clearing their own output
          for _ in 1..currentArgs.len:
            cursorDown(stdout)
          callbacks[c](sliceIx * show + selectedIx)
          for _ in 1..currentArgs.len:
            cursorUp(stdout)
          break
        except Exception as e:
          echo "error in callback: " & e.msg

M src/romanpkg/types.nim => src/romanpkg/types.nim +1 -0
@@ 12,6 12,7 @@ type
    goToTop*: char
    goToBottom*: char
    toggleRead*: char
    allRead*: char
    postWidth*: int
    extractLinks*: char