alanhe421 / coding-note

note
3 stars 1 forks source link

xterm.js使用问题 #374

Open alanhe421 opened 2 years ago

alanhe421 commented 2 years ago

程序化终端写入命令,并执行

socket发送命令到服务端即可,\r\n相当于回车。

this.send('yum -y install lrzsz\r\n')
alanhe421 commented 2 years ago

控制字符

https://xtermjs.org/docs/api/vtfeatures/

alanhe421 commented 2 years ago

单元格宽度

term._core._renderService._renderer.dimensions.actualCellWidth

alanhe421 commented 2 years ago

selection定位逻辑

image

alanhe421 commented 2 years ago

onSelectionChange

term.onSelectionChange(() => {

    });
alanhe421 commented 1 year ago

光标所在位置

term.buffer.active.cursorX
alanhe421 commented 1 year ago

单元格宽度

term.buffer.active.getLine(y)?.getCell(x)?.getWidth()
alanhe421 commented 1 year ago

auto-suggestion

这个Shell配置支持即可,xtermjs前端侧不需要做什么

image

alanhe421 commented 1 year ago

清除当前行

    this.send('data', '\b\b\u001b[K');
alanhe421 commented 1 year ago

终端模式

判断是普通还是编辑修改模式

this.term.buffer.active.type === 'normal'
alanhe421 commented 1 year ago

光标位置

https://github.com/xtermjs/xterm.js/discussions/4392

function calculateCursorPosition() {
  let cursorX = term.buffer.active.cursorX;
  let cursorY = term.buffer.active.cursorY;
  let pixelX = cursorX * 10;
  let pixelY = cursorY * 20;
  return {
    x: pixelX,
    y: pixelY
  }
}
alanhe421 commented 1 year ago

当前行内容

const currentLineContent = term.buffer.active.getLine(term.buffer.active.cursorY).translateToString();
alanhe421 commented 8 months ago

scrollback

https://github.com/xtermjs/xterm.js/issues/518