Giter VIP home page Giter VIP logo

Comments (4)

Tyriar avatar Tyriar commented on August 21, 2024 1

@euroclydon37 node-pty was forked from pty.js about a year ago, here are the main changes:

  • Better Windows support
  • Better support for recent Node versions
  • Converted to TS, added some tests

Checkout the releases for more specifics, 0.4.1 was the first release after forking, 0.6.0 removed pty.js' modification to winpty and updated it to latest.

from pty.js.

euroclydon37 avatar euroclydon37 commented on August 21, 2024 1

Loving it so far.

from pty.js.

euroclydon37 avatar euroclydon37 commented on August 21, 2024

I'm looking for this same solution. Currently, the only thing I could think to do is to capture the input manually in a variable and compare the output with the last known input on each data event, choosing to ignore the said output if they are equal.

let lastInput = '';

term.on('data', (data) => {
  if(lastInput !== data) {
    process.stdout.write(data);  //  instead of console.log to avoid extra newline characters
  }
}

process.stdin.on('readable', () => {
  const chunk = process.stdin.read();
  if (chunk !== null) {
    lastInput = chunk;
    term.write(chunk);
  }
}

The problem with this is that while it seems straight forward, data and chunk are of different types. Then once you get past that with everything converted to what it needs to be for comparison, you end up with them having different newline characters. My attempt had lastInput possessing a trailing \n and data possessing \r\n.

Finally, on top of all of that, stdout doesn't guarantee that the entire string is handed to you on the data event. I would often get something like this.

t
est
bash-3.2$ 

My next step is to possibly wait for a newline character before parsing data. I'm just afraid that there will be scenarios where all of this will cause unintended behavior. It would be much better if the echo could be disabled with a configuration option or something.

from pty.js.

euroclydon37 avatar euroclydon37 commented on August 21, 2024

Solution

Found this explanation in the node-pty repo.

process.stdin.setRawMode(true)

I would expect it to work with pty.js as well.

On that note, this repo hasn't had a commit in a year, so I would consider switching to node-pty if you're doing anything crucial. I've only recently discovered them, and don't know much about them, but it seems like the community has switched boats.

One might be the continuation of the other. I don't know.

from pty.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.