mirror of
				https://github.com/taigrr/wtf
				synced 2025-01-18 04:03:14 -08:00 
			
		
		
		
	WIP Very rudimentary modal showing up
This commit is contained in:
		
							parent
							
								
									4727255df6
								
							
						
					
					
						commit
						6ccdbabec9
					
				@ -39,7 +39,7 @@ func (widget *Widget) openPRs(repo *GithubRepo, username string) string {
 | 
				
			|||||||
		user := *pr.User
 | 
							user := *pr.User
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if *user.Login == username {
 | 
							if *user.Login == username {
 | 
				
			||||||
			str = str + fmt.Sprintf(" [green]%d[white] %s\n", *pr.Number, *pr.Title)
 | 
								str = str + fmt.Sprintf(" [green]%4d[white] %s\n", *pr.Number, *pr.Title)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -15,6 +15,15 @@ import (
 | 
				
			|||||||
// 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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const helpText = `
 | 
				
			||||||
 | 
						Todo
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						h - Displays the help text
 | 
				
			||||||
 | 
						o - Opens the todo file in the operating system
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						space - checks an item on or off
 | 
				
			||||||
 | 
					`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Widget struct {
 | 
					type Widget struct {
 | 
				
			||||||
	wtf.TextWidget
 | 
						wtf.TextWidget
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -76,21 +85,17 @@ func (widget *Widget) editItem() {
 | 
				
			|||||||
	widget.modalFocus(form)
 | 
						widget.modalFocus(form)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (widget *Widget) newItem() {
 | 
					func (widget *Widget) help() {
 | 
				
			||||||
	form := widget.modalForm("New:", "")
 | 
						cancelFn := func() {
 | 
				
			||||||
 | 
							widget.pages.RemovePage("billboard")
 | 
				
			||||||
	saveFctn := func() {
 | 
					 | 
				
			||||||
		text := form.GetFormItem(0).(*tview.InputField).GetText()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		widget.list.Add(text)
 | 
					 | 
				
			||||||
		widget.persist()
 | 
					 | 
				
			||||||
		widget.pages.RemovePage("modal")
 | 
					 | 
				
			||||||
		widget.app.SetFocus(widget.View)
 | 
							widget.app.SetFocus(widget.View)
 | 
				
			||||||
		widget.display()
 | 
							widget.display()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	widget.addButtons(form, saveFctn)
 | 
						billboard := wtf.NewBillboardModal(helpText, cancelFn)
 | 
				
			||||||
	widget.modalFocus(form)
 | 
					
 | 
				
			||||||
 | 
						widget.pages.AddPage("billboard", billboard, false, true)
 | 
				
			||||||
 | 
						widget.app.SetFocus(billboard)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (widget *Widget) init() {
 | 
					func (widget *Widget) init() {
 | 
				
			||||||
@ -110,7 +115,7 @@ func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
 | 
				
			|||||||
		return nil
 | 
							return nil
 | 
				
			||||||
	case "h":
 | 
						case "h":
 | 
				
			||||||
		// Show help menu
 | 
							// Show help menu
 | 
				
			||||||
		fmt.Println("HELP!")
 | 
							widget.help()
 | 
				
			||||||
		return nil
 | 
							return nil
 | 
				
			||||||
	case "j":
 | 
						case "j":
 | 
				
			||||||
		// Select the next item down
 | 
							// Select the next item down
 | 
				
			||||||
@ -198,6 +203,23 @@ func (widget *Widget) persist() {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (widget *Widget) newItem() {
 | 
				
			||||||
 | 
						form := widget.modalForm("New:", "")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						saveFctn := func() {
 | 
				
			||||||
 | 
							text := form.GetFormItem(0).(*tview.InputField).GetText()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							widget.list.Add(text)
 | 
				
			||||||
 | 
							widget.persist()
 | 
				
			||||||
 | 
							widget.pages.RemovePage("modal")
 | 
				
			||||||
 | 
							widget.app.SetFocus(widget.View)
 | 
				
			||||||
 | 
							widget.display()
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						widget.addButtons(form, saveFctn)
 | 
				
			||||||
 | 
						widget.modalFocus(form)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* -------------------- Modal Form -------------------- */
 | 
					/* -------------------- Modal Form -------------------- */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (widget *Widget) addButtons(form *tview.Form, saveFctn func()) {
 | 
					func (widget *Widget) addButtons(form *tview.Form, saveFctn func()) {
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										45
									
								
								wtf/billboard_modal.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								wtf/billboard_modal.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,45 @@
 | 
				
			|||||||
 | 
					package wtf
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"github.com/gdamore/tcell"
 | 
				
			||||||
 | 
						"github.com/rivo/tview"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type BillboardModal struct{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func NewBillboardModal(text string, cancelFn func()) *tview.Frame {
 | 
				
			||||||
 | 
						modal := BillboardModal{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						frame := modal.build(cancelFn)
 | 
				
			||||||
 | 
						frame.AddText(text, false, tview.AlignLeft, tcell.ColorWhite)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return frame
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* -------------------- Unexported Functions -------------------- */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (modal *BillboardModal) build(cancelFn func()) *tview.Frame {
 | 
				
			||||||
 | 
						form := modal.buildForm(cancelFn)
 | 
				
			||||||
 | 
						frame := modal.buildFrame(form)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return frame
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (modal *BillboardModal) buildForm(cancelFn func()) *tview.Form {
 | 
				
			||||||
 | 
						form := tview.NewForm().
 | 
				
			||||||
 | 
							SetButtonsAlign(tview.AlignCenter).
 | 
				
			||||||
 | 
							SetButtonTextColor(tview.Styles.PrimaryTextColor)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						form.AddButton("Cancel", cancelFn)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return form
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (modal *BillboardModal) buildFrame(form *tview.Form) *tview.Frame {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						frame := tview.NewFrame(form).SetBorders(0, 0, 0, 0, 0, 0)
 | 
				
			||||||
 | 
						frame.SetBorder(true)
 | 
				
			||||||
 | 
						frame.SetRect(20, 20, 80, 20)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return frame
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user