Started work on Interactive Mode
This commit is contained in:
parent
ae07d839f0
commit
544a579649
@ -78,7 +78,7 @@ func configLayout(g *gocui.Gui) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateViews(g *gocui.Gui) error {
|
func updateConfigViews(g *gocui.Gui) error {
|
||||||
for _, v := range g.Views() {
|
for _, v := range g.Views() {
|
||||||
v.Clear()
|
v.Clear()
|
||||||
switch v.Name() {
|
switch v.Name() {
|
||||||
@ -117,7 +117,7 @@ func toggleCalendar(g *gocui.Gui, v *gocui.View) error {
|
|||||||
state.StatusMsg = "Calendar '" + calList[cy].Summary + "' Added to Defaults"
|
state.StatusMsg = "Calendar '" + calList[cy].Summary + "' Added to Defaults"
|
||||||
state.account.ActiveCalendars = append(state.account.ActiveCalendars, calList[cy].Id)
|
state.account.ActiveCalendars = append(state.account.ActiveCalendars, calList[cy].Id)
|
||||||
}
|
}
|
||||||
updateViews(g)
|
updateConfigViews(g)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
6
main.go
6
main.go
@ -37,7 +37,7 @@ var state *AppState
|
|||||||
var parameters []string
|
var parameters []string
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
parameters = []string{"add", "colors", "config", "event", "defaults", "delete", "next", "refresh", "today", "ui"}
|
parameters = []string{"add", "config", "event", "defaults", "delete", "next", "refresh", "today", "ui"}
|
||||||
var err error
|
var err error
|
||||||
var op string
|
var op string
|
||||||
state = &AppState{Name: AppName, Version: AppVersion}
|
state = &AppState{Name: AppName, Version: AppVersion}
|
||||||
@ -196,9 +196,9 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// case "ui":
|
case "ui":
|
||||||
// Open the UI mode
|
// Open the UI mode
|
||||||
// DoUIMode()
|
DoUIMode()
|
||||||
|
|
||||||
case "help":
|
case "help":
|
||||||
printHelp()
|
printHelp()
|
||||||
|
73
ui_mode.go
73
ui_mode.go
@ -1,12 +1,27 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/jroimartin/gocui"
|
"github.com/jroimartin/gocui"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type UIState struct {
|
||||||
|
SelCalMonth time.Month
|
||||||
|
SelCalDay int
|
||||||
|
SelCalYear int
|
||||||
|
}
|
||||||
|
|
||||||
|
var uiState *UIState
|
||||||
|
|
||||||
func DoUIMode() {
|
func DoUIMode() {
|
||||||
|
uiState = &UIState{
|
||||||
|
SelCalMonth: time.Now().Month(),
|
||||||
|
SelCalDay: time.Now().Day(),
|
||||||
|
SelCalYear: time.Now().Year(),
|
||||||
|
}
|
||||||
g, err := gocui.NewGui(gocui.Output256)
|
g, err := gocui.NewGui(gocui.Output256)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panicln(err)
|
log.Panicln(err)
|
||||||
@ -15,23 +30,65 @@ func DoUIMode() {
|
|||||||
g.Cursor = true
|
g.Cursor = true
|
||||||
g.SetManagerFunc(uiLayout)
|
g.SetManagerFunc(uiLayout)
|
||||||
|
|
||||||
|
// Set up some keybindings
|
||||||
|
if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
|
||||||
|
log.Panicln(err)
|
||||||
|
}
|
||||||
|
if err := g.SetKeybinding("", 'q', gocui.ModNone, quit); err != nil {
|
||||||
|
log.Panicln(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// And now the main loop
|
||||||
if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
|
if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
|
||||||
log.Panicln(err)
|
log.Panicln(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateUiViews(g *gocui.Gui) {
|
|
||||||
for _, v := range g.Views() {
|
|
||||||
v.Clear()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func uiLayout(g *gocui.Gui) error {
|
func uiLayout(g *gocui.Gui) error {
|
||||||
if v, err := g.SetView("cal_view", 0, 0, 20, 20); err != nil {
|
if v, err := g.SetView("cal_view", 0, 0, 20, 62); err != nil {
|
||||||
if err != gocui.ErrUnknownView {
|
if err != gocui.ErrUnknownView {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_ = v
|
v.SelBgColor = gocui.ColorGreen
|
||||||
|
v.SelFgColor = gocui.ColorBlack
|
||||||
|
|
||||||
|
drawCalendar(g, v)
|
||||||
|
if _, err = g.SetCurrentView("cal_view"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func updateUiViews(g *gocui.Gui) error {
|
||||||
|
for _, v := range g.Views() {
|
||||||
|
v.Clear()
|
||||||
|
switch v.Name() {
|
||||||
|
case "cal_view":
|
||||||
|
if err := drawCalendar(g, v); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func drawCalendar(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
// Print the 'Today' String
|
||||||
|
fmt.Fprintln(v, "<", uiState.SelCalMonth.String()[:3], uiState.SelCalDay, ",", uiState.SelCalYear, ">")
|
||||||
|
// Find the first of the month's week day
|
||||||
|
for wrkDay := 1; wrkDay <= 31; wrkDay++ {
|
||||||
|
wrkCalString := fmt.Sprintf("%04d%02d%02d", uiState.SelCalYear, uiState.SelCalMonth, wrkDay)
|
||||||
|
wrkTime, _ := time.Parse("20060102", wrkCalString)
|
||||||
|
fmt.Fprintf(v, "%04d%02d%02d\n", wrkTime.Year(), wrkTime.Month(), wrkTime.Day())
|
||||||
|
fmt.Fprintln(v, wrkTime.Weekday())
|
||||||
|
if wrkDay == 1 {
|
||||||
|
// For the first day, we need to space it in wrkTime.Weekday() spaces
|
||||||
|
for i := 0; i < int(wrkTime.Weekday()); i++ {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user