Skip to content

Commit

Permalink
feat: gofumpt for strict formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
itschip committed Sep 18, 2022
1 parent 84f17bd commit f790b36
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 193 deletions.
180 changes: 88 additions & 92 deletions cui_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ func nextView(g *gocui.Gui, v *gocui.View) error {
return err
}


func cursorDown(g *gocui.Gui, v *gocui.View) error {
if v != nil {
cx, cy := v.Cursor()
Expand Down Expand Up @@ -54,20 +53,20 @@ func onSideEnter(g *gocui.Gui, v *gocui.View) error {
return err
}

go func() {
g.Update(func(g *gocui.Gui) error {
v, err := g.View(StatusView)
if err != nil {
return err
}
go func() {
g.Update(func(g *gocui.Gui) error {
v, err := g.View(StatusView)
if err != nil {
return err
}

v.Clear()
fmt.Fprintln(v, "Server running")
v.FgColor = gocui.ColorGreen
v.Clear()
fmt.Fprintln(v, "Server running")
v.FgColor = gocui.ColorGreen

return nil
})
}()
return nil
})
}()

startFxServer(profile, g)

Expand All @@ -81,24 +80,23 @@ func executeCommand(g *gocui.Gui, v *gocui.View) error {
log.Fatal(err)
}

if v.Buffer() == "quit" {
io.WriteString(Writer, v.Buffer())
v.Clear()
vM, _ := g.View(FXServerView)
vM.Clear()
g.Update(func(g *gocui.Gui) error {
return nil
})
g.SetCurrentView(ServersView)

return nil
}
if v.Buffer() == "quit" {
io.WriteString(Writer, v.Buffer())
v.Clear()
vM, _ := g.View(FXServerView)
vM.Clear()
g.Update(func(g *gocui.Gui) error {
return nil
})
g.SetCurrentView(ServersView)

return nil
}

if v.Buffer() != "" {
io.WriteString(Writer, v.Buffer())
}



v.Clear()
v.SetCursor(0, 0)

Expand All @@ -110,81 +108,79 @@ func executeCommand(g *gocui.Gui, v *gocui.View) error {
}

func saveNewProfile(g *gocui.Gui, v *gocui.View) error {
var err error
v.Rewind()
if err != nil {
log.Fatal(err)
}

if v.Buffer() != "" {
ServerPath = v.Buffer()

err = g.DeleteView("profile_path")
if err != nil {
return err
}
}

if _, err := g.SetCurrentView(ServersView); err != nil {
return err
}
return nil
}
var err error
v.Rewind()
if err != nil {
log.Fatal(err)
}

func newProfileNameView(g *gocui.Gui, v *gocui.View) error {
maxX, maxY := g.Size()
if v.Buffer() != "" {
ServerPath = v.Buffer()

err = g.DeleteView("profile_path")
if err != nil {
return err
}
}

if vp_n, err := g.SetView("profile_name", maxX/2-30, maxY/2, maxX/2+30, maxY/2+2); err != nil {
if err != gocui.ErrUnknownView {
return err
}
if _, err := g.SetCurrentView(ServersView); err != nil {
return err
}
return nil
}

vp_n.Title = "Add server name - Enter to continue | Abort with q "
vp_n.BgColor = gocui.ColorBlack
vp_n.Editable = true
}
func newProfileNameView(g *gocui.Gui, v *gocui.View) error {
maxX, maxY := g.Size()

if vp_n, err := g.SetView("profile_name", maxX/2-30, maxY/2, maxX/2+30, maxY/2+2); err != nil {
if err != gocui.ErrUnknownView {
return err
}

if _, err := g.SetCurrentView("profile_name"); err != nil {
return err
}
vp_n.Title = "Add server name - Enter to continue | Abort with q "
vp_n.BgColor = gocui.ColorBlack
vp_n.Editable = true
}

if _, err := g.SetCurrentView("profile_name"); err != nil {
return err
}

return nil
return nil
}

func newProfilePathView(g *gocui.Gui, v *gocui.View) error {
var err error
v.Rewind()
if err != nil {
log.Fatal(err)
}
var err error
v.Rewind()
if err != nil {
log.Fatal(err)
}

if v.Buffer() != "" {
ServerName = v.Buffer()
}

maxX, maxY := g.Size()

if vp_p, err := g.SetView("profile_path", maxX/2-30, maxY/2, maxX/2+30, maxY/2+2); err != nil {
if err != gocui.ErrUnknownView {
return err
}

vp_p.Title = "Add startup path - Enter to finish | Abort with q "
vp_p.BgColor = gocui.ColorBlack
vp_p.Editable = true
}

if _, err := g.SetCurrentView("profile_path"); err != nil {
return err
}

// delete profile_name view
err = g.DeleteView("profile_name")
if err != nil {
return err
}
return nil
ServerName = v.Buffer()
}

maxX, maxY := g.Size()

if vp_p, err := g.SetView("profile_path", maxX/2-30, maxY/2, maxX/2+30, maxY/2+2); err != nil {
if err != gocui.ErrUnknownView {
return err
}

vp_p.Title = "Add startup path - Enter to finish | Abort with q "
vp_p.BgColor = gocui.ColorBlack
vp_p.Editable = true
}

if _, err := g.SetCurrentView("profile_path"); err != nil {
return err
}

// delete profile_name view
err = g.DeleteView("profile_name")
if err != nil {
return err
}

return nil
}
31 changes: 15 additions & 16 deletions files.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,24 @@ import (

func getConfigValues() {
viper.SetConfigName("config")
viper.SetConfigType("yaml")
// Win
viper.AddConfigPath("$HOME/.lazyfivem/")
viper.AddConfigPath("~/.lazyfivem/")

err := viper.ReadInConfig()
if err != nil {
panic(fmt.Errorf("Failed to load lazyfivem config: %w", err))
}
viper.SetConfigType("yaml")
// Win
viper.AddConfigPath("$HOME/.lazyfivem/")
viper.AddConfigPath("~/.lazyfivem/")

err := viper.ReadInConfig()
if err != nil {
panic(fmt.Errorf("Failed to load lazyfivem config: %w", err))
}
}

func getAllServers() {
keys := viper.AllKeys()
keys := viper.AllKeys()

for _, k := range keys {
serverName := strings.ToUpper(k)
serverPath := viper.Get(k)
for _, k := range keys {
serverName := strings.ToUpper(k)
serverPath := viper.Get(k)

Servers[serverName] = serverPath.(string)
}
Servers[serverName] = serverPath.(string)
}
}

42 changes: 21 additions & 21 deletions fxserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,25 @@ func updateFxServer(g *gocui.Gui, line string) {
}

func startFxServer(profile string, g *gocui.Gui) {
path := Servers[profile]
os := runtime.GOOS
switch os {
case "windows":
CfxCmd = exec.Command(path)
case "linux":
CfxCmd = exec.Command("bash", "-c", path)
}
Writer, _ = CfxCmd.StdinPipe()

r, _ := CfxCmd.StdoutPipe()

CfxCmd.Stderr = CfxCmd.Stdout
Scanner = *bufio.NewScanner(r)

go listen(g, &Scanner)

err := CfxCmd.Start()
if err != nil {
panic(err)
}
path := Servers[profile]
os := runtime.GOOS
switch os {
case "windows":
CfxCmd = exec.Command(path)
case "linux":
CfxCmd = exec.Command("bash", "-c", path)
}
Writer, _ = CfxCmd.StdinPipe()

r, _ := CfxCmd.StdoutPipe()

CfxCmd.Stderr = CfxCmd.Stdout
Scanner = *bufio.NewScanner(r)

go listen(g, &Scanner)

err := CfxCmd.Start()
if err != nil {
panic(err)
}
}
22 changes: 10 additions & 12 deletions keybinds.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (

"github.com/jroimartin/gocui"
)

Expand Down Expand Up @@ -40,20 +39,19 @@ func keybinds(g *gocui.Gui) error {
return err
}

/* I need to add some better functionality for this. Config files for now.
/* I need to add some better functionality for this. Config files for now.
if err := g.SetKeybinding("side", 'n', gocui.ModNone, newProfileNameView); err != nil {
return err
}
if err := g.SetKeybinding("side", 'n', gocui.ModNone, newProfileNameView); err != nil {
return err
}
if err := g.SetKeybinding("profile_name", gocui.KeyEnter, gocui.ModNone, newProfilePathView); err != nil {
return err
}
if err := g.SetKeybinding("profile_name", gocui.KeyEnter, gocui.ModNone, newProfilePathView); err != nil {
return err
}
if err := g.SetKeybinding("profile_path", gocui.KeyEnter, gocui.ModNone, saveNewProfile); err != nil {
return err
} */
if err := g.SetKeybinding("profile_path", gocui.KeyEnter, gocui.ModNone, saveNewProfile); err != nil {
return err
} */

return nil
}
Loading

0 comments on commit f790b36

Please sign in to comment.