本文整理匯總了Golang中github.com/nsf/gothic.Interpreter類的典型用法代碼示例。如果您正苦於以下問題:Golang Interpreter類的具體用法?Golang Interpreter怎麽用?Golang Interpreter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Interpreter類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: gocov_update
func gocov_update(ir *gothic.Interpreter) {
ir.Eval(`
.f2.funcs delete [.f2.funcs children {}]
`)
ir.EvalAs(&xsourceview, ".f1.sourceview xview")
ir.EvalAs(&ysourceview, ".f1.sourceview yview")
gocov_test(ir)
}
示例2: gocov_test
func gocov_test(ir *gothic.Interpreter) {
var buf bytes.Buffer
cmd := exec.Command("gocov", "test")
cmd.Stdout = &buf
err := cmd.Run()
if err != nil {
gocov_test_error(ir, err)
return
}
result := struct{ Packages []*gocov.Package }{}
err = json.Unmarshal(buf.Bytes(), &result)
if err != nil {
gocov_test_error(ir, err)
return
}
sel := ""
current = result.Packages
for pi, p := range result.Packages {
for fi, f := range p.Functions {
r := reached(f)
n := len(f.Statements)
fun := fmt.Sprintf("%s.%s", p.Name, f.Name)
cov := fmt.Sprintf("%.2f%% (%d/%d)", percentage(r, n), r, n)
file := fmt.Sprintf("%s/%s", p.Name, filepath.Base(f.File))
id := fmt.Sprintf("f_%d_%d", pi, fi)
if prevsel != "" && prevsel == fun {
sel = id
}
ir.Eval(`.f2.funcs insert {} end -id `, id,
` -values {`, strconv.Quote(fun),
` `, strconv.Quote(file),
` `, strconv.Quote(cov), `}`)
}
}
dir := filepath.Dir(current[0].Functions[0].File)
ir.Set("pathtext", dir)
done := 0
total := 0
for _, p := range result.Packages {
for _, f := range p.Functions {
done += reached(f)
total += len(f.Statements)
}
}
ir.Set("covtext", fmt.Sprintf("Overall coverage: %.2f%% (%d/%d)",
percentage(done, total), done, total))
if sel == "" {
sel = "f_0_0"
}
ir.Eval(".f2.funcs selection set ", sel)
}
示例3: gocov_selection
func gocov_selection(ir *gothic.Interpreter) {
var selection string
ir.EvalAs(&selection, ".f2.funcs selection")
var pi, fi int
_, err := fmt.Sscanf(selection, "f_%d_%d", &pi, &fi)
if err != nil {
panic(err)
}
f := current[pi].Functions[fi]
prevsel = fmt.Sprintf("%s.%s", current[pi].Name, f.Name)
data, err := ioutil.ReadFile(f.File)
if err != nil {
panic(err)
}
ir.Set("source", string(data[f.Start:f.End]))
ir.Eval(`
.f1.sourceview configure -state normal
.f1.sourceview delete 1.0 end
.f1.sourceview insert end $source
.f1.sourceview configure -state disabled
`)
for _, s := range f.Statements {
if s.Reached != 0 {
continue
}
ls, le := s.Start-f.Start, s.End-f.Start
ir.Eval(`.f1.sourceview tag add red {1.0 +`, ls, `chars} {1.0 +`, le, `chars}`)
}
if xsourceview != "" {
ir.Eval(".f1.sourceview xview moveto [lindex {", xsourceview, "} 0]")
ir.Eval(".f1.sourceview yview moveto [lindex {", ysourceview, "} 0]")
xsourceview = ""
ysourceview = ""
}
}
示例4: applyOp
func applyOp(op string, ir *gothic.Interpreter) {
var num string
ir.EvalAs(&num, "set calcText")
if args[0] == nil {
if op != "=" {
args[0] = big.NewInt(0)
args[0].SetString(num, 10)
}
} else {
args[1] = big.NewInt(0)
args[1].SetString(num, 10)
}
afterOp = true
if args[1] == nil {
lastOp = op
return
}
switch lastOp {
case "+":
args[0] = args[0].Add(args[0], args[1])
case "-":
args[0] = args[0].Sub(args[0], args[1])
case "/":
args[0] = args[0].Div(args[0], args[1])
case "*":
args[0] = args[0].Mul(args[0], args[1])
}
lastOp = op
args[1] = nil
ir.Eval("set calcText ", args[0])
if op == "=" {
args[0] = nil
}
}
示例5: proc
func proc(ir *gothic.Interpreter, num string) {
button := ".b" + num
progress := ".p" + num
channame := "proc" + num
recv := make(chan int)
// register channel and enable button
ir.RegisterCommand(channame, func(_ string, arg int) {
recv <- arg
})
ir.Eval(`%{} configure -state normal`, button)
for {
// wait for an event
<-recv
// simulate activity
ir.Eval(`%{} configure -state disabled -text "In Progress %{}"`, button, num)
for i := 0; i <= 100; i += 2 {
ir.Eval(`%{%s} configure -value %{}`, progress, i)
time.Sleep(5e7)
}
// reset button state and progress value
ir.Eval(`%{} configure -value 0`, progress)
ir.Eval(`%{} configure -state normal -text "Start %{}"`, button, num)
}
}
示例6: gocov_test_error
func gocov_test_error(ir *gothic.Interpreter, err error) {
ir.Eval(`tk_messageBox -title "gocov test error" -icon error -message `,
strconv.Quote(err.Error()))
}
示例7: initGUI
func initGUI(ir *gothic.Interpreter) {
ir.UploadImage("bg", loadPNG("background.png"))
ir.Eval(`ttk::label .l -image bg`)
ir.Eval(`pack .l -expand true`)
}