-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
88 lines (72 loc) · 2.87 KB
/
main.go
File metadata and controls
88 lines (72 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"sync"
createreactapp "github.com/harshalranjhani/go-furnace/boilerplates/create-react-app"
"github.com/harshalranjhani/go-furnace/boilerplates/electron"
nestjs "github.com/harshalranjhani/go-furnace/boilerplates/nest-js"
nodejswithmongo "github.com/harshalranjhani/go-furnace/boilerplates/nodejs-with-mongo"
"github.com/rivo/tview"
)
var selectedItems map[string]bool
var selectedItemsText *tview.TextView
var wg *sync.WaitGroup
var optionsMap = map[string]func(){
"CRA - Javascript": func() { createreactapp.CreateReactApp("go-furnace", false, wg) },
"CRA - Typescript": func() { createreactapp.CreateReactApp("go-furnace-ts", true, wg) },
"Nodejs With MongoDB": func() { nodejswithmongo.CreateNodeJsWithMongo(wg) },
"Nest.js": func() { nestjs.CreateNestApp("go-furance-nest-js", wg) },
"Electron": func() { electron.CreateElectronApp(wg) },
}
func executeSelected(wg *sync.WaitGroup) {
for item, selected := range selectedItems {
wg.Add(1)
if selected {
go optionsMap[item]()
}
}
}
func main() {
app := tview.NewApplication()
wg = &sync.WaitGroup{}
selectedItemsText = tview.NewTextView().
SetText("Selected Items:\n").
SetTextAlign(tview.AlignLeft).
SetDynamicColors(true)
list := tview.NewList().
AddItem("CRA - Javascript", "Create React App Boilerplate with Javascript template.", 'a', func() { toggleItem("CRA - Javascript") }).
AddItem("CRA - Typescript", "Create React App Boilerplate with Typescript template.", 'b', func() { toggleItem("CRA - Typescript") }).
AddItem("Electron", "Create Electron project template.", 'c', func() { toggleItem("Electron") }).
// AddItem("Nest.js", "Create Nest.js project template.", 'c', func() { toggleItem("Nest.js") }).
// AddItem("Nodejs with MongoDB", "Nodejs boilerplate with MongoDB setup running on localhost:8080", 'c', func() { toggleItem("Nodejs with MongoDB") }).
AddItem("Execute", "Execute the selected commands", 'd', func() {
executeSelected(wg)
}).
AddItem("Quit", "Press to exit", 'q', func() {
app.Stop()
})
flex := tview.NewFlex().
SetDirection(tview.FlexRow).
AddItem(list, 0, 1, true).
AddItem(selectedItemsText, 0, 1, false) // The last item should not grow with the size of the screen.
selectedItems = make(map[string]bool)
if err := app.SetRoot(flex, true).SetFocus(list).Run(); err != nil {
panic(err)
}
wg.Wait()
}
func toggleItem(item string) {
if selected, exists := selectedItems[item]; exists {
selectedItems[item] = !selected // Toggle the selection
} else {
selectedItems[item] = true // If not selected, mark it as selected
}
showSelectedOptions(selectedItems)
}
func showSelectedOptions(selectedItems map[string]bool) {
selectedItemsText.SetText("Selected Items:\n")
for item, selected := range selectedItems {
if selected {
selectedItemsText.SetText(selectedItemsText.GetText(true) + item + "\n")
}
}
}