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,12 +200,24 @@ 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)
buf.content += oneRuneStr
now := time.Now().UnixNano() / int64(time.Millisecond)
if 0 == buf.millisecond {
buf.millisecond = now
}
if now-outputTimeout >= buf.millisecond || len(buf.content) > outputBufMax || oneRuneStr == "\n" {
channelRet["cmd"] = "run" channelRet["cmd"] = "run"
channelRet["output"] = "<span class='stderr'>" + buf + "</span>" channelRet["output"] = "<span class='stderr'>" + buf.content + "</span>"
buf = outputBuf{} // a new buffer
err = wsChannel.WriteJSON(&channelRet) err = wsChannel.WriteJSON(&channelRet)
if nil != err { if nil != err {
logger.Error(err) logger.Error(err)
@ -213,6 +226,7 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
wsChannel.Refresh() 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 {