question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

this.buffer.lines.get(i) returns undefined

See original GitHub issue

Original issue: https://github.com/sourcelair/xterm.js/issues/821 PR for quick fix: https://github.com/sourcelair/xterm.js/pull/823

The resize rows section below is meant to handle this row resizing, if this is actually happening we should figure out the root cause. this.buffer.lines.get(i) should always return an array when i < this.buffer.lines.length which is guaranteed by line 1942.

@jpmasters any more details on how you’re using xterm.js?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
amejia1commented, Jan 12, 2018

Tracked this down to a problem with the ‘buffer’ property here. Seems now with the latest version of xterm.js, this keeps whatever buffer value was set to it initially or on activate. As I resize the terminal, I can see the buffers in the bufferset get updated, but it doesn’t seem to get reflected in this property.

Changing this property to be implemented through a getter resolves the resizing issue for me but now I get a problem with selecting content to be copied from the terminal. In any case, this is the diff I have so far.

diff --git a/src/Buffer.ts b/src/Buffer.ts
index 623c385..3e7d612 100644
--- a/src/Buffer.ts
+++ b/src/Buffer.ts
@@ -121,11 +121,6 @@ export class Buffer implements IBuffer {
       if (this._terminal.cols < newCols) {
         const ch: CharData = [this._terminal.defAttr, ' ', 1, 32]; // does xterm use the default attr?
         for (let i = 0; i < this._lines.length; i++) {
-          // TODO: This should be removed, with tests setup for the case that was
-          // causing the underlying bug, see https://github.com/sourcelair/xterm.js/issues/824
-          if (this._lines.get(i) === undefined) {
-            this._lines.set(i, this._terminal.blankLine(undefined, undefined, newCols));
-          }
           while (this._lines.get(i).length < newCols) {
             this._lines.get(i).push(ch);
           }
diff --git a/src/Terminal.ts b/src/Terminal.ts
index f95cc0e..d653138 100644
--- a/src/Terminal.ts
+++ b/src/Terminal.ts
@@ -293,10 +293,6 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT

     // Create the terminal's buffers and set the current buffer
     this.buffers = new BufferSet(this);
-    this.buffer = this.buffers.active;  // Convenience shortcut;
-    this.buffers.on('activate', (buffer: Buffer) => {
-      this.buffer = buffer;
-    });

     // Ensure the selection manager has the correct buffer
     if (this.selectionManager) {
@@ -304,6 +300,13 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
     }
   }

+  /**
+   * Convenience property to active buffer.
+   */
+  public get buffer(): Buffer {
+      return this.buffers.active;
+  }
+
   /**
    * back_color_erase feature for xterm.
    */
1reaction
jpmasterscommented, Aug 1, 2017

Hi @Tyriar I can reproduce it in the demo using the following after refreshing the demo page:

// create a scroll region from lines 13 to 19
term.write('\x1b[13;19r');
// move the cursor to the top of the scroll region
term.write('\x1b[13;0H');
// RI
term.write('\x1bM');
// now the last entries are undefined
console.log(term.buffer.lines.length);
console.log(term.buffer.lines[term.buffer.lines.length - 5]);

If you now call term.resize() with a rows value > the current rows it’ll throw a type error if the terminal has had the chance to render in the meantime so try the resize() as a new command.

term.resize(50, 50);

The key to reproducing it seems to be to get (Terminal.buffer.y === Terminal.buffer.scrollTop) &&((Terminal.buffer.y + Terminal.buffer.ybase) > 0) then calling reverseIndex. We managed to do that by using a scroll region but I don’t know if that’s the only way it can happen. The code as it is at the moment assumes a RI will only need to insert a new line when buffer.y === 0.

Does that make sense?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node.js Buffer is undefined inside of a Class - Stack Overflow
Inside of this.load you are not returning anything, which means the function will return undefined. You have two ways you can fix this:....
Read more >
Buffer | Node.js v19.3.0 Documentation
In other words, buf[index] returns undefined when index is negative or greater or equal to buf.length , and buf[index] = value does not...
Read more >
Buffer Protocol — Python 3.11.1 documentation
The reference is owned by the consumer and automatically decremented and set to NULL by PyBuffer_Release() . The field is the equivalent of...
Read more >
eval() - JavaScript - MDN Web Docs - Mozilla
The eval() function evaluates JavaScript code represented as a string and returns its completion value. The source is parsed as a script.
Read more >
Using Buffers in Node.js - DigitalOcean
A buffer is a space in memory (typically RAM) that stores binary data. ... You may have used buffers implicitly if you wrote...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found