2021-02-27 23:55:26 -05:00
|
|
|
//nolint:lll
|
2020-06-18 16:54:48 -04:00
|
|
|
package structs
|
|
|
|
|
2020-12-20 15:54:47 -05:00
|
|
|
import "time"
|
|
|
|
|
2020-07-03 17:28:56 -04:00
|
|
|
type Mediatype string
|
|
|
|
|
|
|
|
const (
|
|
|
|
TextGemini Mediatype = "text/gemini"
|
|
|
|
TextPlain Mediatype = "text/plain"
|
2020-07-10 17:45:14 -04:00
|
|
|
TextAnsi Mediatype = "text/x-ansi"
|
2020-07-03 17:28:56 -04:00
|
|
|
)
|
|
|
|
|
2020-07-07 21:13:45 -04:00
|
|
|
type PageMode int
|
|
|
|
|
|
|
|
const (
|
|
|
|
ModeOff PageMode = iota // Regular mode
|
|
|
|
ModeLinkSelect // When the enter key is pressed, allow for tab-based link navigation
|
2020-07-10 19:16:13 -04:00
|
|
|
ModeSearch // When a keyword is being searched in a page - TODO: NOT USED YET
|
2020-07-07 21:13:45 -04:00
|
|
|
)
|
|
|
|
|
2020-06-18 16:54:48 -04:00
|
|
|
// Page is for storing UTF-8 text/gemini pages, as well as text/plain pages.
|
|
|
|
type Page struct {
|
2020-11-17 20:56:15 -05:00
|
|
|
URL string
|
|
|
|
Mediatype Mediatype // Used for rendering purposes, generalized
|
|
|
|
RawMediatype string // The actual mediatype sent by the server
|
2021-05-14 21:00:44 -04:00
|
|
|
Raw []byte // The raw response, as received over the network. Never modify it, only set and read.
|
2020-11-17 20:56:15 -05:00
|
|
|
Links []string // URLs, for each region in the content.
|
2021-02-27 18:17:49 -05:00
|
|
|
Row int // Vertical scroll position
|
|
|
|
Column int // Horizontal scroll position - does not map exactly to a cview.TextView because it includes left margin size changes, see #197
|
|
|
|
TermWidth int // The terminal width when the Content was set, to know when reformatting should happen.
|
2020-11-17 20:56:15 -05:00
|
|
|
Selected string // The current text or link selected
|
|
|
|
SelectedID string // The cview region ID for the selected text/link
|
|
|
|
Mode PageMode
|
2020-12-20 15:54:47 -05:00
|
|
|
MadeAt time.Time // When the page was made. Zero value indicates it should stay in cache forever.
|
2020-06-18 16:54:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Size returns an approx. size of a Page in bytes.
|
|
|
|
func (p *Page) Size() int {
|
2021-05-14 21:00:44 -04:00
|
|
|
n := len(p.Raw) + len(p.URL) + len(p.Selected) + len(p.SelectedID)
|
2020-06-18 16:54:48 -04:00
|
|
|
for i := range p.Links {
|
2020-07-10 19:16:13 -04:00
|
|
|
n += len(p.Links[i])
|
2020-06-18 16:54:48 -04:00
|
|
|
}
|
2020-07-10 19:16:13 -04:00
|
|
|
return n
|
2020-06-18 16:54:48 -04:00
|
|
|
}
|