| 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 |
|
| 17 |
package html |
| 18 |
|
| 19 |
import ( |
| 20 |
"go.mau.fi/mauview" |
| •21 |
"github.com/gdamore/tcell/v2" |
| 22 |
) |
| 23 |
|
| 24 |
type CodeBlockEntity struct { |
| 25 |
*ContainerEntity |
| 26 |
Background tcell.Style |
| 27 |
} |
| 28 |
|
| 29 |
func NewCodeBlockEntity(children []Entity, background tcell.Style) *CodeBlockEntity { |
| 30 |
return &CodeBlockEntity{ |
| 31 |
ContainerEntity: &ContainerEntity{ |
| 32 |
BaseEntity: &BaseEntity{ |
| 33 |
Tag: "pre", |
| 34 |
Block: true, |
| 35 |
}, |
| 36 |
Children: children, |
| 37 |
}, |
| 38 |
Background: background, |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
func (ce *CodeBlockEntity) Clone() Entity { |
| 43 |
return &CodeBlockEntity{ |
| 44 |
ContainerEntity: ce.ContainerEntity.Clone().(*ContainerEntity), |
| 45 |
Background: ce.Background, |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
func (ce *CodeBlockEntity) Draw(screen mauview.Screen, ctx DrawContext) { |
| 50 |
screen.Fill(' ', ce.Background) |
| 51 |
ce.ContainerEntity.Draw(screen, ctx) |
| 52 |
} |
| 53 |
|
| 54 |
func (ce *CodeBlockEntity) AdjustStyle(fn AdjustStyleFunc, reason AdjustStyleReason) Entity { |
| 55 |
if reason != AdjustStyleReasonNormal { |
| 56 |
ce.ContainerEntity.AdjustStyle(fn, reason) |
| 57 |
} |
| 58 |
return ce |
| 59 |
} |