Colorize some results
* Can toggle default calendars * Though the interactive screen doesn't update :( * Colorize default view depending on time until event
This commit is contained in:
parent
22e770cc64
commit
23b8a190ec
144
interactive_mode.go
Normal file
144
interactive_mode.go
Normal file
@ -0,0 +1,144 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/jroimartin/gocui"
|
||||
)
|
||||
|
||||
// BEGIN CONFIG SCREEN FUNCTIONS //
|
||||
func DoConfig() {
|
||||
g, err := gocui.NewGui(gocui.Output256)
|
||||
if err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
defer g.Close()
|
||||
g.Cursor = true
|
||||
g.SetManagerFunc(configLayout)
|
||||
|
||||
// Set up some keybindings
|
||||
if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
if err := g.SetKeybinding("default_calendars", gocui.KeyArrowUp, gocui.ModNone, cursorUp); err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
if err := g.SetKeybinding("default_calendars", 'k', gocui.ModNone, cursorUp); err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
if err := g.SetKeybinding("default_calendars", gocui.KeyArrowDown, gocui.ModNone, cursorDown); err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
if err := g.SetKeybinding("default_calendars", 'j', gocui.ModNone, cursorDown); err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
if err := g.SetKeybinding("default_calendars", gocui.KeySpace, gocui.ModNone, toggleCalendar); err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
if err := g.SetKeybinding("default_calendars", gocui.KeyEnter, gocui.ModNone, toggleCalendar); err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
|
||||
// Kick off the main loop
|
||||
if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
|
||||
log.Panicln(err)
|
||||
}
|
||||
}
|
||||
|
||||
func configLayout(g *gocui.Gui) error {
|
||||
list := state.account.GetCalendarList()
|
||||
height := len(list) + 4
|
||||
width, _ := g.Size()
|
||||
if v, err := g.SetView("default_calendars", 0, 0, width-1, height); err != nil {
|
||||
if err != gocui.ErrUnknownView {
|
||||
return err
|
||||
}
|
||||
|
||||
v.Highlight = true
|
||||
v.SelBgColor = gocui.ColorGreen
|
||||
v.SelFgColor = gocui.ColorBlack
|
||||
|
||||
v.Clear()
|
||||
drawCalList(g, v)
|
||||
_, err := g.SetCurrentView("default_calendars")
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func quit(g *gocui.Gui, v *gocui.View) error {
|
||||
return gocui.ErrQuit
|
||||
}
|
||||
|
||||
func toggleCalendar(g *gocui.Gui, v *gocui.View) error {
|
||||
_, cy := v.Cursor()
|
||||
calList := state.account.GetCalendarList()
|
||||
if v != nil {
|
||||
for i := range state.defaultCalendars {
|
||||
state.StatusMsg = time.Now().Format(time.RFC3339)
|
||||
if state.defaultCalendars[i] == calList[cy].Id {
|
||||
// Remove calendar from defaults
|
||||
state.defaultCalendars = append(state.defaultCalendars[:i], state.defaultCalendars[i+1:]...)
|
||||
}
|
||||
}
|
||||
}
|
||||
// Add calendar to defaults
|
||||
state.defaultCalendars = append(state.defaultCalendars, calList[cy].Id)
|
||||
return nil
|
||||
}
|
||||
|
||||
func cursorUp(g *gocui.Gui, v *gocui.View) error {
|
||||
if v != nil {
|
||||
ox, oy := v.Origin()
|
||||
cx, cy := v.Cursor()
|
||||
if err := v.SetCursor(cx, cy-1); err != nil && oy > 0 {
|
||||
if err := v.SetOrigin(ox, oy-1); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func cursorDown(g *gocui.Gui, v *gocui.View) error {
|
||||
if v != nil {
|
||||
cx, cy := v.Cursor()
|
||||
if err := v.SetCursor(cx, cy+1); err != nil {
|
||||
ox, oy := v.Origin()
|
||||
if err := v.SetOrigin(ox, oy+1); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func drawCalList(g *gocui.Gui, v *gocui.View) error {
|
||||
width, _ := g.Size()
|
||||
list := state.account.GetCalendarList()
|
||||
for i := range list {
|
||||
isDef := false
|
||||
for defIdx := range state.defaultCalendars {
|
||||
if list[i].Id == state.defaultCalendars[defIdx] {
|
||||
isDef = true
|
||||
break
|
||||
}
|
||||
}
|
||||
calSumTxt := "["
|
||||
if isDef {
|
||||
calSumTxt += "*"
|
||||
} else {
|
||||
calSumTxt += " "
|
||||
}
|
||||
calSumTxt += "] " + list[i].Summary
|
||||
spc := strings.Repeat(" ", width-len(calSumTxt)-2)
|
||||
fmt.Fprintln(v, calSumTxt+spc)
|
||||
}
|
||||
fmt.Fprintln(v, "Status: "+time.Now().Format(time.RFC3339))
|
||||
return nil
|
||||
}
|
||||
|
||||
// END CONFIG SCREEN FUNCTIONS //
|
166
main.go
166
main.go
@ -11,7 +11,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/br0xen/user-config"
|
||||
"github.com/jroimartin/gocui"
|
||||
"github.com/fatih/color"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -50,14 +50,22 @@ func main() {
|
||||
|
||||
DoVersionCheck()
|
||||
|
||||
switch op {
|
||||
case "--reinit":
|
||||
// Reset all config
|
||||
for _, v := range state.cfg.GetKeyList() {
|
||||
fmt.Println("Deleting Key: " + v)
|
||||
state.cfg.DeleteKey(v)
|
||||
}
|
||||
for i := range os.Args {
|
||||
switch os.Args[i] {
|
||||
case "--reinit":
|
||||
// Reset all config
|
||||
for _, v := range state.cfg.GetKeyList() {
|
||||
fmt.Println("Deleting Key: " + v)
|
||||
state.cfg.DeleteKey(v)
|
||||
}
|
||||
case "--refresh":
|
||||
|
||||
case "-r":
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
switch op {
|
||||
case "today":
|
||||
// Show everything on the calendar for today
|
||||
InitComm()
|
||||
@ -78,10 +86,16 @@ func main() {
|
||||
}
|
||||
sort.Sort(ByStartTime(todayEvents))
|
||||
for _, e := range todayEvents {
|
||||
if e.GetStartTime() == "00:00:00" {
|
||||
fmt.Println("[All Day ] " + e.Summary)
|
||||
if e.GetStartTimeString() == "00:00:00" {
|
||||
color.New(color.FgGreen).Println("[All Day ] " + e.Summary)
|
||||
} else {
|
||||
fmt.Println("[" + e.GetStartTime() + "] " + e.Summary)
|
||||
if time.Until(e.GetStartTime()) < time.Hour {
|
||||
color.New(color.FgYellow).Add(color.Bold).Println("[" + e.GetStartTimeString() + "] " + e.Summary)
|
||||
} else if time.Until(e.GetStartTime()) < time.Minute*30 {
|
||||
color.New(color.FgRed).Add(color.Bold).Println("[" + e.GetStartTimeString() + "] " + e.Summary)
|
||||
} else {
|
||||
fmt.Println("[" + e.GetStartTimeString() + "] " + e.Summary)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -207,133 +221,3 @@ func loadAccountState() {
|
||||
fmt.Println("error: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
// BEGIN CONFIG SCREEN FUNCTIONS //
|
||||
func DoConfig() {
|
||||
g, err := gocui.NewGui(gocui.Output256)
|
||||
if err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
defer g.Close()
|
||||
g.Cursor = true
|
||||
g.SetManagerFunc(configLayout)
|
||||
|
||||
// Set up some keybindings
|
||||
if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
if err := g.SetKeybinding("default_calendars", gocui.KeyArrowUp, gocui.ModNone, cursorUp); err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
if err := g.SetKeybinding("default_calendars", 'k', gocui.ModNone, cursorUp); err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
if err := g.SetKeybinding("default_calendars", gocui.KeyArrowDown, gocui.ModNone, cursorDown); err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
if err := g.SetKeybinding("default_calendars", 'j', gocui.ModNone, cursorDown); err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
if err := g.SetKeybinding("default_calendars", gocui.KeySpace, gocui.ModNone, toggleCalendar); err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
if err := g.SetKeybinding("default_calendars", gocui.KeyEnter, gocui.ModNone, toggleCalendar); err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
|
||||
// Kick off the main loop
|
||||
if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
|
||||
log.Panicln(err)
|
||||
}
|
||||
}
|
||||
|
||||
func configLayout(g *gocui.Gui) error {
|
||||
list := state.account.GetCalendarList()
|
||||
height := len(list) + 4
|
||||
width, _ := g.Size()
|
||||
if v, err := g.SetView("default_calendars", 0, 0, width-1, height); err != nil {
|
||||
v.Highlight = true
|
||||
v.SelBgColor = gocui.ColorGreen
|
||||
v.SelFgColor = gocui.ColorBlack
|
||||
if err != gocui.ErrUnknownView {
|
||||
return err
|
||||
}
|
||||
drawCalList(g, v)
|
||||
|
||||
if _, err := g.SetCurrentView("default_calendars"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func quit(g *gocui.Gui, v *gocui.View) error {
|
||||
return gocui.ErrQuit
|
||||
}
|
||||
|
||||
func toggleCalendar(g *gocui.Gui, v *gocui.View) error {
|
||||
_, cy := v.Cursor()
|
||||
calList := state.account.GetCalendarList()
|
||||
if v != nil {
|
||||
for i := range state.defaultCalendars {
|
||||
state.StatusMsg = time.Now().Format(time.RFC3339)
|
||||
if state.defaultCalendars[i] == calList[cy].Id {
|
||||
}
|
||||
}
|
||||
}
|
||||
drawCalList(g, v)
|
||||
return nil
|
||||
}
|
||||
|
||||
func cursorUp(g *gocui.Gui, v *gocui.View) error {
|
||||
if v != nil {
|
||||
ox, oy := v.Origin()
|
||||
cx, cy := v.Cursor()
|
||||
if err := v.SetCursor(cx, cy-1); err != nil && oy > 0 {
|
||||
if err := v.SetOrigin(ox, oy-1); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func cursorDown(g *gocui.Gui, v *gocui.View) error {
|
||||
if v != nil {
|
||||
cx, cy := v.Cursor()
|
||||
if err := v.SetCursor(cx, cy+1); err != nil {
|
||||
ox, oy := v.Origin()
|
||||
if err := v.SetOrigin(ox, oy+1); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func drawCalList(g *gocui.Gui, v *gocui.View) error {
|
||||
width, _ := g.Size()
|
||||
list := state.account.GetCalendarList()
|
||||
for i := range list {
|
||||
isDef := false
|
||||
for defIdx := range state.defaultCalendars {
|
||||
if list[i].Id == state.defaultCalendars[defIdx] {
|
||||
isDef = true
|
||||
break
|
||||
}
|
||||
}
|
||||
calSumTxt := "["
|
||||
if isDef {
|
||||
calSumTxt += "*"
|
||||
} else {
|
||||
calSumTxt += " "
|
||||
}
|
||||
calSumTxt += "] " + list[i].Summary
|
||||
spc := strings.Repeat(" ", width-len(calSumTxt)-2)
|
||||
fmt.Fprintln(v, calSumTxt+spc)
|
||||
}
|
||||
fmt.Fprintln(v, "Status: "+state.StatusMsg)
|
||||
return nil
|
||||
}
|
||||
|
||||
// END CONFIG SCREEN FUNCTIONS //
|
||||
|
@ -48,7 +48,7 @@ func (e *Event) ToCLIString() string {
|
||||
return fmt.Sprintf("%s\n%s\n", e.Summary, e.GetStartTime())
|
||||
}
|
||||
|
||||
func (e *Event) GetStartTime() string {
|
||||
func (e *Event) GetStartTimeString() string {
|
||||
tm, err := time.Parse(time.RFC3339, e.Start.DateTime)
|
||||
if err != nil {
|
||||
return "00:00:00"
|
||||
@ -56,6 +56,11 @@ func (e *Event) GetStartTime() string {
|
||||
return tm.Local().Format("15:04:05")
|
||||
}
|
||||
|
||||
func (e *Event) GetStartTime() time.Time {
|
||||
tm, _ := time.Parse(time.RFC3339, e.Start.DateTime)
|
||||
return tm
|
||||
}
|
||||
|
||||
func GoogleEventToLocal(e *calendar.Event) *Event {
|
||||
return &Event{
|
||||
//Attachments []EventAttachment // Google Drive files
|
23
struct_screen.go
Normal file
23
struct_screen.go
Normal file
@ -0,0 +1,23 @@
|
||||
package main
|
||||
|
||||
import "github.com/jroimartin/gocui"
|
||||
|
||||
type screen interface {
|
||||
setViewDefaults(*gocui.View)
|
||||
setViewTextAndCursor(*gocui.View, string)
|
||||
getViewValue(*gocui.Gui)
|
||||
}
|
||||
|
||||
type position struct {
|
||||
// value = pct * MAX + abs
|
||||
pct float32
|
||||
abs int
|
||||
}
|
||||
|
||||
func (p position) getCoordinate(max int) int {
|
||||
return int(p.pct*float32(max)) + p.abs
|
||||
}
|
||||
|
||||
type viewPosition struct {
|
||||
x0, y0, x1, y1 position
|
||||
}
|
Loading…
Reference in New Issue
Block a user