ck/drw/drw.go
2024-07-21 00:36:02 +02:00

72 lines
1.6 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package drw
import (
"unicode/utf8"
"github.com/gdamore/tcell/v2"
"git.bonsai.cool/kayprish/ck/util"
)
var (
months = [...]string{"", "Јануар", "Фебруар", "Март", "Април", "Мај", "Јун",
"Јул", "Август", "Септембар", "Октобар", "Новембар", "Децембар"}
weekdays = [...]string{"Недеља", "Понедељак", "Уторак", "Среда", "Четвртак",
"Петак", "Субота"}
)
var (
DefStyle tcell.Style = tcell.StyleDefault.
Background(tcell.ColorReset).
Foreground(tcell.ColorReset)
TodayStyle tcell.Style = tcell.StyleDefault.
Background(tcell.ColorReset).
Foreground(tcell.GetColor("blue")).
Bold(true).
Reverse(true)
SelStyle tcell.Style = tcell.StyleDefault.
Background(tcell.ColorReset).
Foreground(tcell.GetColor("green")).
Bold(true)
HolyStyle tcell.Style = tcell.StyleDefault.
Background(tcell.ColorReset).
Foreground(tcell.GetColor("red")).
Bold(true)
)
func centeredText(s string, x, y, width int, scr tcell.Screen, style tcell.Style) {
start := x + util.Max((width-utf8.RuneCountInString(s))/2, 0)
i := 0
for ; x+i < start; i++ {
scr.SetContent(x+i, y, ' ', nil, style)
}
for _, char := range s {
if i >= width {
break
}
scr.SetContent(x+i, y, char, nil, style)
i++
}
for ; x+i < start; i++ {
scr.SetContent(x+i, y, ' ', nil, style)
}
}
func wrappedText(s string, scr tcell.Screen, style tcell.Style) {
x := 0
y := 0
w, h := scr.Size()
for _, char := range s {
if x >= w {
if y >= h {
break
}
x = 0
y++
}
scr.SetContent(x, y, char, nil, style)
x++
}
}