present.go -> control.go
This commit is contained in:
+59
@@ -0,0 +1,59 @@
|
||||
// preset.go
|
||||
package expr
|
||||
|
||||
import "strings"
|
||||
|
||||
// Preset control variables
|
||||
const (
|
||||
control_last_result = "_last"
|
||||
control_bool_shortcut = "_bool_shortcut"
|
||||
control_import_path = "_import_path"
|
||||
)
|
||||
|
||||
// Other control variables
|
||||
const (
|
||||
control_export_all = "_export_all"
|
||||
)
|
||||
|
||||
// Initial values
|
||||
const (
|
||||
init_import_path = "~/.local/lib/go-pkg/expr:/usr/local/lib/go-pkg/expr:/usr/lib/go-pkg/expr"
|
||||
)
|
||||
|
||||
func initDefaultVars(ctx exprContext) {
|
||||
ctx.SetVar(control_bool_shortcut, true)
|
||||
ctx.SetVar(control_import_path, init_import_path)
|
||||
}
|
||||
|
||||
func enable(ctx exprContext, name string) {
|
||||
if strings.HasPrefix(name, "_") {
|
||||
ctx.SetVar(name, true)
|
||||
} else {
|
||||
ctx.SetVar("_"+name, true)
|
||||
}
|
||||
}
|
||||
|
||||
func disable(ctx exprContext, name string) {
|
||||
if strings.HasPrefix(name, "_") {
|
||||
ctx.SetVar(name, false)
|
||||
} else {
|
||||
ctx.SetVar("_"+name, false)
|
||||
}
|
||||
}
|
||||
|
||||
func isEnabled(ctx exprContext, name string) (status bool) {
|
||||
if v, exists := ctx.GetVar(name); exists {
|
||||
if b, ok := v.(bool); ok {
|
||||
status = b
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func getControlString(ctx exprContext, name string) (s string, exists bool) {
|
||||
var v any
|
||||
if v, exists = ctx.GetVar(name); exists {
|
||||
s, exists = v.(string)
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user