jupyterlite / cockle

In-browser bash-like shell implemented in TypeScript.
BSD 3-Clause "New" or "Revised" License
3 stars 2 forks source link

Echo buffered stdin (whilst running a command) back to stdout #52

Closed ianthomas23 closed 2 months ago

ianthomas23 commented 2 months ago

Whilst running a command that accepts stdin, such as wc or cat without any arguments, stdin should be echoed back to stdout a character at a time. This PR does this in the getChar() that is monkey-patched into the command's WASM wrapper. It only does so if stdout is the terminal, if it is a file for example then it is not echoed. Perhaps the code should alternatively go in TerminalInput, but then that would need access to the current TerminalOutput too.

It is not fully correct for the situation of cat accepting multiple lines of input, as here all the output is written at once at the end of the command. What should actually happen is that the command should write each line after it receives a carriage return. I think this occurs because the WASM commands are not set up to perform line buffering. There are a number of similar issues around input/output handling of the WASM commands that will be dealt with in due course.