mirror of
https://github.com/makew0rld/amfora.git
synced 2024-11-12 19:14:48 +03:00
543d15abfc
Squashed commit of the following: commit72f36afc9e
Author: makeworld <colecmac@protonmail.com> Date: Tue Jul 7 16:15:45 2020 -0400 🚧 Scroll is applied correctly when navigating around commit4b8982723f
Author: makeworld <colecmac@protonmail.com> Date: Tue Jul 7 15:34:45 2020 -0400 🚧 Fix bottomBar code Make sure it always resets to a selected link if one was selected before commitbe09ffcf91
Author: makeworld <colecmac@protonmail.com> Date: Mon Jul 6 20:30:54 2020 -0400 🚧 Switch to using tab pointers instead of ints Almost finished overall work. commitef8ab3da39
Author: makeworld <colecmac@protonmail.com> Date: Mon Jul 6 12:10:50 2020 -0400 🚧 Fixed some bugs, major ones remain commitd3d47a344d
Author: makeworld <colecmac@protonmail.com> Date: Sat Jul 4 20:58:46 2020 -0400 🚧 Everything uses tab struct, no compile errors, untested commit44bf54c12f
Author: makeworld <colecmac@protonmail.com> Date: Sat Jul 4 13:24:49 2020 -0400 🚧 Initial work on tab struct
40 lines
1.3 KiB
Go
40 lines
1.3 KiB
Go
package structs
|
|
|
|
type Mediatype string
|
|
|
|
const (
|
|
TextGemini Mediatype = "text/gemini"
|
|
TextPlain Mediatype = "text/plain"
|
|
)
|
|
|
|
type PageMode int
|
|
|
|
const (
|
|
ModeOff PageMode = iota // Regular mode
|
|
ModeLinkSelect // When the enter key is pressed, allow for tab-based link navigation
|
|
)
|
|
|
|
// Page is for storing UTF-8 text/gemini pages, as well as text/plain pages.
|
|
type Page struct {
|
|
Url string
|
|
Mediatype Mediatype
|
|
Raw string // The raw response, as received over the network
|
|
Content string // The processed content, NOT raw. Uses cview colour tags. All link/link texts must have region tags. It will also have a left margin.
|
|
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
|
|
}
|
|
|
|
// Size returns an approx. size of a Page in bytes.
|
|
func (p *Page) Size() int {
|
|
b := len(p.Raw) + len(p.Content) + len(p.Url) + len(p.Selected) + len(p.SelectedID)
|
|
for i := range p.Links {
|
|
b += len(p.Links[i])
|
|
}
|
|
return b
|
|
}
|