mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
WTF-484 DigitalOcean module (#782)
* WTF-484 DigitalOcean module stubbed out * WTF-484 Delete droplets via Ctrl-d * WTF-484 Rebasing off master after a long time away * WTF-484 Improve DigitalOcean display * WTF-484 Can shutdown and restart the selected droplet * WTF-484 Display info about the selected droplet using the ? key * WTF-484 Display info about the selected droplet using the Return key * WTF-484 Greatly improve the utils.Truncate function * WTF-484 Display a droplet's features in the info modal * WTF-484 Change reboot key from r to b to not conflict with refresh * WTF-484 Panic if a keyboard control is mapped to the same character more than once * WTF-484 Colorize droplet status indicator * WTF-484 Extract view.InfoTable out into a reusable component
This commit is contained in:
@@ -26,10 +26,10 @@ type Widget struct {
|
||||
view.ScrollableWidget
|
||||
|
||||
app *tview.Application
|
||||
settings *Settings
|
||||
filePath string
|
||||
list checklist.Checklist
|
||||
pages *tview.Pages
|
||||
settings *Settings
|
||||
}
|
||||
|
||||
// NewWidget creates a new instance of a widget
|
||||
@@ -61,27 +61,11 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
|
||||
/* -------------------- Exported Functions -------------------- */
|
||||
|
||||
func (widget *Widget) Refresh() {
|
||||
widget.load()
|
||||
widget.display()
|
||||
}
|
||||
|
||||
func (widget *Widget) SetList(list checklist.Checklist) {
|
||||
widget.list = list
|
||||
}
|
||||
|
||||
// HelpText returns the help text for this widget
|
||||
func (widget *Widget) HelpText() string {
|
||||
return widget.KeyboardWidget.HelpText()
|
||||
}
|
||||
|
||||
/* -------------------- Unexported Functions -------------------- */
|
||||
|
||||
// isItemSelected returns weather any item of the todo is selected or not
|
||||
func (widget *Widget) isItemSelected() bool {
|
||||
|
||||
return widget.Selected >= 0 && widget.Selected < len(widget.list.Items)
|
||||
}
|
||||
|
||||
// SelectedItem returns the currently-selected checklist item or nil if no item is selected
|
||||
func (widget *Widget) SelectedItem() *checklist.ChecklistItem {
|
||||
var selectedItem *checklist.ChecklistItem
|
||||
@@ -92,38 +76,18 @@ func (widget *Widget) SelectedItem() *checklist.ChecklistItem {
|
||||
return selectedItem
|
||||
}
|
||||
|
||||
// updateSelectedItem update the text of the selected item.
|
||||
func (widget *Widget) updateSelectedItem(text string) {
|
||||
selectedItem := widget.SelectedItem()
|
||||
if selectedItem == nil {
|
||||
return
|
||||
}
|
||||
|
||||
selectedItem.Text = text
|
||||
// Refresh updates the data for this widget and displays it onscreen
|
||||
func (widget *Widget) Refresh() {
|
||||
widget.load()
|
||||
widget.display()
|
||||
}
|
||||
|
||||
// updateSelected sets the text of the currently-selected item to the provided text
|
||||
func (widget *Widget) updateSelected() {
|
||||
if !widget.isItemSelected() {
|
||||
return
|
||||
}
|
||||
|
||||
form := widget.modalForm("Edit:", widget.SelectedItem().Text)
|
||||
|
||||
saveFctn := func() {
|
||||
text := form.GetFormItem(0).(*tview.InputField).GetText()
|
||||
|
||||
widget.updateSelectedItem(text)
|
||||
widget.persist()
|
||||
widget.pages.RemovePage("modal")
|
||||
widget.app.SetFocus(widget.View)
|
||||
widget.display()
|
||||
}
|
||||
|
||||
widget.addButtons(form, saveFctn)
|
||||
widget.modalFocus(form)
|
||||
func (widget *Widget) SetList(list checklist.Checklist) {
|
||||
widget.list = list
|
||||
}
|
||||
|
||||
/* -------------------- Unexported Functions -------------------- */
|
||||
|
||||
func (widget *Widget) init() {
|
||||
_, err := cfg.CreateFile(widget.filePath)
|
||||
if err != nil {
|
||||
@@ -131,6 +95,11 @@ func (widget *Widget) init() {
|
||||
}
|
||||
}
|
||||
|
||||
// isItemSelected returns weather any item of the todo is selected or not
|
||||
func (widget *Widget) isItemSelected() bool {
|
||||
return widget.Selected >= 0 && widget.Selected < len(widget.list.Items)
|
||||
}
|
||||
|
||||
// Loads the todo list from3 Yaml file
|
||||
func (widget *Widget) load() {
|
||||
confDir, _ := cfg.WtfConfigDir()
|
||||
@@ -189,6 +158,38 @@ func (widget *Widget) setItemChecks() {
|
||||
}
|
||||
}
|
||||
|
||||
// updateSelected sets the text of the currently-selected item to the provided text
|
||||
func (widget *Widget) updateSelected() {
|
||||
if !widget.isItemSelected() {
|
||||
return
|
||||
}
|
||||
|
||||
form := widget.modalForm("Edit:", widget.SelectedItem().Text)
|
||||
|
||||
saveFctn := func() {
|
||||
text := form.GetFormItem(0).(*tview.InputField).GetText()
|
||||
|
||||
widget.updateSelectedItem(text)
|
||||
widget.persist()
|
||||
widget.pages.RemovePage("modal")
|
||||
widget.app.SetFocus(widget.View)
|
||||
widget.display()
|
||||
}
|
||||
|
||||
widget.addButtons(form, saveFctn)
|
||||
widget.modalFocus(form)
|
||||
}
|
||||
|
||||
// updateSelectedItem update the text of the selected item.
|
||||
func (widget *Widget) updateSelectedItem(text string) {
|
||||
selectedItem := widget.SelectedItem()
|
||||
if selectedItem == nil {
|
||||
return
|
||||
}
|
||||
|
||||
selectedItem.Text = text
|
||||
}
|
||||
|
||||
/* -------------------- Modal Form -------------------- */
|
||||
|
||||
func (widget *Widget) addButtons(form *tview.Form, saveFctn func()) {
|
||||
|
||||
Reference in New Issue
Block a user