chore: formatting

pull/38/head
Devin Singh 2021-04-18 21:09:27 -05:00
parent 04875dc493
commit 94f0ccf9f6
No known key found for this signature in database
GPG Key ID: 7EA319C5D57B6506
3 changed files with 58 additions and 41 deletions

6
lua.go
View File

@ -2,10 +2,10 @@ package main
import ( import (
"fmt" "fmt"
"os"
lfs "hilbish/golibs/fs"
cmds "hilbish/golibs/commander"
hooks "hilbish/golibs/bait" hooks "hilbish/golibs/bait"
cmds "hilbish/golibs/commander"
lfs "hilbish/golibs/fs"
"os"
"github.com/yuin/gopher-lua" "github.com/yuin/gopher-lua"
) )

32
main.go
View File

@ -2,27 +2,30 @@ package main
import ( import (
"fmt" "fmt"
"os"
"os/user"
"os/signal"
"strings"
"io"
hooks "hilbish/golibs/bait" hooks "hilbish/golibs/bait"
"io"
"os"
"os/signal"
"os/user"
"strings"
"github.com/akamensky/argparse" "github.com/akamensky/argparse"
"github.com/bobappleyard/readline" "github.com/bobappleyard/readline"
"github.com/yuin/gopher-lua" lua "github.com/yuin/gopher-lua"
"golang.org/x/term" "golang.org/x/term"
) )
const version = "0.3.2" const version = "0.3.2"
var l *lua.LState var l *lua.LState
// User's prompt, this will get set when lua side is initialized // User's prompt, this will get set when lua side is initialized
var prompt string var prompt string
var multilinePrompt = "> " var multilinePrompt = "> "
// Map of builtin/custom commands defined in the commander lua module // Map of builtin/custom commands defined in the commander lua module
var commands = map[string]bool{} var commands = map[string]bool{}
// Command aliases // Command aliases
var aliases = map[string]string{} var aliases = map[string]string{}
var bait hooks.Bait var bait hooks.Bait
@ -62,7 +65,9 @@ func main() {
} }
// Set $SHELL if the user wants to // Set $SHELL if the user wants to
if *setshflag { os.Setenv("SHELL", os.Args[0]) } if *setshflag {
os.Setenv("SHELL", os.Args[0])
}
// If user's config doesn't exixt, // If user's config doesn't exixt,
if _, err := os.Stat(defaultconfpath); os.IsNotExist(err) { if _, err := os.Stat(defaultconfpath); os.IsNotExist(err) {
@ -108,20 +113,26 @@ func main() {
} }
input = strings.TrimSpace(input) input = strings.TrimSpace(input)
if len(input) == 0 { continue } if len(input) == 0 {
continue
}
if strings.HasSuffix(input, "\\") { if strings.HasSuffix(input, "\\") {
for { for {
input, err = ContinuePrompt(strings.TrimSuffix(input, "\\")) input, err = ContinuePrompt(strings.TrimSuffix(input, "\\"))
if err != nil || !strings.HasSuffix(input, "\\") { break } if err != nil || !strings.HasSuffix(input, "\\") {
break
}
} }
} }
running = true running = true
RunInput(input) RunInput(input)
termwidth, _, err := term.GetSize(0) termwidth, _, err := term.GetSize(0)
if err != nil { continue } if err != nil {
continue
}
fmt.Printf("\u001b[7m∆\u001b[0m" + strings.Repeat(" ", termwidth-1) + "\r") fmt.Printf("\u001b[7m∆\u001b[0m" + strings.Repeat(" ", termwidth-1) + "\r")
} }
} }
@ -175,4 +186,3 @@ func HandleSignals() {
} }
} }
} }

View File

@ -1,11 +1,11 @@
package main package main
import ( import (
"fmt"
"os"
"bufio" "bufio"
"context" "context"
"fmt"
"io" "io"
"os"
"strings" "strings"
"github.com/bobappleyard/readline" "github.com/bobappleyard/readline"
@ -13,7 +13,6 @@ import (
"layeh.com/gopher-luar" "layeh.com/gopher-luar"
"mvdan.cc/sh/v3/interp" "mvdan.cc/sh/v3/interp"
"mvdan.cc/sh/v3/syntax" "mvdan.cc/sh/v3/syntax"
) )
func RunInput(input string) { func RunInput(input string) {
@ -50,7 +49,9 @@ func RunInput(input string) {
fmt.Fprintln(os.Stderr, fmt.Fprintln(os.Stderr,
"Error in command:\n\n"+err.Error()) "Error in command:\n\n"+err.Error())
} }
if cmdArgs[0] != "exit" { HandleHistory(cmdString) } if cmdArgs[0] != "exit" {
HandleHistory(cmdString)
}
return return
} }
@ -61,7 +62,9 @@ func RunInput(input string) {
if syntax.IsIncomplete(err) { if syntax.IsIncomplete(err) {
for { for {
cmdString, err = ContinuePrompt(strings.TrimSuffix(cmdString, "\\")) cmdString, err = ContinuePrompt(strings.TrimSuffix(cmdString, "\\"))
if err != nil { break } if err != nil {
break
}
err = execCommand(cmdString) err = execCommand(cmdString)
if syntax.IsIncomplete(err) || strings.HasSuffix(input, "\\") { if syntax.IsIncomplete(err) || strings.HasSuffix(input, "\\") {
continue continue
@ -76,7 +79,9 @@ func RunInput(input string) {
} else { } else {
if code, ok := interp.IsExitStatus(err); ok { if code, ok := interp.IsExitStatus(err); ok {
bait.Em.Emit("command.exit", code) bait.Em.Emit("command.exit", code)
} else { fmt.Fprintln(os.Stderr, err) } } else {
fmt.Fprintln(os.Stderr, err)
}
} }
} else { } else {
bait.Em.Emit("command.exit", 0) bait.Em.Emit("command.exit", 0)
@ -160,7 +165,9 @@ func HandleHistory(cmd string) {
func StartMultiline(prev string, sb *strings.Builder) bool { func StartMultiline(prev string, sb *strings.Builder) bool {
// sb fromt outside is passed so we can // sb fromt outside is passed so we can
// save input from previous prompts // save input from previous prompts
if sb.String() == "" { sb.WriteString(prev + "\n") } if sb.String() == "" {
sb.WriteString(prev + "\n")
}
fmt.Print(multilinePrompt) fmt.Print(multilinePrompt)