logos

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2024 License: UNKNOWN not legal advice Imports: 0 Imported by: 0

README

Logos Browser

Logos is a Gno object browser. The modern browser as well as the modern javascript ecosystem is from a security point of view, completely fucked. The entire paradigm of continuously updating browsers with incrementally added features is a security nightmare.

The Logos browser is based on a new model that is vastly simpler than HTML. The purpose of Logos is to become a fully expressive web API and implementation standard that does most of what HTML and the World Wide Web originally intended to do, but without becoming more complex than necessary.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsInBounds

func IsInBounds(x, y int, origin Coord, size Size) bool

Types

type AttrFlags

type AttrFlags uint32

NOTE: AttrFlags are merged with a simple or-assign op.

const (
	AttrFlagIsCursor   AttrFlags = 1 << iota // is current cursor
	AttrFlagIsSelected                       // is selected (among possibly others)
	AttrFlagIsOccluded                       // is hidden due to stack
	AttrFlagIsDirty                          // is dirty (not yet used)
)
const AttrFlagNone AttrFlags = 0

func (AttrFlags) GetAttrFlags

func (af AttrFlags) GetAttrFlags() AttrFlags

type Attrs

type Attrs struct {
	Parent Elem
	AttrFlags
	Other []KVPair
}

Attrs have side effects in the Logos system; for example, the lone cursor element (one with AttrFlagIsCursor set) is where most key events are sent to.

func (*Attrs) GetAttrs

func (tt *Attrs) GetAttrs() *Attrs

func (*Attrs) GetIsCursor

func (tt *Attrs) GetIsCursor() bool

func (*Attrs) GetIsDirty

func (tt *Attrs) GetIsDirty() bool

func (*Attrs) GetIsOccluded

func (tt *Attrs) GetIsOccluded() bool

func (*Attrs) GetParent

func (tt *Attrs) GetParent() Elem

func (*Attrs) Merge

func (tt *Attrs) Merge(ot *Attrs)

func (*Attrs) SetIsCursor

func (tt *Attrs) SetIsCursor(ic bool)

func (*Attrs) SetIsDirty

func (tt *Attrs) SetIsDirty(id bool)

func (*Attrs) SetIsOccluded

func (tt *Attrs) SetIsOccluded(ic bool)

func (*Attrs) SetParent

func (tt *Attrs) SetParent(p Elem)

type Border

type Border struct {
	Corners   [4]string // starts upper-left and clockwise, "" draws no corner.
	TopLine   []string  // nil if no top border.
	BotLine   []string  // nil if no bottom border.
	LeftLine  []string  // nil if no left border.
	RightLine []string  // nil if no right border.
}

A border can only have width 0 or 1, and is part of the padding. Each string should represent a character of width 1.

func DefaultBorder

func DefaultBorder() Border

func LeftBorder

func LeftBorder() Border

func (*Border) BLCorner

func (br *Border) BLCorner() string

func (*Border) BRCorner

func (br *Border) BRCorner() string

func (*Border) BottomBorder

func (br *Border) BottomBorder(x int) string

func (*Border) GetCorner

func (br *Border) GetCorner(i int) string

func (*Border) LeftBorder

func (br *Border) LeftBorder(y int) string

func (*Border) RightBorder

func (br *Border) RightBorder(y int) string

func (*Border) TLCorner

func (br *Border) TLCorner() string

func (*Border) TRCorner

func (br *Border) TRCorner() string

func (*Border) TopBorder

func (br *Border) TopBorder(x int) string

type Buffer

type Buffer struct {
	Size
	Cells []Cell
}

A Buffer is a buffer area in which to draw.

func NewBuffer

func NewBuffer(sz Size) *Buffer

func (*Buffer) DrawToScreen

func (bb *Buffer) DrawToScreen(s tcell.Screen)

func (*Buffer) GetCell

func (bb *Buffer) GetCell(x, y int) *Cell

func (*Buffer) NewView

func (bb *Buffer) NewView(offset Coord) View

offset elements must be 0 or positive.

func (*Buffer) Reset

func (bb *Buffer) Reset()

func (*Buffer) Sprint

func (bb *Buffer) Sprint() string

type BufferedElemView

type BufferedElemView struct {
	Coord
	Size
	*Style
	Attrs         // e.g. to focus on a scrollbar
	Base    Elem  // the underlying elem
	Offset  Coord // within elem for pagination
	*Buffer       // view's internal draw screen
}

A view onto an element. Somewhat like a slice onto an array (as a view is onto an elem), except cells are allocated here.

func NewBufferedElemView

func NewBufferedElemView(elem Elem, size Size) *BufferedElemView

Returns a new *BufferedElemView that spans the whole elem. If size is zero, the elem is measured first to get the full buffer size. The result must still be rendered before drawing. The *BufferedElemView inherits the style and coordinates of the elem, and the elem's coord is set to zero.

func (*BufferedElemView) Draw

func (bpv *BufferedElemView) Draw(offset Coord, view View)

func (*BufferedElemView) Measure

func (bpv *BufferedElemView) Measure() Size

BufferedElemView's size is simply defined by .Size.

func (*BufferedElemView) ProcessEventKey

func (bpv *BufferedElemView) ProcessEventKey(ev *EventKey) bool

func (*BufferedElemView) Render

func (bpv *BufferedElemView) Render() (updated bool)

Renders the elem onto the internal buffer. Assumes buffered elem view's elem was already rendered. TODO: this function could be optimized to reduce redundant background cell modifications.

func (*BufferedElemView) Scroll

func (bpv *BufferedElemView) Scroll(dir Coord)

func (*BufferedElemView) SetIsCursor

func (bpv *BufferedElemView) SetIsCursor(ic bool)

Cursor status pierces the buffered elem view; but a few key events are still consumed before the base.

func (*BufferedElemView) SetSize

func (bpv *BufferedElemView) SetSize(size Size)

func (*BufferedElemView) SetStyle

func (bpv *BufferedElemView) SetStyle(style *Style)

Pass on style to the base elem.

func (*BufferedElemView) String

func (bpv *BufferedElemView) String() string

func (*BufferedElemView) StringIndented

func (bpv *BufferedElemView) StringIndented(indent string) string

type Cell

type Cell struct {
	Character string // 1 unicode character, or " ".
	Width     int
	*Style
	Attrs
	Ref Elem // reference to element
}

A terminal character cell.

func (*Cell) GetTCellContent

func (cc *Cell) GetTCellContent() (mainc rune, combc []rune, tstyle tcell.Style)

This is where a bit of dynamic logic is performed, namely where the attr is used to derive the final style.

func (*Cell) Reset

func (cc *Cell) Reset()

func (*Cell) SetValue

func (cc *Cell) SetValue(chs string, w int, st *Style, el Elem)

func (*Cell) SetValueFromCell

func (cc *Cell) SetValueFromCell(c2 *Cell)

NOTE: there is a difference in behavior from SetValue(...,c2) when c2 has attributes not present in c2.Ref, so the two are not equivalent.

type Color

type Color = tcell.Color

func RandColor

func RandColor() Color

type Coord

type Coord struct {
	X int
	Y int
}

func AbsCoord

func AbsCoord(elem Elem) (crd Coord)

func (Coord) Add

func (crd Coord) Add(crd2 Coord) Coord

func (Coord) GetCoord

func (crd Coord) GetCoord() Coord

func (Coord) IsNonNegative

func (crd Coord) IsNonNegative() bool

func (Coord) Neg

func (crd Coord) Neg() Coord

func (*Coord) SetCoord

func (crd *Coord) SetCoord(nc Coord)

func (Coord) Sub

func (crd Coord) Sub(crd2 Coord) Coord

type Elem

type Elem interface {
	GetParent() Elem
	SetParent(Elem)
	GetCoord() Coord
	SetCoord(Coord)
	GetStyle() *Style
	SetStyle(*Style)
	GetAttrs() *Attrs
	GetIsCursor() bool
	SetIsCursor(bool)
	GetIsDirty() bool
	SetIsDirty(bool)
	GetIsOccluded() bool
	SetIsOccluded(bool)
	GetSize() Size
	Measure() Size
	Render() bool
	Draw(offset Coord, dst View)
	ProcessEventKey(*EventKey) bool
	String() string
	StringIndented(indent string) string
}

An elem is something that can draw a portion of itself onto a view. It has a relative coord and a size. Before it is drawn, it is rendered. Measure will update its size, while GetSize() returns the cached size. ProcessEventKey() returns true if event was consumed.

type EventKey

type EventKey = tcell.EventKey

type KVPair

type KVPair struct {
	Key   string
	Value interface{}
}

type Padding

type Padding struct {
	Left   int
	Top    int
	Right  int
	Bottom int
}

func (Padding) GetPadding

func (pd Padding) GetPadding() Padding

type Page

type Page struct {
	Coord // used by parent only. TODO document.
	Size
	*Style
	Attrs
	Elems  []Elem
	Cursor int // selected cursor element index, or -1.
}

A Page has renderable Elem(ents).

func NewPage

func NewPage(s string, width int, isCode bool, style *Style) *Page

produces a page from a string. width is the width of the page. if isCode, width is ignored.

func (*Page) AppendElem

func (pg *Page) AppendElem(elem Elem)

Measures the size of elem and appends to page below the last element, or if empty, the top-leftmost coordinate exclusive of padding cells.

func (*Page) DecCursor

func (pg *Page) DecCursor(isVertical bool)

func (*Page) Draw

func (pg *Page) Draw(offset Coord, view View)

Draw the rendered page elements onto the view.

func (*Page) IncCursor

func (pg *Page) IncCursor(isVertical bool)

func (*Page) Measure

func (pg *Page) Measure() Size

Assumes page starts at 0,0.

func (*Page) NextCoord

func (pg *Page) NextCoord() Coord

func (*Page) ProcessEventKey

func (pg *Page) ProcessEventKey(ev *EventKey) bool

func (*Page) Render

func (pg *Page) Render() (updated bool)

Unlike TextElem or BufferedElemView, a Page doesn't keep its own buffer. Its render function calls the elements' render functions, and the element buffers are combined during Draw(). There is a need for distinction because Draw() can't be too slow, so Render() is about optimizing Draw() calls. The distinction between *Page and BufferedElemView gives the user more flexibility.

func (*Page) SetStyle

func (pg *Page) SetStyle(style *Style)

func (*Page) String

func (pg *Page) String() string

func (*Page) StringIndented

func (pg *Page) StringIndented(indent string) string

type Size

type Size struct {
	Width  int
	Height int // -1 if not set.
}

func (Size) GetSize

func (sz Size) GetSize() Size

func (Size) IsPositive

func (sz Size) IsPositive() bool

func (Size) IsValid

func (sz Size) IsValid() bool

zero widths or heights are valid.

func (Size) IsZero

func (sz Size) IsZero() bool

func (Size) String

func (sz Size) String() string

func (Size) SubCoord

func (sz Size) SubCoord(crd Coord) Size

type Stack

type Stack struct {
	Page // a Stack has the same fields as a page.
}

A Stack is like a Page, but it only highlights the top element, and dims, occludes, or hides lower elements. A Stack is therefore ideal for showing modal views. NOTE: While most applications shouldn't, it's perfectly fine to embed Stacks within Stacks, or layer them on top within a stack.

func NewStack

func NewStack(size Size) *Stack

func StackOf

func StackOf(elem Elem) *Stack

Traverses the inclusive ancestors of elem and returns the first *Stack encountered. The purpose of this function is to find where to push new layers and modal elements for drawing.

func (*Stack) Draw

func (st *Stack) Draw(offset Coord, view View)

Draw the rendered layers onto the view. Any dimming of occluded layers must actually stretch in all directions infinitely (since we can scroll beyond the bounds of any view and we expect the dimming effect to carry while we scroll), so the entire view is dimmed first, and then the upper-most layer is drawn.

func (*Stack) Measure

func (st *Stack) Measure() Size

A Stack's size is simply determined by its .Size.

func (*Stack) ProcessEventKey

func (st *Stack) ProcessEventKey(ev *EventKey) bool

func (*Stack) PushLayer

func (st *Stack) PushLayer(layer Elem)

func (*Stack) Render

func (st *Stack) Render() (updated bool)

A Stack's render function behaves the same as a Page's; it renders its elements (here, its layers).

func (*Stack) String

func (st *Stack) String() string

func (*Stack) StringIndented

func (st *Stack) StringIndented(indent string) string

type Style

type Style struct {
	Foreground Color
	Background Color
	Padding    Padding
	Border     Border
	StyleFlags
	Other       []KVPair
	CursorStyle *Style
}

Style is purely visual and has no side effects. It is generally referred to by pointer; you may need to copy before modifying.

func DefaultStyle

func DefaultStyle() *Style

func (*Style) Copy

func (st *Style) Copy() *Style

func (*Style) GetBackground

func (st *Style) GetBackground() Color

func (*Style) GetBorder

func (st *Style) GetBorder() *Border

func (*Style) GetCursorStyle

func (st *Style) GetCursorStyle() *Style

func (*Style) GetForeground

func (st *Style) GetForeground() Color

func (*Style) GetPadding

func (st *Style) GetPadding() Padding

func (*Style) GetStyle

func (st *Style) GetStyle() *Style

func (Style) GetTStyle

func (st Style) GetTStyle() (tst tcell.Style)

func (*Style) WithAttrs

func (st *Style) WithAttrs(attrs *Attrs) (res Style)

NOTE: this should only be called during the last step when writing to screen. The receiver must not be nil and must not be modified, and the result is a value, not the style of any particular element.

type StyleFlags

type StyleFlags uint32
const (
	StyleFlagBold StyleFlags = 1 << iota
	StyleFlagDim
	StyleFlagShaded
	StyleFlagBlink
	StyleFlagUnderline
	StyleFlagItalic
	StyleFlagStrikeThrough
)
const StyleFlagNone StyleFlags = 0

func (StyleFlags) GetIsDim

func (sf StyleFlags) GetIsDim() bool

func (StyleFlags) GetIsShaded

func (sf StyleFlags) GetIsShaded() bool

func (*StyleFlags) SetIsDim

func (sf *StyleFlags) SetIsDim(id bool)

func (*StyleFlags) SetIsShaded

func (sf *StyleFlags) SetIsShaded(id bool)

type TextElem

type TextElem struct {
	Coord
	Size
	*Style // ignores padding.
	Attrs
	Text string
	*Buffer
}

func NewTextElem

func NewTextElem(text string, style *Style) *TextElem

func (*TextElem) Draw

func (tel *TextElem) Draw(offset Coord, view View)

func (*TextElem) Measure

func (tel *TextElem) Measure() Size

func (*TextElem) ProcessEventKey

func (tel *TextElem) ProcessEventKey(ev *EventKey) bool

func (*TextElem) Render

func (tel *TextElem) Render() (updated bool)

func (*TextElem) SetStyle

func (tel *TextElem) SetStyle(style *Style)

func (*TextElem) String

func (tel *TextElem) String() string

func (*TextElem) StringIndented

func (tel *TextElem) StringIndented(indent string) string

type View

type View struct {
	Base   *Buffer
	Offset Coord // offset within Buffer
	Bounds Size  // total size of slice
}

Offset and Size must be within bounds of *Buffer.

func (View) GetCell

func (bs View) GetCell(x, y int) *Cell

func (View) NewView

func (bs View) NewView(offset Coord) View

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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