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

Closer to having a help modal. Text is showing onscreen (badly)

This commit is contained in:
Chris Cummer
2018-05-03 15:49:06 -07:00
parent 53d2fdacda
commit 351f5100bc
2 changed files with 67 additions and 33 deletions

View File

@@ -16,8 +16,22 @@ import (
var Config *config.Config
const helpText = `
h: Displays the help text. o: Opens the todo file in the operating system.
space: Checks an item on or off
Keyboard commands for Todo:
h: Displays the help text
j: Select the next item in the list
k: Select the previous item in the list
n: Create a new list item
o: Open the todo file in the operating system
arrow down: Select the next item in the list
arrow up: Select the previous item in the list
ctrl-d: delete selected item
esc: Unselect the todo list
return: Edit selected item
space: Check the selected item on or off
`
type Widget struct {
@@ -81,22 +95,6 @@ func (widget *Widget) editItem() {
widget.modalFocus(form)
}
func (widget *Widget) help() {
cancelFn := func(idx int, label string) {
widget.pages.RemovePage("help")
widget.app.SetFocus(widget.View)
widget.display()
}
helpModal := tview.NewModal()
helpModal.SetText(helpText)
helpModal.AddButtons([]string{"Close"})
helpModal.SetDoneFunc(cancelFn)
widget.pages.AddPage("help", helpModal, false, true)
widget.app.SetFocus(helpModal)
}
func (widget *Widget) init() {
_, err := wtf.CreateFile(widget.filePath)
if err != nil {
@@ -114,7 +112,7 @@ func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
return nil
case "h":
// Show help menu
widget.help()
widget.showHelp()
return nil
case "j":
// Select the next item down
@@ -188,20 +186,6 @@ func (widget *Widget) load() {
yaml.Unmarshal(fileData, &widget.list)
}
// persist writes the todo list to Yaml file
func (widget *Widget) persist() {
confDir, _ := wtf.ConfigDir()
filePath := fmt.Sprintf("%s/%s", confDir, widget.filePath)
fileData, _ := yaml.Marshal(&widget.list)
err := ioutil.WriteFile(filePath, fileData, 0644)
if err != nil {
panic(err)
}
}
func (widget *Widget) newItem() {
form := widget.modalForm("New:", "")
@@ -219,6 +203,27 @@ func (widget *Widget) newItem() {
widget.modalFocus(form)
}
// persist writes the todo list to Yaml file
func (widget *Widget) persist() {
confDir, _ := wtf.ConfigDir()
filePath := fmt.Sprintf("%s/%s", confDir, widget.filePath)
fileData, _ := yaml.Marshal(&widget.list)
err := ioutil.WriteFile(filePath, fileData, 0644)
if err != nil {
panic(err)
}
}
func (widget *Widget) showHelp() {
modal := wtf.NewBillboardModal(helpText)
widget.pages.AddPage("help", modal, false, true)
widget.app.SetFocus(modal)
}
/* -------------------- Modal Form -------------------- */
func (widget *Widget) addButtons(form *tview.Form, saveFctn func()) {