optimize output stderr 📜

This commit is contained in:
Liang Ding 2015-01-14 14:19:31 +08:00
parent 0a5a88335d
commit a2f50ae94e
2 changed files with 25 additions and 10 deletions

View File

@ -191,6 +191,7 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
} }
}() }()
buf := outputBuf{}
for { for {
r, _, err := errReader.ReadRune() r, _, err := errReader.ReadRune()
@ -199,19 +200,32 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
break break
} }
buf := string(r) oneRuneStr := string(r)
buf = strings.Replace(buf, "<", "&lt;", -1) oneRuneStr = strings.Replace(oneRuneStr, "<", "&lt;", -1)
buf = strings.Replace(buf, ">", "&gt;", -1) oneRuneStr = strings.Replace(oneRuneStr, ">", "&gt;", -1)
channelRet["cmd"] = "run" buf.content += oneRuneStr
channelRet["output"] = "<span class='stderr'>" + buf + "</span>"
err = wsChannel.WriteJSON(&channelRet) now := time.Now().UnixNano() / int64(time.Millisecond)
if nil != err {
logger.Error(err) if 0 == buf.millisecond {
break buf.millisecond = now
} }
wsChannel.Refresh() if now-outputTimeout >= buf.millisecond || len(buf.content) > outputBufMax || oneRuneStr == "\n" {
channelRet["cmd"] = "run"
channelRet["output"] = "<span class='stderr'>" + buf.content + "</span>"
buf = outputBuf{} // a new buffer
err = wsChannel.WriteJSON(&channelRet)
if nil != err {
logger.Error(err)
break
}
wsChannel.Refresh()
}
} }
}(rand.Int()) }(rand.Int())
} }

View File

@ -439,6 +439,7 @@
padding: 0 5px; padding: 0 5px;
line-height: 16px; line-height: 16px;
font-size: 12px; font-size: 12px;
overflow-x: scroll;
} }
.bottom-window-group .output pre { .bottom-window-group .output pre {