Initial commit
This commit is contained in:
commit
e41bb4d8ae
135
Main.go
Normal file
135
Main.go
Normal file
|
@ -0,0 +1,135 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
"strconv"
|
||||||
|
"unicode/utf8"
|
||||||
|
|
||||||
|
|
||||||
|
"github.com/gdamore/tcell/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
dayWidth = 2
|
||||||
|
gapWidth = 1
|
||||||
|
monthWidth = 7*dayWidth + 6*gapWidth
|
||||||
|
monthHeight = (31+6+(7-1))/7 + 2
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
months = [...]string{"", "Јануар", "Фебруар", "Март", "Април", "Мај", "Јун",
|
||||||
|
"Јул", "Август", "Септембар", "Октобар", "Новембар", "Децембар"}
|
||||||
|
weekdays = [...]string{"Недеља", "Понедељак", "Уторак", "Среда", "Четвртак",
|
||||||
|
"Петак", "Субота"}
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
wall tcell.Screen
|
||||||
|
defStyle tcell.Style
|
||||||
|
selStyle tcell.Style
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
selTime time.Time
|
||||||
|
today time.Time
|
||||||
|
)
|
||||||
|
|
||||||
|
func max(a, b int) int {
|
||||||
|
if a > b {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func date(year int, month time.Month, day int) time.Time {
|
||||||
|
return time.Date(year, month, day, 0, 0, 0, 0, time.Local)
|
||||||
|
}
|
||||||
|
|
||||||
|
func centeredText(s string, x, y, width int, scr tcell.Screen, style tcell.Style) {
|
||||||
|
start := x + max((width - utf8.RuneCountInString(s)) / 2, 0)
|
||||||
|
i := 0
|
||||||
|
for _, char := range s {
|
||||||
|
if i >= width {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
scr.SetContent(start + i, y, char, nil, style)
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func drawMonth(m time.Month, x, y int) {
|
||||||
|
centeredText(months[m], x, y, monthWidth, wall, defStyle)
|
||||||
|
|
||||||
|
for i := 1; i <= 7; i++ {
|
||||||
|
centeredText(weekdays[i % 7], x + (i - 1) * (dayWidth + gapWidth), y + 1, dayWidth, wall, defStyle)
|
||||||
|
}
|
||||||
|
|
||||||
|
dayNum := date(selTime.Year(), m + 1, 0).Day()
|
||||||
|
for i := 1; i <= dayNum; i++ {
|
||||||
|
weekday := int(date(selTime.Year(), m, i).Weekday())
|
||||||
|
style := defStyle
|
||||||
|
if selTime.Day() == i && selTime.Month() == m {
|
||||||
|
style = selStyle
|
||||||
|
}
|
||||||
|
centeredText(
|
||||||
|
strconv.Itoa(i),
|
||||||
|
x + ((weekday - 1 + 7) % 7) * (dayWidth + gapWidth),
|
||||||
|
y + 2,
|
||||||
|
2,
|
||||||
|
wall,
|
||||||
|
style)
|
||||||
|
if weekday == 0 {
|
||||||
|
y++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func drawWall() {
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
today = time.Now()
|
||||||
|
selTime = today
|
||||||
|
var err error
|
||||||
|
wall, err = tcell.NewScreen()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("%+v", err)
|
||||||
|
}
|
||||||
|
if err := wall.Init(); err != nil {
|
||||||
|
log.Fatalf("%+v", err)
|
||||||
|
}
|
||||||
|
defStyle = tcell.StyleDefault.Background(tcell.ColorReset).Foreground(tcell.ColorReset)
|
||||||
|
selStyle = tcell.StyleDefault.Background(tcell.ColorReset).Foreground(tcell.GetColor("green")).Bold(true)
|
||||||
|
|
||||||
|
wall.SetStyle(defStyle)
|
||||||
|
wall.Clear()
|
||||||
|
drawMonth(time.January, 0, 0)
|
||||||
|
drawMonth(time.July, monthWidth * 2, 0)
|
||||||
|
|
||||||
|
|
||||||
|
quit := func() {
|
||||||
|
wall.Fini()
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
for {
|
||||||
|
// Update screen
|
||||||
|
wall.Show()
|
||||||
|
|
||||||
|
// Poll event
|
||||||
|
ev := wall.PollEvent()
|
||||||
|
|
||||||
|
// Process event
|
||||||
|
switch ev := ev.(type) {
|
||||||
|
case *tcell.EventResize:
|
||||||
|
wall.Sync()
|
||||||
|
case *tcell.EventKey:
|
||||||
|
if ev.Key() == tcell.KeyEscape || ev.Key() == tcell.KeyCtrlC ||
|
||||||
|
ev.Rune() == 'Q' || ev.Rune() == 'q' {
|
||||||
|
quit()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
8
go.mod
Normal file
8
go.mod
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
module gitlab.com/tvrdosrz/ck
|
||||||
|
|
||||||
|
go 1.16
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/gdamore/tcell v1.4.0
|
||||||
|
github.com/gdamore/tcell/v2 v2.3.11 // indirect
|
||||||
|
)
|
22
go.sum
Normal file
22
go.sum
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
|
||||||
|
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
|
||||||
|
github.com/gdamore/tcell v1.4.0 h1:vUnHwJRvcPQa3tzi+0QI4U9JINXYJlOz9yiaiPQ2wMU=
|
||||||
|
github.com/gdamore/tcell v1.4.0/go.mod h1:vxEiSDZdW3L+Uhjii9c3375IlDmR05bzxY404ZVSMo0=
|
||||||
|
github.com/gdamore/tcell/v2 v2.3.11 h1:ECO6WqHGbKZ3HrSL7bG/zArMCmLaNr5vcjjMVnLHpzc=
|
||||||
|
github.com/gdamore/tcell/v2 v2.3.11/go.mod h1:cTTuF84Dlj/RqmaCIV5p4w8uG1zWdk0SF6oBpwHp4fU=
|
||||||
|
github.com/lucasb-eyer/go-colorful v1.0.3 h1:QIbQXiugsb+q10B+MI+7DI1oQLdmnep86tWFlaaUAac=
|
||||||
|
github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||||
|
github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54=
|
||||||
|
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||||
|
github.com/mattn/go-runewidth v0.0.10 h1:CoZ3S2P7pvtP45xOtBw+/mDL2z0RKI576gSkzRRpdGg=
|
||||||
|
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
|
||||||
|
github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY=
|
||||||
|
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||||
|
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756 h1:9nuHUbU8dRnRRfj9KjWUVrJeoexdbeMjttk6Oh1rD10=
|
||||||
|
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
|
||||||
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf h1:MZ2shdL+ZM/XzY3ZGOnh4Nlpnxz5GSOhOmtHo3iPU6M=
|
||||||
|
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
|
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
Loading…
Reference in a new issue