2020-06-18 23:54:48 +03:00
|
|
|
package structs
|
|
|
|
|
2020-07-04 00:28:56 +03:00
|
|
|
type Mediatype string
|
|
|
|
|
|
|
|
const (
|
|
|
|
TextGemini Mediatype = "text/gemini"
|
|
|
|
TextPlain Mediatype = "text/plain"
|
2020-07-11 00:45:14 +03:00
|
|
|
TextAnsi Mediatype = "text/x-ansi"
|
2020-07-04 00:28:56 +03:00
|
|
|
)
|
|
|
|
|
2020-07-08 04:13:45 +03: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-11 02:16:13 +03:00
|
|
|
ModeSearch // When a keyword is being searched in a page - TODO: NOT USED YET
|
2020-07-08 04:13:45 +03:00
|
|
|
)
|
|
|
|
|
2020-06-18 23:54:48 +03:00
|
|
|
// Page is for storing UTF-8 text/gemini pages, as well as text/plain pages.
|
|
|
|
type Page struct {
|
2020-07-08 04:13:45 +03:00
|
|
|
Url string
|
|
|
|
Mediatype Mediatype
|
|
|
|
Raw string // The raw response, as received over the network
|
2020-07-28 23:58:32 +03:00
|
|
|
Content string // The processed content, NOT raw. Uses cview color tags. All link/link texts must have region tags. It will also have a left margin.
|
2020-07-08 04:13:45 +03:00
|
|
|
Links []string // URLs, for each region in the content.
|
|
|
|
Row int // Scroll position
|
|
|
|
Column int // ditto
|
|
|
|
Width int // The width of the terminal at the time when the Content was set. This is to know when reformatting should happen.
|
|
|
|
Selected string // The current text or link selected
|
|
|
|
SelectedID string // The cview region ID for the selected text/link
|
|
|
|
Mode PageMode
|
2020-08-05 20:31:59 +03:00
|
|
|
Favicon string
|
2020-06-18 23:54:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Size returns an approx. size of a Page in bytes.
|
|
|
|
func (p *Page) Size() int {
|
2020-07-11 02:16:13 +03:00
|
|
|
n := len(p.Raw) + len(p.Content) + len(p.Url) + len(p.Selected) + len(p.SelectedID)
|
2020-06-18 23:54:48 +03:00
|
|
|
for i := range p.Links {
|
2020-07-11 02:16:13 +03:00
|
|
|
n += len(p.Links[i])
|
2020-06-18 23:54:48 +03:00
|
|
|
}
|
2020-07-11 02:16:13 +03:00
|
|
|
return n
|
2020-06-18 23:54:48 +03:00
|
|
|
}
|