saturn

package
v0.0.0-...-c5bc608 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultFormater = HtmlFormater{
	ColorProfile: termenv.ColorProfile(),
}
View Source
var DefaultStyle = lipgloss.NewStyle()

Functions

func NewMainModel

func NewMainModel(book *epub.Epub, db *db.DB, renderer *Renderer) tea.Model

func NewTextModel

func NewTextModel(book *epub.Epub, db *db.DB, renderer *Renderer,
	currentId epub.ManifestId, prev tea.Model, width, height int) tea.Model

func Style

func Style(tag string) lipgloss.Style

Types

type BlockMessage

type BlockMessage struct {
	ID  epub.ManifestId
	Msg string
}

type Buffer

type Buffer struct {
	Lines []Line

	// The position of each block of the spine in the Lines
	BlockPos map[epub.ManifestId]BufferLineIndex
	// contains filtered or unexported fields
}

Buffer is the ebook one to one mapping

func NewBuffer

func NewBuffer() *Buffer

func (*Buffer) Accept

func (b *Buffer) Accept(visitor IVisualVisiter)

func (*Buffer) GetBaseVisualLine

func (b *Buffer) GetBaseVisualLine(vy VisualLineIndex) VisualLineIndex

GetBaseVisualLine returns the y position of the first line of the given visual index(one buffer line maybe rendered to multiple screen lines)

func (*Buffer) GetBufferLineNumById

func (b *Buffer) GetBufferLineNumById(id epub.ManifestId) BufferLineIndex

func (*Buffer) GetBufferLineNumByVisual

func (b *Buffer) GetBufferLineNumByVisual(visualLineNum VisualLineIndex) BufferLineIndex

func (*Buffer) GetBufferX

func (b *Buffer) GetBufferX(bufferLineNum BufferLineIndex, vy VisualLineIndex, vx VisualIndex) RuneIndex

func (*Buffer) GetVisualLineNumById

func (b *Buffer) GetVisualLineNumById(id epub.ManifestId) VisualLineIndex

func (*Buffer) LinesNum

func (b *Buffer) LinesNum() int

func (*Buffer) VisualLines

func (b *Buffer) VisualLines(start, end int) []string

VisualLines return a portion of visual lines in a range

func (*Buffer) VisualLinesNum

func (b *Buffer) VisualLinesNum() int

VisualLinesNum returns total lines number after rendition

type BufferLineIndex

type BufferLineIndex int

BufferLineIndex is the index of the line in the buffer

type ByteIndex

type ByteIndex int

ByteIndex returns the index of the byte in the given string

type HtmlFormater

type HtmlFormater struct {
	ColorProfile termenv.Profile
	Styles       []*cssparser.Rule
}

func (HtmlFormater) Header

func (f HtmlFormater) Header(c string) string

func (HtmlFormater) I

func (f HtmlFormater) I(c string) string

func (HtmlFormater) P

func (f HtmlFormater) P(c string, attributes []html.Attribute) string

func (HtmlFormater) PostProcess

func (f HtmlFormater) PostProcess(c string) string

func (HtmlFormater) Title

func (f HtmlFormater) Title(c string) string

type IHtmlFormater

type IHtmlFormater interface {
	Title(string) string
	I(string) string
	P(string, []html.Attribute) string
	Header(string) string
	PostProcess(string) string
}

type IVisualVisiter

type IVisualVisiter interface {
	VisitBufferPrev(*Buffer) bool
	VisitBufferPost(*Buffer) bool
	VisitLinePrev(*VisualLine) bool
	VisitLinePost(*VisualLine) bool
	VisitRune(*VisualRune) bool
}

type Line

type Line struct {
	Content  string
	Segments []Segment
	Style    string
}

Line contains the text parsed from the ebooks together with it's styles specified. The Content field is the original text without rendering

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

func NewParser

func NewParser(book *epub.Epub) *Parser

func (*Parser) GetBuffer

func (p *Parser) GetBuffer() *Buffer

func (*Parser) Parse

func (p *Parser) Parse() error

Parse iterates over the spine and parses each HTML file

type Pos

type Pos struct {
	X, Y int
}
var InvalidPos Pos = Pos{-1, -1}

type Renderer

type Renderer struct {
	// contains filtered or unexported fields
}

func NewRender

func NewRender(book *epub.Epub, buffer *Buffer) *Renderer

func (*Renderer) ClearCursorStyles

func (r *Renderer) ClearCursorStyles(vy VisualLineIndex)

func (*Renderer) GetBuffer

func (r *Renderer) GetBuffer() *Buffer

func (*Renderer) GetBufferX

func (r *Renderer) GetBufferX(line string, vy VisualLineIndex, vx VisualIndex) RuneIndex

func (*Renderer) GetVisualLineNumById

func (r *Renderer) GetVisualLineNumById(id epub.ManifestId) VisualLineIndex

func (*Renderer) MarkInline

func (r *Renderer) MarkInline(vy VisualLineIndex, vxs, vxe VisualIndex) string

func (*Renderer) MarkLine

func (r *Renderer) MarkLine(vy VisualLineIndex) string

func (*Renderer) MarkPosition

func (r *Renderer) MarkPosition(vy VisualLineIndex, vx VisualIndex) string

func (*Renderer) Render

func (r *Renderer) Render(width int)

Render iterates over the buffer and renders each line to the screen.

func (*Renderer) RenderEmptyLinum

func (r *Renderer) RenderEmptyLinum() string

func (*Renderer) RenderLine

func (r *Renderer) RenderLine(linum BufferLineIndex) []VisualLine

func (*Renderer) RenderLinum

func (r *Renderer) RenderLinum(linum BufferLineIndex) string

type RuneIndex

type RuneIndex int

RuneIndex returns the index of the rune in the given string

type Segment

type Segment struct {
	Content string
	Style   string
	Pos     ByteIndex
}

Segment is to describe the style in a part of the string

type Visitor

type Visitor struct {
	Style   lipgloss.Style
	Content string
	Start   int
	End     int
}

func (*Visitor) VisitBufferPost

func (v *Visitor) VisitBufferPost(b *Buffer) bool

func (*Visitor) VisitBufferPrev

func (v *Visitor) VisitBufferPrev(b *Buffer) bool

func (*Visitor) VisitLinePost

func (v *Visitor) VisitLinePost(l *VisualLine) bool

func (*Visitor) VisitLinePrev

func (v *Visitor) VisitLinePrev(l *VisualLine) bool

func (*Visitor) VisitRune

func (v *Visitor) VisitRune(r *VisualRune) bool

type VisualIndex

type VisualIndex int

VisualIndex returns the visual index of the screen position

type VisualLine

type VisualLine struct {
	// index in the original buffer, some visual lines
	// may mapping to the same buffer line because of the
	// line wrapping.
	BufferLinum BufferLineIndex

	// rendered content
	Content string
	Runes   []VisualRune

	// rendered line number
	LineNum    string
	LinumStyle lipgloss.Style

	Dirty bool
}

func (*VisualLine) Accept

func (v *VisualLine) Accept(visitor IVisualVisiter)

func (*VisualLine) ClearLine

func (v *VisualLine) ClearLine()

func (*VisualLine) MarkInline

func (v *VisualLine) MarkInline(start, end VisualIndex) string

func (*VisualLine) MarkLine

func (v *VisualLine) MarkLine() string

func (*VisualLine) MarkPosition

func (v *VisualLine) MarkPosition(vx VisualIndex) string

func (*VisualLine) Render

func (v *VisualLine) Render() string

func (*VisualLine) Replace

func (v *VisualLine) Replace(content string)

type VisualLineIndex

type VisualLineIndex int

VisualLineIndex is the index of the line in the rendered buffer

type VisualPos

type VisualPos struct {
	X, Y int
}

type VisualRune

type VisualRune struct {
	C     rune
	Style lipgloss.Style
	VC    string
	Dirty bool
}

func (*VisualRune) Accept

func (r *VisualRune) Accept(visitor IVisualVisiter)

Jump to

Keyboard shortcuts

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