Skip to content

Commit

Permalink
Merge pull request #5 from vinodsr/feature/delete-in-ui
Browse files Browse the repository at this point in the history
Feature/delete in UI
  • Loading branch information
vinodsr authored Mar 21, 2021
2 parents 558f458 + 759b7e3 commit 2192665
Show file tree
Hide file tree
Showing 14 changed files with 251 additions and 95 deletions.
35 changes: 35 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch file",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${file}",
"output": "debug",
},
{
"name": "Connect to server",
"type": "go",
"request": "launch",
"mode": "remote",
"remotePath": "${fileDirname}",
"port": 2345,
"host": "127.0.0.1",
"program": "${fileDirname}",
"env": {},
"args": []
}
{
"name": "Attach to Process",
"type": "go",
"request": "attach",
"mode": "local",
"processId": 20297
}
]
}
21 changes: 0 additions & 21 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
{
"workbench.colorCustomizations": {
"activityBar.activeBackground": "#37e119",
"activityBar.activeBorder": "#536aec",
"activityBar.background": "#37e119",
"activityBar.foreground": "#15202b",
"activityBar.inactiveForeground": "#15202b99",
"activityBarBadge.background": "#536aec",
"activityBarBadge.foreground": "#e7e7e7",
"editorGroup.border": "#37e119",
"panel.border": "#37e119",
"sideBar.border": "#37e119",
"statusBar.background": "#2cb314",
"statusBar.border": "#2cb314",
"statusBar.foreground": "#e7e7e7",
"statusBarItem.hoverBackground": "#37e119",
"titleBar.activeBackground": "#2cb314",
"titleBar.activeForeground": "#e7e7e7",
"titleBar.border": "#2cb314",
"titleBar.inactiveBackground": "#2cb31499",
"titleBar.inactiveForeground": "#e7e7e799"
},
"peacock.color": "#2cb314"
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ go build -o out/ main.go
Create a alias to the run script

```
alias j='source <path to package> /run'
alias j='source <path to package>/alfred'
```


Expand All @@ -71,7 +71,7 @@ To add your commands edit the settings.json
You can also run the add command

```
run add
alfred add
```

Make sure that run is available in the PATH.
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/cli/add/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func Execute() {

if commandAccepted {
newCommand := types.Command{
Context: contextInput,
Context: contextInput + ":",
Program: commandInput,
}
configData.Commands = append(configData.Commands, newCommand)
Expand Down
12 changes: 12 additions & 0 deletions lib/cli/help/help.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package help

import (
"fmt"
)

func Execute() {
fmt.Println("Shell Butler - Help")
fmt.Println(`
add - Add a new command
help - Shows the help screen`)
}
42 changes: 38 additions & 4 deletions lib/runtime/runtime.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package runtime

import (
"encoding/json"
"io/ioutil"
"log"
"os"
"path/filepath"
"sync"

"github.com/vinodsr/shell-butler/lib/config"
types "github.com/vinodsr/shell-butler/lib/types"
)

Expand Down Expand Up @@ -46,9 +52,37 @@ func (rt *Runtime) GetContextDS() []string {
}

// Init initializes
func (rt *Runtime) Init(configData types.ConfigData, commandMap map[string]string, contextDataSource []string) {
rt.configData = configData
rt.commandMap = commandMap
func (rt *Runtime) Init() {

dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
log.Fatal(err)
}

dir, _ = os.UserHomeDir()
configFile := dir + "/.butler/settings.json"
dat, err := ioutil.ReadFile(configFile)
if err != nil {
initStruct := types.ConfigData{
Commands: []types.Command{{
Context: "Help",
Program: "echo Edit " + configFile + " to add more commands",
}},
}
//fmt.Printf("%+v\n", initStruct)
//os.Exit(0)
config.WriteConfig(initStruct)
rt.configData = initStruct
}

json.Unmarshal([]byte(string(dat)), &rt.configData)

rt.initialized = true
rt.contextDataSource = contextDataSource
rt.commandMap = make(map[string]string)
rt.contextDataSource = nil
for _, command := range rt.configData.Commands {
// splits := strings.Split(command.Context, ":")
rt.contextDataSource = append(rt.contextDataSource, command.Context)
rt.commandMap[command.Context] = command.Program
}
}
38 changes: 38 additions & 0 deletions lib/ui/confirmbox.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package ui

import (
ui "github.com/gizak/termui/v3"
"github.com/gizak/termui/v3/widgets"
)

func ConfirmBox(msg string, uiEvents <-chan ui.Event) bool {

alertBox := widgets.NewParagraph()
alertBox.Title = "Alert"
alertBox.Text = msg + " [y/n] "
termWidth, termHeight := ui.TerminalDimensions()
alertBox.SetRect((termWidth/2)-40, (termHeight/2)-2, (termWidth/2)+40, (termHeight/2)+2)
alertBox.TextStyle.Fg = ui.ColorRed
alertBox.BorderStyle.Fg = ui.ColorRed
ret := true
//fmt.Println(msg)
ui.Render(alertBox)
loop := true
for loop {
e := <-uiEvents

switch e.ID {
case "n", "N":
loop = false
ret = false
break
case "y", "Y":
loop = false
ret = true
break
}
ui.Render(alertBox)

}
return ret
}
Loading

0 comments on commit 2192665

Please sign in to comment.