Skip to content

Commit e8e795e

Browse files
committed
[vue2] fix pushMessage接口传入数组时无法解析ansi格式 #112
1 parent 1ea73fb commit e8e795e

File tree

3 files changed

+35
-27
lines changed

3 files changed

+35
-27
lines changed

src/Terminal.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ export default {
940940
this._closeTips(true)
941941
},
942942
_filterMessageType(message) {
943-
let valid = message.type && /^(normal|html|code|table|json)$/.test(message.type)
943+
let valid = message.type && /^(normal|html|code|table|json|ansi)$/.test(message.type)
944944
if (!valid) {
945945
console.debug(`Invalid terminal message type: ${message.type}, the default type normal will be used`)
946946
message.type = MESSAGE_TYPE.NORMAL
@@ -995,18 +995,6 @@ export default {
995995
return;
996996
}
997997

998-
if (typeof message === 'string') {
999-
message = {
1000-
type: MESSAGE_TYPE.NORMAL,
1001-
content: message
1002-
}
1003-
}
1004-
1005-
if (message.type === MESSAGE_TYPE.ANSI) {
1006-
message.type = MESSAGE_TYPE.HTML
1007-
message.content = _parseANSI(message.content)
1008-
}
1009-
1010998
this._pushMessage0(message)
1011999
this._jumpToBottom()
10121000

@@ -1017,10 +1005,22 @@ export default {
10171005
}
10181006
},
10191007
_pushMessage0(message, checkSize = true) {
1020-
this._filterMessageType(message)
1021-
if (message.type !== MESSAGE_TYPE.CMD_LINE && this.pushMessageBefore) {
1022-
this.pushMessageBefore(message, this.getName())
1008+
if (typeof message === 'string') {
1009+
message = {
1010+
type: MESSAGE_TYPE.NORMAL,
1011+
content: message
1012+
}
1013+
} else {
1014+
this._filterMessageType(message)
1015+
if (message.type === MESSAGE_TYPE.ANSI) {
1016+
message.type = MESSAGE_TYPE.HTML
1017+
message.content = _parseANSI(message.content)
1018+
}
1019+
if (message.type !== MESSAGE_TYPE.CMD_LINE && this.pushMessageBefore) {
1020+
this.pushMessageBefore(message, this.getName())
1021+
}
10231022
}
1023+
10241024
let terminalLogLength = this.terminalLog.length;
10251025
if (terminalLogLength === 0) {
10261026
this._newTerminalLogGroup()

src/css/ansi.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
text-decoration: underline;
1919
}
2020

21-
@-webkit-keyframes t-blink {
21+
@keyframes t-blink {
2222
0% {
2323
opacity: 1;
2424
}

test/App.vue

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,24 @@ export default {
8383
}
8484
],
8585
commandStore: commandStore,
86-
initLog: [{
87-
type: 'normal',
88-
content: "Terminal Initializing ..."
89-
}, {
90-
type: 'normal',
91-
content: "Current login time: " + new Date().toLocaleString()
92-
}, {
93-
type: 'normal',
94-
content: "Welcome to vue web terminal! If you are using for the first time, you can use the <span class='t-cmd-key'>help</span> command to learn. Thanks for your star support: <a class='t-a' target='_blank' href='https://github.com/tzfun/vue-web-terminal'>https://github.com/tzfun/vue-web-terminal</a>"
95-
}]
86+
initLog: [
87+
{
88+
type: 'normal',
89+
content: "Terminal Initializing ..."
90+
},
91+
{
92+
type: 'normal',
93+
content: "Current login time: " + new Date().toLocaleString()
94+
},
95+
{
96+
type: 'ansi',
97+
content: "\x1B[1;34mThis are some blue text.\x1B[0m\n\x1B[30;43mThis is a line of text with a background color.\x1B[0m\n\x1B[92;5mThis is blink text.\x1B[0m"
98+
},
99+
{
100+
type: 'normal',
101+
content: "Welcome to vue web terminal! If you are using for the first time, you can use the <span class='t-cmd-key'>help</span> command to learn. Thanks for your star support: <a class='t-a' target='_blank' href='https://github.com/tzfun/vue-web-terminal'>https://github.com/tzfun/vue-web-terminal</a>"
102+
}
103+
]
96104
}
97105
},
98106
methods: {

0 commit comments

Comments
 (0)