render

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2024 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package render handles output size constraints and paginated rendering of contents and menus using templates.

Index

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 struct {
	// contains filtered or unexported fields
}

Menu renders menus.

May be included in a Page object to render menus for pages.

func NewMenu

func NewMenu() *Menu

NewMenu creates a new Menu with an explicit page count.

func (m *Menu) GetBrowseConfig() BrowseConfig

GetBrowseConfig returns a copy of the current state of the browse configuration.

func (m Menu) IsSink() bool
func (m *Menu) Put(selector string, title string) error

Put adds a menu option to the menu rendering.

func (m *Menu) Render(ctx context.Context, idx uint16) (string, error)

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 (m *Menu) Reset()

Reset clears all current state from the menu object, making it ready for re-use in a new render.

func (m *Menu) Sizes(ctx context.Context) ([4]uint32, error)

Sizes returns the size limitations for each part of the render, as a four-element array:

  1. mainSize
  2. prevsize
  3. nextsize
  4. nextsize + prevsize
func (m Menu) String() string

String implements the String interface.

It returns debug representation of menu.

func (m *Menu) WithBrowseConfig(cfg BrowseConfig) *Menu

WithBrowseConfig defines the criteria for page browsing.

func (m *Menu) WithDispose() *Menu

WithDispose is a chainable function that preserves the menu after render is complete.

It is used for multi-page content.

func (m *Menu) WithPageCount(pageCount uint16) *Menu

WithPageCount is a chainable function that defines the number of allowed pages for browsing.

func (m *Menu) WithPages() *Menu

WithPages is a chainable function which activates pagination in the menu.

It is equivalent to WithPageCount(1)

func (m *Menu) WithResource(rs resource.Resource) *Menu
func (m *Menu) WithSink() *Menu

WithSink is a chainable function that informs the menu that a content sink exists in the render.

A content sink receives priority to consume all remaining space after all non-sink items have been rendered.

type Page

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

Page executes output rendering into pages constrained by size.

func NewPage

func NewPage(cache cache.Memory, rs resource.Resource) *Page

NewPage creates a new Page object.

func (*Page) Error

func (pg *Page) Error() string

Error implements the Error interface.

func (*Page) Map

func (pg *Page) Map(key string) error

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

func (pg *Page) Render(ctx context.Context, sym string, idx uint16) (string, error)

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

func (pg *Page) Sizes() (map[string]uint16, error)

Sizes returned the actual used bytes by each mapped symbol.

func (*Page) Usage

func (pg *Page) Usage() (uint32, uint32, error)

Usage returns size used by values and menu, and remaining size available

func (*Page) Val

func (pg *Page) Val(key string) (string, error)

Val gets the mapped content for the given symbol.

Fails if key is not mapped.

func (*Page) WithError

func (pg *Page) WithError(err error) *Page

WithError adds an error to prepend to the page output.

func (*Page) WithMenu

func (pg *Page) WithMenu(menu *Menu) *Page

WithMenu sets a menu renderer for the page.

func (*Page) WithSizer

func (pg *Page) WithSizer(sizer *Sizer) *Page

WithSizer sets a size constraints definition 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

func NewSizer(outputSize uint32) *Sizer

NewSizer creates a new Sizer object with the given output size constraint.

func (*Sizer) AddCursor

func (szr *Sizer) AddCursor(c uint32)

AddCursor adds a pagination cursor for the paged sink content.

func (*Sizer) Check

func (szr *Sizer) Check(s string) (uint32, bool)

Check audits whether the rendered string is within the output size constraint of the sizer.

func (*Sizer) GetAt

func (szr *Sizer) GetAt(values map[string]string, idx uint16) (map[string]string, error)

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

func (szr *Sizer) Set(key string, size uint16) error

Set adds a content symbol in the state it will be used by the renderer.

func (*Sizer) Size

func (szr *Sizer) Size(s string) (uint16, error)

Size gives the byte size of content for a single symbol.

Fails if the symbol has not been registered using Set

func (*Sizer) String

func (szr *Sizer) String() string

String implements the String interface.

It outputs a representation of the Sizer fit for debug output.

Jump to

Keyboard shortcuts

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