This commit is contained in:
Van 2014-10-22 18:06:36 +08:00
commit bd7eaff974
2 changed files with 124 additions and 96 deletions

View File

@ -262,7 +262,30 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
return
}
if data["succ"].(bool) {
if !data["succ"].(bool) {
return
}
channelRet := map[string]interface{}{}
if nil != session.OutputWS[sid] {
// 在前端 output 中显示“开始构建”
channelRet["output"] = "go build"
channelRet["cmd"] = "pre-build"
wsChannel := session.OutputWS[sid]
err := wsChannel.Conn.WriteJSON(&channelRet)
if nil != err {
glog.Error(err)
return
}
// 更新通道最近使用时间
wsChannel.Time = time.Now()
}
reader := io.MultiReader(stdout, stderr)
if err := cmd.Start(); nil != err {
@ -283,13 +306,13 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
count, _ := reader.Read(buf)
channelRet := map[string]interface{}{}
channelRet["output"] = string(buf[:count])
channelRet["cmd"] = "build"
channelRet["executable"] = executable
if 0 == count { // 说明构建成功,没有错误信息输出
// 设置下一次执行命令(前端会根据这个发送请求)
channelRet["nextCmd"] = args["nextCmd"]
channelRet["output"] = "Build Succ"
go func() { // 运行 go install生成的库用于 gocode lib-path
cmd := exec.Command("go", "install")
@ -305,6 +328,8 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
} else { // 构建失败
// 解析错误信息,返回给编辑器 gutter lint
errOut := string(buf[:count])
channelRet["output"] = "Build Failed\n" + errOut
lines := strings.Split(errOut, "\n")
if lines[0][0] == '#' {
@ -361,7 +386,6 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
}
}(rand.Int())
}
}
// go install.

View File

@ -330,6 +330,8 @@ var wide = {
});
}
// TODO: 重构成 switch-case
if ('run' === data.cmd) { // 正在运行
wide.fillOutput($('.bottom-window-group .output').text() + data.output);
wide.curProcessId = data.pid;
@ -358,6 +360,8 @@ var wide = {
CodeMirror.signal(wide.curEditor, "change", wide.curEditor);
} else if ('go get' === data.cmd || 'go install' === data.cmd) {
wide.fillOutput($('.bottom-window-group .output').text() + data.output);
} else if ('pre-build' === data.cmd) {
wide.fillOutput(data.output);
}
};
outputWS.onclose = function (e) {