Debian Codegraph @

ui/messages/html/base.go

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 // gomuks - A terminal Matrix client written in Go.
2 // Copyright (C) 2020 Tulir Asokan
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
13 //
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <https://www.gnu.org/licenses/>.
16 package html
17
18 import (
19 "fmt"
20
21 "go.mau.fi/mauview"
•22 "github.com/gdamore/tcell/v2"
23 )
24
25 type BaseEntity struct {
26 // The HTML tag of this entity.
27 Tag string
28 // Style for this entity.
29 Style tcell.Style
30 // Whether or not this is a block-type entity.
31 Block bool
32 // Height to use for entity if both text and children are empty.
33 DefaultHeight int
34
35 prevWidth int
36 startX int
37 height int
38 }
39
40 // AdjustStyle changes the style of this text entity.
41 func (be *BaseEntity) AdjustStyle(fn AdjustStyleFunc, reason AdjustStyleReason) Entity {
42 be.Style = fn(be.Style)
43 return be
44 }
45
46 func (be *BaseEntity) IsEmpty() bool {
47 return false
48 }
49
50 // IsBlock returns whether or not this is a block-type entity.
51 func (be *BaseEntity) IsBlock() bool {
52 return be.Block
53 }
54
55 // GetTag returns the HTML tag of this entity.
56 func (be *BaseEntity) GetTag() string {
57 return be.Tag
58 }
59
60 // Height returns the render height of this entity.
61 func (be *BaseEntity) Height() int {
62 return be.height
63 }
64
65 func (be *BaseEntity) getStartX() int {
66 return be.startX
67 }
68
69 // Clone creates a copy of this base entity.
70 func (be *BaseEntity) Clone() Entity {
71 return &BaseEntity{
72 Tag: be.Tag,
73 Style: be.Style,
74 Block: be.Block,
75 DefaultHeight: be.DefaultHeight,
76 }
77 }
78
79 func (be *BaseEntity) PlainText() string {
80 return ""
81 }
82
83 // String returns a textual representation of this BaseEntity struct.
84 func (be *BaseEntity) String() string {
85 return fmt.Sprintf(`&html.BaseEntity{Tag="%s", Style=%#v, Block=%t, startX=%d, height=%d}`,
86 be.Tag, be.Style, be.Block, be.startX, be.height)
87 }
88
89 // CalculateBuffer prepares this entity for rendering with the given parameters.
90 func (be *BaseEntity) CalculateBuffer(width, startX int, ctx DrawContext) int {
91 be.height = be.DefaultHeight
92 be.startX = startX
93 if be.Block {
94 be.startX = 0
95 }
96 return be.startX
97 }
98
99 func (be *BaseEntity) Draw(screen mauview.Screen, ctx DrawContext) {
100 panic("Called Draw() of BaseEntity")
101 }