Debian Codegraph @

ui/messages/tstring/cell.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
17 package tstring
18
19 import (
20 "github.com/mattn/go-runewidth"
21
22 "go.mau.fi/mauview"
•23 "github.com/gdamore/tcell/v2"
24 )
25
26 type Cell struct {
27 Char rune
28 Style tcell.Style
29 }
30
31 func NewStyleCell(char rune, style tcell.Style) Cell {
32 return Cell{char, style}
33 }
34
35 func NewColorCell(char rune, color tcell.Color) Cell {
36 return Cell{char, tcell.StyleDefault.Foreground(color)}
37 }
38
39 func NewCell(char rune) Cell {
40 return Cell{char, tcell.StyleDefault}
41 }
42
43 func (cell Cell) RuneWidth() int {
44 return runewidth.RuneWidth(cell.Char)
45 }
46
47 func (cell Cell) Draw(screen mauview.Screen, x, y int) (chWidth int) {
48 chWidth = cell.RuneWidth()
49 for runeWidthOffset := 0; runeWidthOffset < chWidth; runeWidthOffset++ {
50 screen.SetContent(x+runeWidthOffset, y, cell.Char, nil, cell.Style)
51 }
52 return
53 }