|
|
|
@ -31,6 +31,14 @@ const prop = defineProps({
@@ -31,6 +31,14 @@ const prop = defineProps({
|
|
|
|
|
prmt: { |
|
|
|
|
type: String, |
|
|
|
|
default: ">" |
|
|
|
|
}, |
|
|
|
|
cols: { |
|
|
|
|
type: Number, |
|
|
|
|
default: 80 |
|
|
|
|
}, |
|
|
|
|
rows: { |
|
|
|
|
type: Number, |
|
|
|
|
default: 40 |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
const flag = reactive({ |
|
|
|
@ -95,31 +103,69 @@ const onKey = e => {
@@ -95,31 +103,69 @@ const onKey = e => {
|
|
|
|
|
//\x1B ESC |
|
|
|
|
//\x1BOP-\x1B[24~ F1-F12 |
|
|
|
|
const key = e.key; |
|
|
|
|
if (key.indexOf("\u001b") !== -1) { |
|
|
|
|
|
|
|
|
|
if (key.indexOf("\u001b") !== -1 || !isWsOpen()) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (isWsOpen()) { |
|
|
|
|
if (key === '\x7F') { |
|
|
|
|
if (text.length > 0) { |
|
|
|
|
term.value.write("\b \b"); |
|
|
|
|
text = text.substring(0, text.length - 1) |
|
|
|
|
} |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (key == '\r') { |
|
|
|
|
term.value.writeln(key) |
|
|
|
|
if (e.domEvent.ctrlKey) { |
|
|
|
|
text += key; |
|
|
|
|
} else { |
|
|
|
|
sendText(text); |
|
|
|
|
text = ""; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
text += key |
|
|
|
|
term.value.write(key) |
|
|
|
|
} |
|
|
|
|
if (back(e) || newLine(e) || cancel(e) || copy(e) || paste(e)) |
|
|
|
|
return; |
|
|
|
|
text += key; |
|
|
|
|
term.value.write(key); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const back = e => { |
|
|
|
|
if (e.key !== '\x7F') {//回退 |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
if (text.length > 0) { |
|
|
|
|
term.value.write("\b \b"); |
|
|
|
|
text = text.substring(0, text.length - 1) |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
const newLine = (e) => { |
|
|
|
|
const key = e.key; |
|
|
|
|
if (key !== '\r') {//回车 |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
term.value.writeln(key) |
|
|
|
|
if (e.domEvent.ctrlKey) { |
|
|
|
|
text += key; |
|
|
|
|
} else { |
|
|
|
|
sendText(text); |
|
|
|
|
text = ""; |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
const cancel = (e) => { |
|
|
|
|
if (e.key !== '\x1A') {//ctrl+z |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
if(text){ |
|
|
|
|
term.value.writeln("\r"); |
|
|
|
|
term.value.write(prop.prmt); |
|
|
|
|
text = ""; |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
const copy = e => { |
|
|
|
|
if (e.key !== '\x03') {//ctrl+c |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
const paste = (e) => { |
|
|
|
|
if (e.key !== '\x16') {//粘贴 |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
navigator.clipboard.readText().then(val => { |
|
|
|
|
text += val; |
|
|
|
|
term.value.write(val); |
|
|
|
|
}) |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const initTerm = () => { |
|
|
|
|
const options: any = { |
|
|
|
|
lineHeight: 1.2, |
|
|
|
@ -133,9 +179,9 @@ const initTerm = () => {
@@ -133,9 +179,9 @@ const initTerm = () => {
|
|
|
|
|
cursorStyle: 'underline', |
|
|
|
|
scrollback: 100, |
|
|
|
|
tabStopWidth: 2, |
|
|
|
|
cols: 80 |
|
|
|
|
cols: prop.cols, |
|
|
|
|
rows: prop.rows |
|
|
|
|
} |
|
|
|
|
options.cols = Math.ceil((window.innerWidth - 80) / 20) |
|
|
|
|
term.value = new Terminal(options); |
|
|
|
|
term.value.open(terminal.value); |
|
|
|
|
term.value.onKey(onKey); |
|
|
|
@ -166,11 +212,11 @@ const showClear = e => {
@@ -166,11 +212,11 @@ const showClear = e => {
|
|
|
|
|
document.oncontextmenu = function (e) { |
|
|
|
|
e.preventDefault(); |
|
|
|
|
}; |
|
|
|
|
navigator.clipboard.readText().then(content => { |
|
|
|
|
term.value.write(content) |
|
|
|
|
text += content; |
|
|
|
|
// sendText(content); |
|
|
|
|
}) |
|
|
|
|
// navigator.clipboard.readText().then(content => { |
|
|
|
|
// term.value.write(content) |
|
|
|
|
// text += content; |
|
|
|
|
// sendText(content); |
|
|
|
|
// }) |
|
|
|
|
// term.value.clear(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|