
Security News
Bun 1.2.19 Adds Isolated Installs for Better Monorepo Support
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.
github.com/openengineer/go-repl
Lightweight Golang REPL library, inspired by GNU Readline. You provide the Eval
function, and go-repl
does the rest.
Your REPLs that use this library will enjoy the following features:
Eval
Notes:
Fetch this library with the following command:
$ go get -u github.com/openengineer/go-repl
In order to create your own REPL you have to define a type that implements the Handler
interface:
type Handler interface {
Prompt() string
Tab(buffer string) string
Eval(line string) string
}
Here is a complete example (can also be found in ./examples/basic_repl.go
):
package main
import (
"fmt"
"log"
"strconv"
"strings"
repl "github.com/openengineer/go-repl"
)
var helpMessage = `help display this message
add <int> <int> add two numbers
quit quit this program`
// implements repl.Handler interface
type MyHandler struct {
r *repl.Repl
}
func main() {
fmt.Println("Welcome, type \"help\" for more info")
h := &MyHandler{}
h.r = repl.NewRepl(h)
// start the terminal loop
if err := h.r.Loop(); err != nil {
log.Fatal(err)
}
}
func (h *MyHandler) Prompt() string {
return "> "
}
func (h *MyHandler) Tab(buffer string) string {
return "" // do nothing
}
func (h *MyHandler) Eval(line string) string {
fields := strings.Fields(line)
if len(fields) == 0 {
return ""
} else {
cmd, args := fields[0], fields[1:]
switch cmd {
case "help":
return helpMessage
case "add":
if len(args) != 2 {
return "\"add\" expects 2 args"
} else {
return add(args[0], args[1])
}
case "quit":
h.r.Quit()
return ""
default:
return fmt.Sprintf("unrecognized command \"%s\"", cmd)
}
}
}
func add(a_ string, b_ string) string {
a, err := strconv.Atoi(a_)
if err != nil {
return "first arg is not an integer"
}
b, err := strconv.Atoi(b_)
if err != nil {
return "second arg is not an integer"
}
return strconv.Itoa(a + b)
}
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.
Security News
Popular npm packages like eslint-config-prettier were compromised after a phishing attack stole a maintainer’s token, spreading malicious updates.
Security News
/Research
A phishing attack targeted developers using a typosquatted npm domain (npnjs.com) to steal credentials via fake login pages - watch out for similar scams.