1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Rudimentary modal showing up for Todo on 'e'

This commit is contained in:
Chris Cummer 2018-04-24 19:41:15 -07:00
parent ed52835650
commit bef57d799b
7 changed files with 47 additions and 31 deletions

View File

@ -2,6 +2,8 @@ package clocks
import ( import (
"fmt" "fmt"
"github.com/senorprogrammer/wtf/wtf"
) )
func (widget *Widget) display(clocks []Clock) { func (widget *Widget) display(clocks []Clock) {
@ -16,8 +18,8 @@ func (widget *Widget) display(clocks []Clock) {
" [%s]%-12s %-10s %7s[white]\n", " [%s]%-12s %-10s %7s[white]\n",
widget.rowColor(idx), widget.rowColor(idx),
clock.Label, clock.Label,
clock.LocalTime.Format(TimeFormat), clock.LocalTime.Format(wtf.SimpleTimeFormat),
clock.LocalTime.Format(DateFormat), clock.LocalTime.Format(wtf.SimpleDateFormat),
) )
} }

View File

@ -7,9 +7,6 @@ import (
"github.com/senorprogrammer/wtf/wtf" "github.com/senorprogrammer/wtf/wtf"
) )
const TimeFormat = "15:04 MST"
const DateFormat = "Jan 2"
// Config is a pointer to the global config object // Config is a pointer to the global config object
var Config *config.Config var Config *config.Config

View File

@ -113,7 +113,7 @@ func (widget *Widget) eventSummary(event *calendar.Event, conflict bool) string
func (widget *Widget) eventTimestamp(event *calendar.Event) string { func (widget *Widget) eventTimestamp(event *calendar.Event) string {
startTime, _ := time.Parse(time.RFC3339, event.Start.DateTime) startTime, _ := time.Parse(time.RFC3339, event.Start.DateTime)
return startTime.Format("Mon, Jan 2, 15:04") return startTime.Format(wtf.FriendlyDateTimeFormat)
} }
// eventIsNow returns true if the event is happening now, false if it not // eventIsNow returns true if the event is happening now, false if it not

View File

@ -48,7 +48,7 @@ func (widget *Widget) Refresh() {
} }
func (widget *Widget) prettyBuiltAt() string { func (widget *Widget) prettyBuiltAt() string {
str, err := time.Parse("2006-01-02T15:04:05-0700", widget.BuiltAt) str, err := time.Parse(wtf.TimestampFormat, widget.BuiltAt)
if err != nil { if err != nil {
return err.Error() return err.Error()
} else { } else {

View File

@ -3,11 +3,11 @@ package todo
import ( import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
//"os/exec"
"time" "time"
"github.com/gdamore/tcell" "github.com/gdamore/tcell"
"github.com/olebedev/config" "github.com/olebedev/config"
"github.com/rivo/tview"
"github.com/senorprogrammer/wtf/wtf" "github.com/senorprogrammer/wtf/wtf"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
) )
@ -18,16 +18,18 @@ var Config *config.Config
type Widget struct { type Widget struct {
wtf.TextWidget wtf.TextWidget
FilePath string pages *tview.Pages
filePath string
list *List list *List
} }
func NewWidget() *Widget { func NewWidget(pages *tview.Pages) *Widget {
widget := Widget{ widget := Widget{
TextWidget: wtf.NewTextWidget(" 📝 Todo ", "todo"), TextWidget: wtf.NewTextWidget(" 📝 Todo ", "todo"),
FilePath: Config.UString("wtf.mods.todo.filename"),
list: &List{selected: -1}, pages: pages,
filePath: Config.UString("wtf.mods.todo.filename"),
list: &List{selected: -1},
} }
widget.init() widget.init()
@ -50,8 +52,23 @@ func (widget *Widget) Refresh() {
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */
// edit opens a modal dialog that permits editing the text of the currently-selected item
func (widget *Widget) edit() {
modal := tview.NewModal().
SetText("Do you want to quit the application?").
AddButtons([]string{"Quit", "Cancel"}).
SetDoneFunc(func(buttonIndex int, buttonLabel string) {
if buttonLabel == "Quit" {
widget.pages.RemovePage("edit")
}
})
widget.pages.AddPage("edit", modal, false, true)
//widget.app.SetFocus(modal)
}
func (widget *Widget) init() { func (widget *Widget) init() {
_, err := wtf.CreateFile(widget.FilePath) _, err := wtf.CreateFile(widget.filePath)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -67,6 +84,7 @@ func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
return nil return nil
case "e": case "e":
// Edit selected item // Edit selected item
widget.edit()
return nil return nil
case "h": case "h":
// Show help menu // Show help menu
@ -86,7 +104,7 @@ func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
case "o": case "o":
// Open the file // Open the file
//widget.openFile() //widget.openFile()
wtf.OpenFile(widget.FilePath) wtf.OpenFile(widget.filePath)
return nil return nil
} }
@ -133,24 +151,16 @@ func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
// Loads the todo list from Yaml file // Loads the todo list from Yaml file
func (widget *Widget) load() { func (widget *Widget) load() {
confDir, _ := wtf.ConfigDir() confDir, _ := wtf.ConfigDir()
filePath := fmt.Sprintf("%s/%s", confDir, widget.FilePath) filePath := fmt.Sprintf("%s/%s", confDir, widget.filePath)
fileData, _ := wtf.ReadFileBytes(filePath) fileData, _ := wtf.ReadFileBytes(filePath)
yaml.Unmarshal(fileData, &widget.list) yaml.Unmarshal(fileData, &widget.list)
} }
//func (widget *Widget) openFile() {
//confDir, _ := wtf.ConfigDir()
//filePath := fmt.Sprintf("%s/%s", confDir, widget.FilePath)
//cmd := exec.Command("open", filePath)
//wtf.ExecuteCommand(cmd)
//}
// persist writes the todo list to Yaml file // persist writes the todo list to Yaml file
func (widget *Widget) persist() { func (widget *Widget) persist() {
confDir, _ := wtf.ConfigDir() confDir, _ := wtf.ConfigDir()
filePath := fmt.Sprintf("%s/%s", confDir, widget.FilePath) filePath := fmt.Sprintf("%s/%s", confDir, widget.filePath)
fileData, _ := yaml.Marshal(&widget.list) fileData, _ := yaml.Marshal(&widget.list)

16
wtf.go
View File

@ -138,7 +138,7 @@ var Widgets []wtf.TextViewer
var result = wtf.CreateConfigDir() var result = wtf.CreateConfigDir()
var ( var (
builtat = "now" builtat = time.Now().Format(wtf.TimestampFormat)
version = "dev" version = "dev"
) )
@ -163,7 +163,8 @@ func main() {
Config = wtf.LoadConfigFile(*flagConf) Config = wtf.LoadConfigFile(*flagConf)
wtf.Config = Config app := tview.NewApplication()
pages := tview.NewPages()
bamboohr.Config = Config bamboohr.Config = Config
clocks.Config = Config clocks.Config = Config
@ -179,6 +180,7 @@ func main() {
textfile.Config = Config textfile.Config = Config
todo.Config = Config todo.Config = Config
weather.Config = Config weather.Config = Config
wtf.Config = Config
Widgets = []wtf.TextViewer{ Widgets = []wtf.TextViewer{
bamboohr.NewWidget(), bamboohr.NewWidget(),
@ -193,13 +195,10 @@ func main() {
status.NewWidget(), status.NewWidget(),
system.NewWidget(builtat, version), system.NewWidget(builtat, version),
textfile.NewWidget(), textfile.NewWidget(),
todo.NewWidget(), todo.NewWidget(pages),
weather.NewWidget(), weather.NewWidget(),
} }
app := tview.NewApplication()
app.SetInputCapture(keyboardIntercept)
FocusTracker = wtf.FocusTracker{ FocusTracker = wtf.FocusTracker{
App: app, App: app,
Idx: 0, Idx: 0,
@ -210,7 +209,10 @@ func main() {
go redrawApp(app) go redrawApp(app)
grid := buildGrid(Widgets) grid := buildGrid(Widgets)
if err := app.SetRoot(grid, true).Run(); err != nil { pages.AddPage("grid", grid, true, true)
app.SetInputCapture(keyboardIntercept)
if err := app.SetRoot(pages, true).Run(); err != nil {
os.Exit(1) os.Exit(1)
} }
} }

View File

@ -10,6 +10,11 @@ import (
"github.com/rivo/tview" "github.com/rivo/tview"
) )
const SimpleDateFormat = "Jan 2"
const SimpleTimeFormat = "15:04 MST"
const FriendlyDateTimeFormat = "Mon, Jan 2, 15:04"
const TimestampFormat = "2006-01-02T15:04:05-0700"
func CenterText(str string, width int) string { func CenterText(str string, width int) string {
return fmt.Sprintf("%[1]*s", -width, fmt.Sprintf("%[1]*s", (width+len(str))/2, str)) return fmt.Sprintf("%[1]*s", -width, fmt.Sprintf("%[1]*s", (width+len(str))/2, str))
} }