cronvel / terminal-kit

Terminal utilities for node.js
MIT License
3.08k stars 198 forks source link

Word/Line wrap ERROR when x,y,width or height of TextBox are non integers #226

Open SinanAkkoyun opened 1 year ago

SinanAkkoyun commented 1 year ago

I received following crash:

TypeError: Cannot read properties of undefined (reading 'char')
    at TextBuffer.wrapLine (/mnt/c/Users/.../node_modules/terminal-kit/lib/TextBuffer.js:595:25)
    at TextBuffer.inlineInsert (/mnt/c/Users/.../node_modules/terminal-kit/lib/TextBuffer.js:1501:35)
    at TextBuffer.insert (/mnt/c/Users/.../node_modules/terminal-kit/lib/TextBuffer.js:1388:16)
    at TextBuffer.append (/mnt/c/Users/.../node_modules/terminal-kit/lib/TextBuffer.js:1412:7)
    at TextBox.addContent (/mnt/c/Users/.../node_modules/terminal-kit/lib/document/TextBox.js:495:20)
    at TextBox.appendContent (/mnt/c/Users/.../node_modules/terminal-kit/lib/document/TextBox.js:466:80)
    at ClientEventEmitter.<anonymous> (/mnt/c/Users/.../src/index.ts:216:26)
    at ClientEventEmitter.emit (node:events:525:35)

I could remove the crash by replacing:

const speechBox = new terminalkit.TextBox( {
  parent: document ,
  // content: text ,
  // contentHasMarkup: true ,
  scrollable: true ,
  vScrollBar: false ,
  // lineWrap: true ,
  wordWrap: true ,
  x: document.outputWidth * 0.4,
  y: 0 ,
  width: document.outputWidth * 0.6, // TODO: need to find responsive solution
  height: document.outputHeight - 2,
  resizable: true
})

with:

const speechBox = new terminalkit.TextBox( {
  parent: document ,
  // content: text ,
  // contentHasMarkup: true ,
  scrollable: true ,
  vScrollBar: false ,
  // lineWrap: true ,
  wordWrap: true ,
  x: Math.round(document.outputWidth * 0.4) , // padding etc
  y: 0 ,
  width: Math.round(document.outputWidth * 0.6), // TODO: need to find responsive solution
  height: document.outputHeight - 2,
  resizable: true
})

Please incorporate that into the package itself! Thank you so much for the document feature, it's the most amazing thing I've ever seen with CLIs