Skip to content
This repository has been archived by the owner on Jun 7, 2022. It is now read-only.

Commit

Permalink
rewind saved position to 0 when end of article is reached
Browse files Browse the repository at this point in the history
  • Loading branch information
skuzzymiglet committed Dec 7, 2020
1 parent 563d0b7 commit a658c28
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 6 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ func main() {
end, err := speedread(content, conf, title)
if savePos {
log.Println("Saving position...")
err = writePos(contentHash, end)
if end == len(content)-1 {
log.Println("reached end, saving position as 0")
err = writePos(contentHash, 0)
} else {
err = writePos(contentHash, end)
}
if err != nil {
log.Fatalln("Error saving position:", err)
}
Expand Down
5 changes: 4 additions & 1 deletion speedread.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type config struct { // TODO: add command line flags for every value here
func speedread(content []string, config config, title string) (endPos int, err error) {
// TODO: pause at start and end. You often can't start reading instantly
// TODO: show "unfamiliar" words for longer
// TODO: / to search for text
// + Emojis
// + "Weird" characters (symbols)
// + Long words
Expand Down Expand Up @@ -66,7 +67,9 @@ func speedread(content []string, config config, title string) (endPos int, err e
if len(title) >= (w/2)-3 {
truncTitle = title[:(w/2)-3] + "..."
}
fmt.Fprintf(&tagline, "%s [%d wpm] (%d/%d) <", truncTitle, config.wpm, word, len(content)) // TODO: truncate title
fmt.Fprint(&tagline, truncTitle)
fmt.Fprintf(&tagline, "[%d wpm]", config.wpm)
fmt.Fprintf(&tagline, "(%d/%d) <", word, len(content))
taglineWidth := w - len(tagline.String()) - 1

for i := 0; i < int(read*float64(taglineWidth)); i++ {
Expand Down

0 comments on commit a658c28

Please sign in to comment.