Skip to content

Commit

Permalink
fixing prompt issues on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Levinson committed Mar 2, 2018
1 parent d722885 commit 00c3c15
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 184 deletions.
2 changes: 1 addition & 1 deletion cmd/gscript/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func CompileScript(c *cli.Context) error {

func NewScript(c *cli.Context) error {
logger := logrus.New()
logger.Formatter = new(logrus.TextFormatter)
logger.Formatter = new(logging.GSEFormatter)
logger.Out = logging.LogWriter{Name: "compiler"}
if c.NArg() == 0 {
fmt.Printf("%s\n", string(compiler.RetrieveExample()))
Expand Down
7 changes: 7 additions & 0 deletions debug_windows.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/local/bin/bash
set -x
CWD=$(pwd)
cd $GOPATH/src/github.com/gen0cide/gscript/cmd/gscript
go-bindata -pkg compiler -nomemcopy -o $GOPATH/src/github.com/gen0cide/gscript/compiler/bindata.go -prefix '../..' ../../templates/...
GOOS=windows GOARCH=amd64 go build -o $HOME/Public/bin/gscript.exe
cd $CWD
17 changes: 17 additions & 0 deletions debugger/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"

prompt "github.com/c-bata/go-prompt"
"github.com/fatih/color"
"github.com/gen0cide/gscript/compiler"
"github.com/gen0cide/gscript/engine"
"github.com/gen0cide/gscript/logging"
Expand All @@ -18,6 +19,7 @@ import (
type Debugger struct {
Engine *engine.Engine
Logger *logrus.Logger
Prompt *prompt.Prompt
}

func New(name string) *Debugger {
Expand Down Expand Up @@ -101,7 +103,22 @@ func (d *Debugger) InteractiveSession() {
d.SessionExecutor,
d.SessionCompleter,
prompt.OptionPrefix("gscript> "),
prompt.OptionPrefixTextColor(prompt.Red),
prompt.OptionTitle("Genesis Scripting Engine Console"),
)
d.Prompt = p
entryText := []string{
fmt.Sprintf(
"%s %s %s %s",
color.HiWhiteString("***"),
color.HiRedString("GSCRIPT"),
color.YellowString("INTERACTIVE SHELL"),
color.HiWhiteString("***"),
),
fmt.Sprintf("%s %s", color.YellowString("NOTE:"), "To exit the debugger, use CONTROL+D"),
}
for _, l := range entryText {
fmt.Fprintf(color.Output, "%s\n", l)
}
p.Run()
}
76 changes: 76 additions & 0 deletions engine/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"

services "github.com/gen0cide/service-go"
"github.com/matishsiao/goInfo"
ps "github.com/mitchellh/go-ps"
)
Expand Down Expand Up @@ -55,3 +56,78 @@ func FindProcessPid(key string) (int, error) {
}
return pid, err
}

func (e *Engine) InstallSystemService(path, name, displayName, description string) error {
c := &services.Config{
Path: path,
Name: name,
DisplayName: displayName,
Description: description,
}

s, err := services.NewServiceConfig(c)
if err != nil {
return err
}

err = s.Install()
if err != nil {
return err
}

return nil
}

func (e *Engine) StartServiceByName(name string) error {
c := &services.Config{
Name: name,
}

s, err := services.NewServiceConfig(c)
if err != nil {
return err
}

err = s.Start()
if err != nil {
return err
}

return nil
}

func (e *Engine) StopServiceByName(name string) error {
c := &services.Config{
Name: name,
}

s, err := services.NewServiceConfig(c)
if err != nil {
return err
}

err = s.Stop()
if err != nil {
return err
}

return nil
}

func (e *Engine) RemoveServiceByName(name string) error {
c := &services.Config{
Name: name,
}

s, err := services.NewServiceConfig(c)
if err != nil {
return err
}

err = s.Remove()
if err != nil {
return err
}

return nil
}
102 changes: 102 additions & 0 deletions engine/os_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,105 @@ func (e *Engine) VMProcExistsWithName(call otto.FunctionCall) otto.Value {
}
return otto.FalseValue()
}

func (e *Engine) VMInstallSystemService(call otto.FunctionCall) otto.Value {
if len(call.ArgumentList) != 4 {
e.Logger.Errorf("Not enough arguments provided.")
return otto.FalseValue()
}

path, err := call.Argument(0).ToString()
if err != nil {
e.Logger.Errorf("Error converting path to string: %s", err.Error())
return otto.FalseValue()
}

name, err := call.Argument(1).ToString()
if err != nil {
e.Logger.Errorf("Error converting name to string: %s", err.Error())
return otto.FalseValue()
}

displayName, err := call.Argument(2).ToString()
if err != nil {
e.Logger.Errorf("Error converting displayName to string: %s", err.Error())
return otto.FalseValue()
}

description, err := call.Argument(3).ToString()
if err != nil {
e.Logger.Errorf("Error converting description to string: %s", err.Error())
return otto.FalseValue()
}

err = e.InstallSystemService(path, name, displayName, description)
if err != nil {
e.Logger.Errorf("Error installing system service: %s", err.Error())
return otto.FalseValue()
}

return otto.TrueValue()
}

func (e *Engine) VMStartServiceByName(call otto.FunctionCall) otto.Value {
if len(call.ArgumentList) != 1 {
e.Logger.Errorf("Not enough arguments provided.")
return otto.FalseValue()
}

name, err := call.Argument(0).ToString()
if err != nil {
e.Logger.Errorf("Error converting name to string: %s", err.Error())
return otto.FalseValue()
}

err = e.StartServiceByName(name)
if err != nil {
e.Logger.Errorf("Error starting system service: %s", err.Error())
return otto.FalseValue()
}

return otto.TrueValue()
}

func (e *Engine) VMStopServiceByName(call otto.FunctionCall) otto.Value {
if len(call.ArgumentList) != 1 {
e.Logger.Errorf("Not enough arguments provided.")
return otto.FalseValue()
}

name, err := call.Argument(0).ToString()
if err != nil {
e.Logger.Errorf("Error converting name to string: %s", err.Error())
return otto.FalseValue()
}

err = e.StopServiceByName(name)
if err != nil {
e.Logger.Errorf("Error starting system service: %s", err.Error())
return otto.FalseValue()
}

return otto.TrueValue()
}

func (e *Engine) VMRemoveServiceByName(call otto.FunctionCall) otto.Value {
if len(call.ArgumentList) != 1 {
e.Logger.Errorf("Not enough arguments provided.")
return otto.FalseValue()
}

name, err := call.Argument(0).ToString()
if err != nil {
e.Logger.Errorf("Error converting name to string: %s", err.Error())
return otto.FalseValue()
}

err = e.RemoveServiceByName(name)
if err != nil {
e.Logger.Errorf("Error starting system service: %s", err.Error())
return otto.FalseValue()
}

return otto.TrueValue()
}
Loading

0 comments on commit 00c3c15

Please sign in to comment.