Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update gomacro prompts #63

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions base/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"io"
"os"
r "reflect"
"runtime"
"strings"

"github.com/cosmos72/gomacro/base/reflect"
Expand Down Expand Up @@ -66,6 +67,9 @@ type Globals struct {
MacroChar rune // prefix for macro-related keywords macro, quote, quasiquote, splice... The default is '~'
ReplCmdChar byte // prefix for special REPL commands env, help, inspect, quit, unload... The default is ':'
Inspector Inspector
GoVersion string
GoOS string
GoArch string
}

func NewGlobals() *Globals {
Expand All @@ -86,11 +90,14 @@ func NewGlobals() *Globals {
Imports: nil,
Declarations: nil,
Statements: nil,
Prompt: "gomacro> ",
Prompt: "gomacro [In]: ",
GensymN: 0,
ParserMode: 0,
MacroChar: '~',
ReplCmdChar: ':', // Jupyter and gophernotes would probably set this to '%'
GoVersion: runtime.Version(),
GoOS: runtime.GOOS,
GoArch: runtime.GOARCH,
}
g.Importer = genimport.DefaultImporter(&g.Output)
return g
Expand Down Expand Up @@ -186,11 +193,11 @@ func (g *Globals) Print(values []r.Value, types []xr.Type) {
} else {
ti = reflect.Type(vi)
}
g.Fprintf(g.Stdout, "%v\t// %v\n", vi, ti)
g.Fprintf(g.Stdout, " [Out]: %v\t// %v\n\n", vi, ti)
}
} else {
for _, vi := range values {
g.Fprintf(g.Stdout, "%v\n", vi)
g.Fprintf(g.Stdout, " [Out]: %v\n", vi)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions base/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func ReadMultiline(in Readline, opts ReadOptions, prompt string) (src string, fi
m = mNormal
}
if optPrompt {
currPrompt = makeDots(9 + 2*paren)
currPrompt = makeDots(14 + 2*paren)
}
}
if err != nil {
Expand Down Expand Up @@ -413,7 +413,7 @@ func lastIsKeywordIgnoresNl(line []byte, first, last int) bool {

func makeDots(count int) string {
const (
dots = ". . . . "
dots = " ....: "
spaces = " "
ndots = len(dots)
nspaces = len(spaces)
Expand Down
14 changes: 7 additions & 7 deletions classic/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ var historyfile = paths.Subdir(paths.UserHomeDir(), ".gomacro_history")
func (ir *Interp) ReplStdin() {
g := ir.Globals
if g.Options&OptShowPrompt != 0 {
fmt.Fprintf(ir.Stdout, `// GOMACRO, an interactive Go interpreter with macros <https://github.com/cosmos72/gomacro>
// Copyright (C) 2017-2019 Massimiliano Ghilardi
// License MPL v2.0+: Mozilla Public License version 2.0 or later <http://mozilla.org/MPL/2.0/>
// This is free software with ABSOLUTELY NO WARRANTY.
//
// Type %chelp for help
`, g.ReplCmdChar)
fmt.Fprintf(ir.Stdout, `Go version %s (%s, %s)
Type %ccopyright or %clicense for more information
GOMACRO ---- interactive Go interpreter with generics and macros

Type %chelp for help

`, g.GoVersion, g.GoOS, g.GoArch, g.ReplCmdChar, g.ReplCmdChar, g.ReplCmdChar)
}
tty, _ := MakeTtyReadline(historyfile)
defer tty.Close(historyfile) // restore normal tty mode
Expand Down
19 changes: 19 additions & 0 deletions fast/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,22 @@ func (cmds Cmds) ShowHelp(g *base.Globals) {
g.Fprintf(out, "%s", "// abbreviations are allowed if unambiguous.\n")
}

func (cmds Cmds) ShowMessage(g *base.Globals, msg string) {
out := g.Stdout
g.Fprintf(out, "%s", msg)
}

var Commands Cmds

func init() {
Commands.m = map[byte][]Cmd{
'c': []Cmd{{"copyright", (*Interp).cmdCopyright, `copyright show copyright`}},
'd': []Cmd{{"debug", (*Interp).cmdDebug, `debug EXPR debug expression or statement interactively`}},
'e': []Cmd{{"env", (*Interp).cmdEnv, `env [NAME] show available functions, variables and constants
in current package, or from imported package NAME`}},
'h': []Cmd{{"help", (*Interp).cmdHelp, `help show this help`}},
'i': []Cmd{{"inspect", (*Interp).cmdInspect, `inspect EXPR inspect expression interactively`}},
'l': []Cmd{{"license", (*Interp).cmdLicense, `license show license`}},
'o': []Cmd{{"options", (*Interp).cmdOptions, `options [OPTS] show or toggle interpreter options`}},
'p': []Cmd{{"package", (*Interp).cmdPackage, `package "PKGPATH" switch to package PKGPATH, importing it if possible`}},
'q': []Cmd{{"quit", (*Interp).cmdQuit, `quit quit the interpreter`}},
Expand Down Expand Up @@ -337,6 +344,18 @@ func (ir *Interp) cmdHelp(arg string, opt base.CmdOpt) (string, base.CmdOpt) {
return "", opt
}

func (ir *Interp) cmdCopyright(arg string, opt base.CmdOpt) (string, base.CmdOpt) {
copyright := "Copyright (C) 2018-2019 Massimiliano Ghilardi <https://github.com/cosmos72/gomacro>\nThis is free software with ABSOLUTELY NO WARRANTY.\n"
Commands.ShowMessage(&ir.Comp.Globals, copyright)
return "", opt
}

func (ir *Interp) cmdLicense(arg string, opt base.CmdOpt) (string, base.CmdOpt) {
license := "License MPL v2.0+: Mozilla Public License version 2.0 or later <http://mozilla.org/MPL/2.0/>\n"
Commands.ShowMessage(&ir.Comp.Globals, license)
return "", opt
}

func (ir *Interp) cmdInspect(arg string, opt base.CmdOpt) (string, base.CmdOpt) {
g := &ir.Comp.Globals
if len(arg) == 0 {
Expand Down
2 changes: 1 addition & 1 deletion fast/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func newTopInterp(path string) *Interp {
KnownImports: make(map[string]*Import),
interf2proxy: make(map[r.Type]r.Type),
proxy2interf: make(map[r.Type]xr.Type),
Prompt: "gomacro> ",
Prompt: "gomacro [In]: ",
Jit: NewJit(),
}

Expand Down
14 changes: 7 additions & 7 deletions fast/repl.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,13 @@ func (ir *Interp) ReplStdin() {
g := ir.Comp.CompGlobals

if g.Options&OptShowPrompt != 0 {
g.Fprintf(g.Stdout, `// GOMACRO, an interactive Go interpreter with generics and macros
// Copyright (C) 2018-2019 Massimiliano Ghilardi <https://github.com/cosmos72/gomacro>
// License MPL v2.0+: Mozilla Public License version 2.0 or later <http://mozilla.org/MPL/2.0/>
// This is free software with ABSOLUTELY NO WARRANTY.
//
// Type %chelp for help
`, g.ReplCmdChar)
g.Fprintf(g.Stdout, `Go version %s (%s, %s)
Type %ccopyright or %clicense for more information
GOMACRO ---- interactive Go interpreter with generics and macros

Type %chelp for help

`, g.GoVersion, g.GoOS, g.GoArch, g.ReplCmdChar, g.ReplCmdChar, g.ReplCmdChar)
}
tty, _ := MakeTtyReadline(historyfile)
defer tty.Close(historyfile) // restore normal tty mode
Expand Down