Hacker News new | ask | show | jobs
by hnlmorg 3196 days ago
Maybe you could support a user-defined auto-completion config like Bash et al do for theirs and IDEs would for custom languages too.

With regards to the shell input: I don't know how you are currently detecting the $SHELL prompt (and thus when you can do your auto-completion) but maybe you could allow users to specify hooks for what to watch for to determine the different between the $SHELL and other tools, based on the $SHELL prompt (possibly using $PS1 env var?)

For example you could define that $SHELL's prompt would be:

    SHELLPROMPT>
And when you read that from the $SHELL's STDOUT you know the shell is waiting for prompt. There is obviously the danger that your term would get confused if SHELLPROMPT> happens to appear in the STDOUT when not part of the prompt that it would confuse your term, so perhaps you might need to include an ANSI escape sequence in there as well. Or maybe even define your own custom ANSI escape sequence that $SHELL's need to include in their prompt? (I'm mostly just brainstorming at the moment so these ideas might be worse than your current implementation).

As a side note, the project I'm currently working on is a $SHELL that supports defining data types to STDOUT and STDERR. The issue I have is that those byte streams are typeless and scripts written in my $SHELL needs to work with existing POSIX utilities and potentially on other $SHELLs with untypes streams. Plus I wanted people to be able to type those streams from other languages as well if they wanted and for my $SHELL to understand that. The solution I've decided upon was for an ASNI escape sequence to surround a string with the typed information and for this to only be a included if an environmental variable was set to the name of my shell. This is how I'm working around limitations with POSIX compatibility while still offering a richer environment to develop in when my $SHELL is running (I hope that makes sense).

In fact it sounds like we are attempting to solve similar problems but from a different angle - with myself targeting the $SHELL while you are targeting terminal emulation (which it probably why I'm warming to your project).

2 comments

It works differently: we just create a new shell session for each command. We create a non-interactive session without reading config files to make it fast and pass it appropriate ENV, which we maintain.
Ahh so the prompt isn't bash then? That explains some of the bugs I got.

I'm not going to criticize your approach as it totally makes sense in terms of building a minimum viable product but I do think you're going to run into a lot of problems with that approach as your project gains traction as it's very different to how a terminal emulators traditionally work. Plus you'll potentially spend a lot of time reimplementing Bash features like it's builtins, scripting features and the multitude of parsers it runs (depending on if you're interested in having a REPL environment like you would normally would with $TERM + $SHELL).

That all said, it looks like you're handling pseudo TTYs decently, which is an easy thing to get wrong (I say that from experience as I've screwed up PTYs in the past!) but also probably the most important part to get right, in my opinion.

Can your project be found anywhere? (github??)