reader

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package reader provides core RSVP (Rapid Serial Visual Presentation) speed reading logic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractText added in v1.1.0

func ExtractText(filename string) (string, error)

ExtractText extracts text from a file, using a registered format or plain text fallback.

func ExtractTextFromEPUB added in v1.1.0

func ExtractTextFromEPUB(filename string) (string, error)

ExtractTextFromEPUB extracts all text content from an EPUB file.

func FindSentenceStarts

func FindSentenceStarts(words []string) []int

FindSentenceStarts returns indices of words that start sentences.

func GetORPPosition

func GetORPPosition(word string) int

GetORPPosition returns the Optimal Recognition Point index for a word. This is the character (rune) position where the eye should focus for fastest recognition.

func ParseText

func ParseText(text string) []string

ParseText splits text into words.

func Register added in v1.1.0

func Register(f Format)

Register adds a format reader to the registry.

func SupportedFormats added in v1.1.0

func SupportedFormats() []string

SupportedFormats returns registered format names with their extensions.

Types

type Chapter added in v1.1.0

type Chapter struct {
	Title     string
	WordStart int
	WordEnd   int
}

Chapter represents extracted chapter content with boundaries

type ChapterExtractor added in v1.1.0

type ChapterExtractor interface {
	ExtractChapters(filename string) ([]Chapter, []string, error)
}

ChapterExtractor is an optional interface for chapter-aware extraction

type EPUBFormat added in v1.1.0

type EPUBFormat struct{}

EPUBFormat implements Format for EPUB files.

func (*EPUBFormat) Extensions added in v1.1.0

func (f *EPUBFormat) Extensions() []string

func (*EPUBFormat) Extract added in v1.1.0

func (f *EPUBFormat) Extract(filename string) (string, error)

func (*EPUBFormat) ExtractChapters added in v1.1.0

func (f *EPUBFormat) ExtractChapters(filename string) ([]Chapter, []string, error)

ExtractChapters extracts text with chapter boundaries preserved.

func (*EPUBFormat) Name added in v1.1.0

func (f *EPUBFormat) Name() string

func (*EPUBFormat) TOC added in v1.1.0

func (f *EPUBFormat) TOC(filename string) ([]TOCEntry, error)

TOC extracts the table of contents from an EPUB file.

type Format added in v1.1.0

type Format interface {
	Name() string
	Extensions() []string
	Extract(filename string) (string, error)
}

Format defines a file format reader for extracting text.

type MarkdownFormat added in v1.1.0

type MarkdownFormat struct{}

MarkdownFormat implements Format for Markdown files.

func (*MarkdownFormat) Extensions added in v1.1.0

func (f *MarkdownFormat) Extensions() []string

func (*MarkdownFormat) Extract added in v1.1.0

func (f *MarkdownFormat) Extract(filename string) (string, error)

func (*MarkdownFormat) ExtractChapters added in v1.1.0

func (f *MarkdownFormat) ExtractChapters(filename string) ([]Chapter, []string, error)

ExtractChapters extracts text with chapter boundaries from headers.

func (*MarkdownFormat) Name added in v1.1.0

func (f *MarkdownFormat) Name() string

func (*MarkdownFormat) TOC added in v1.1.0

func (f *MarkdownFormat) TOC(filename string) ([]TOCEntry, error)

TOC extracts the table of contents from a Markdown file by parsing headers.

type Reader

type Reader struct {
	Words          []string
	SentenceStarts []int
	CurrentIndex   int
	WPM            int
	Paused         bool
	LastArrowPress time.Time

	// Chapter support
	Chapters       []Chapter
	TOC            []TOCEntry
	CurrentChapter int
}

Reader holds the state for an RSVP speed reading session.

func NewReader

func NewReader(text string, wpm int) *Reader

NewReader creates a new Reader from the given text and words-per-minute setting.

func (*Reader) Advance

func (r *Reader) Advance() bool

Advance moves to the next word. Returns true if there are more words.

func (*Reader) AtEnd

func (r *Reader) AtEnd() bool

AtEnd returns true if the reader is at the last word.

func (*Reader) CurrentChapterTitle added in v1.1.0

func (r *Reader) CurrentChapterTitle() string

CurrentChapterTitle returns the title of the current chapter.

func (*Reader) CurrentWord

func (r *Reader) CurrentWord() string

CurrentWord returns the word at the current index.

func (*Reader) GetDelay

func (r *Reader) GetDelay() time.Duration

GetDelay returns the duration to display each word based on WPM.

func (*Reader) JumpToChapter added in v1.1.0

func (r *Reader) JumpToChapter(wordIndex int)

JumpToChapter jumps to the specified word index and updates current chapter.

func (*Reader) JumpToNextSentence

func (r *Reader) JumpToNextSentence()

JumpToNextSentence moves to the start of the next sentence.

func (*Reader) JumpToPrevSentence

func (r *Reader) JumpToPrevSentence()

JumpToPrevSentence moves to the start of the previous sentence.

func (*Reader) Progress

func (r *Reader) Progress() (current, total int)

Progress returns the current position and total word count.

func (*Reader) SetChapters added in v1.1.0

func (r *Reader) SetChapters(chapters []Chapter, toc []TOCEntry)

SetChapters sets the chapter data and updates the current chapter.

type TOCEntry added in v1.1.0

type TOCEntry struct {
	Title     string
	Preview   string
	WordIndex int
	Level     int
}

TOCEntry represents a single entry in a table of contents

type TOCProvider added in v1.1.0

type TOCProvider interface {
	TOC(filename string) ([]TOCEntry, error)
}

TOCProvider is an optional interface for formats that support TOC extraction

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL