Documentation ¶
Overview ¶
Package render handles output size constraints and paginated rendering of contents and menus using templates.
Index ¶
- type BrowseConfig
- type BrowseError
- type Menu
- func (m *Menu) GetBrowseConfig() BrowseConfig
- func (m Menu) IsSink() bool
- func (m *Menu) Put(selector string, title string) error
- func (m *Menu) Render(ctx context.Context, idx uint16) (string, error)
- func (m *Menu) Reset()
- func (m *Menu) Sizes(ctx context.Context) ([4]uint32, error)
- func (m Menu) String() string
- func (m *Menu) WithBrowseConfig(cfg BrowseConfig) *Menu
- func (m *Menu) WithDispose() *Menu
- func (m *Menu) WithPageCount(pageCount uint16) *Menu
- func (m *Menu) WithPages() *Menu
- func (m *Menu) WithResource(rs resource.Resource) *Menu
- func (m *Menu) WithSink() *Menu
- type Page
- func (pg *Page) Error() string
- func (pg *Page) Map(key string) error
- func (pg *Page) Render(ctx context.Context, sym string, idx uint16) (string, error)
- func (pg *Page) RenderTemplate(ctx context.Context, sym string, values map[string]string, idx uint16) (string, error)
- func (pg *Page) Reset()
- func (pg *Page) Sizes() (map[string]uint16, error)
- func (pg *Page) Usage() (uint32, uint32, error)
- func (pg *Page) Val(key string) (string, error)
- func (pg *Page) WithError(err error) *Page
- func (pg *Page) WithMenu(menu *Menu) *Page
- func (pg *Page) WithSizer(sizer *Sizer) *Page
- type Sizer
- func (szr *Sizer) AddCursor(c uint32)
- func (szr *Sizer) Check(s string) (uint32, bool)
- func (szr *Sizer) GetAt(values map[string]string, idx uint16) (map[string]string, error)
- func (szr *Sizer) Reset()
- func (szr *Sizer) Set(key string, size uint16) error
- func (szr *Sizer) Size(s string) (uint16, error)
- func (szr *Sizer) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BrowseConfig ¶
type BrowseConfig struct { // Set if a consecutive page is available for lateral navigation. NextAvailable bool // Menu selector used to navigate to next page. NextSelector string // Menu title used to label selector for next page. NextTitle string // Set if a previous page is available for lateral navigation. PreviousAvailable bool // Menu selector used to navigate to previous page. PreviousSelector string // Menu title used to label selector for previous page. PreviousTitle string }
BrowseConfig defines the availability and display parameters for page browsing.
func DefaultBrowseConfig ¶
func DefaultBrowseConfig() BrowseConfig
Create a BrowseConfig with default values.
type BrowseError ¶
type BrowseError struct { // The lateral page index where the error occurred. Idx uint16 // The total number of lateral page indicies. PageCount uint16 }
BrowseError is raised when browsing outside the page range of a rendered node.
func (*BrowseError) Error ¶
func (err *BrowseError) Error() string
Error implements the Error interface.
type Menu ¶
type Menu struct {
// contains filtered or unexported fields
}
Menu renders menus.
May be included in a Page object to render menus for pages.
func (*Menu) GetBrowseConfig ¶
func (m *Menu) GetBrowseConfig() BrowseConfig
GetBrowseConfig returns a copy of the current state of the browse configuration.
func (*Menu) Put ¶
Put adds a menu option to the menu rendering.
func (*Menu) Render ¶
Render returns the full current state of the menu as a string.
After this has been executed, the state of the menu will be empty.
func (*Menu) Reset ¶
func (m *Menu) Reset()
Reset clears all current state from the menu object, making it ready for re-use in a new render.
func (*Menu) Sizes ¶
Sizes returns the size limitations for each part of the render, as a four-element array:
- mainSize
- prevsize
- nextsize
- nextsize + prevsize
func (Menu) String ¶
String implements the String interface.
It returns debug representation of menu.
func (*Menu) WithBrowseConfig ¶
func (m *Menu) WithBrowseConfig(cfg BrowseConfig) *Menu
WithBrowseConfig defines the criteria for page browsing.
func (*Menu) WithDispose ¶
WithDispose is a chainable function that preserves the menu after render is complete.
It is used for multi-page content.
func (*Menu) WithPageCount ¶
WithPageCount is a chainable function that defines the number of allowed pages for browsing.
func (*Menu) WithPages ¶
WithPages is a chainable function which activates pagination in the menu.
It is equivalent to WithPageCount(1)
type Page ¶
type Page struct {
// contains filtered or unexported fields
}
Page executes output rendering into pages constrained by size.
func NewPage ¶
NewPage creates a new Page object.
func (*Page) Map ¶
Map marks the given key for retrieval.
After this, Val() will return the value for the key, and Size() will include the value size and limitations in its calculations.
Only one symbol with no size limitation may be mapped at the current level.
func (*Page) Render ¶
Render renders the current mapped content and menu state against the template associated with the symbol.
func (*Page) RenderTemplate ¶
func (pg *Page) RenderTemplate(ctx context.Context, sym string, values map[string]string, idx uint16) (string, error)
RenderTemplate is an adapter to implement the builtin golang text template renderer as resource.RenderTemplate.
func (*Page) Reset ¶
func (pg *Page) Reset()
Reset prepared the Page object for re-use.
It clears mappings and removes the sink definition.
func (*Page) Sizes ¶
Sizes returned the actual used bytes by each mapped symbol.
func (*Page) Usage ¶
Usage returns size used by values and menu, and remaining size available
func (*Page) WithError ¶
WithError adds an error to prepend to the page output.
func (*Page) WithMenu ¶
WithMenu sets a menu renderer for the page.
type Sizer ¶
type Sizer struct {
// contains filtered or unexported fields
}
Sizer splits dynamic contents into individual segments for browseable pages.
func NewSizer ¶
NewSizer creates a new Sizer object with the given output size constraint.
func (*Sizer) AddCursor ¶
AddCursor adds a pagination cursor for the paged sink content.
func (*Sizer) Check ¶
Check audits whether the rendered string is within the output size constraint of the sizer.
func (*Sizer) GetAt ¶
GetAt the paged symbols for the current page index.
Fails if index requested is out of range.
func (*Sizer) Reset ¶
func (szr *Sizer) Reset()
Reset flushes all size measurements, making the sizer available for reuse.
func (*Sizer) Set ¶
Set adds a content symbol in the state it will be used by the renderer.
func (*Sizer) Size ¶
Size gives the byte size of content for a single symbol.
Fails if the symbol has not been registered using Set