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:
parent
53d2fdacda
commit
351f5100bc
@ -16,8 +16,22 @@ import (
|
|||||||
var Config *config.Config
|
var Config *config.Config
|
||||||
|
|
||||||
const helpText = `
|
const helpText = `
|
||||||
h: Displays the help text. o: Opens the todo file in the operating system.
|
Keyboard commands for Todo:
|
||||||
space: Checks an item on or off
|
|
||||||
|
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 {
|
type Widget struct {
|
||||||
@ -81,22 +95,6 @@ func (widget *Widget) editItem() {
|
|||||||
widget.modalFocus(form)
|
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() {
|
func (widget *Widget) init() {
|
||||||
_, err := wtf.CreateFile(widget.filePath)
|
_, err := wtf.CreateFile(widget.filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -114,7 +112,7 @@ func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
|||||||
return nil
|
return nil
|
||||||
case "h":
|
case "h":
|
||||||
// Show help menu
|
// Show help menu
|
||||||
widget.help()
|
widget.showHelp()
|
||||||
return nil
|
return nil
|
||||||
case "j":
|
case "j":
|
||||||
// Select the next item down
|
// Select the next item down
|
||||||
@ -188,20 +186,6 @@ func (widget *Widget) load() {
|
|||||||
yaml.Unmarshal(fileData, &widget.list)
|
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() {
|
func (widget *Widget) newItem() {
|
||||||
form := widget.modalForm("New:", "")
|
form := widget.modalForm("New:", "")
|
||||||
|
|
||||||
@ -219,6 +203,27 @@ func (widget *Widget) newItem() {
|
|||||||
widget.modalFocus(form)
|
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 -------------------- */
|
/* -------------------- Modal Form -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) addButtons(form *tview.Form, saveFctn func()) {
|
func (widget *Widget) addButtons(form *tview.Form, saveFctn func()) {
|
||||||
|
29
wtf/billboard_modal.go
Normal file
29
wtf/billboard_modal.go
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package wtf
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gdamore/tcell"
|
||||||
|
"github.com/rivo/tview"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewBillboardModal(text string) *tview.Frame {
|
||||||
|
textView := tview.NewTextView()
|
||||||
|
textView.SetWrap(true)
|
||||||
|
textView.SetText(text)
|
||||||
|
|
||||||
|
textView.SetBackgroundColor(tview.Styles.ContrastBackgroundColor)
|
||||||
|
|
||||||
|
thing := tview.NewFrame(textView)
|
||||||
|
|
||||||
|
drawFunc := func(screen tcell.Screen, x, y, width, height int) (int, int, int, int) {
|
||||||
|
w, h := screen.Size()
|
||||||
|
thing.SetRect((w/2)-40, (h/2)-11, 80, 22)
|
||||||
|
return x, y, width, height
|
||||||
|
}
|
||||||
|
|
||||||
|
thing.SetBackgroundColor(tview.Styles.ContrastBackgroundColor)
|
||||||
|
thing.SetBorder(true)
|
||||||
|
thing.SetBorders(1, 1, 0, 0, 1, 1)
|
||||||
|
thing.SetDrawFunc(drawFunc)
|
||||||
|
|
||||||
|
return thing
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user