Crate(s) recommendation for CLI REPL shell development

Does anyone have a recommendation of a crate that facilitates development of a CLI shell - think telnet-like interface where a user is provided a prompt and can execute commands. I don’t need too many bells and whistles, but things like history, colored (ANSI is fine) output, and auto-complete support/hooks would be nice. Only need linux, if that matters.

I found linefeed, but wanted to survey the landscape and see if there’re other crates that I missed. Or if someone has used linefeed and has feedback on it, that’s welcomed as well.


1 Like

There are others crates, like liner.
But in my experience (I’ve been developing an interpreter for work, and a CLI-based REPL to go with it) linefeed works best across OSes at this particular moment and in fact I ported my REPL from liner to linefeed.
I mention this despite the fact you’re linux-only at this moment, because you never know when requirements change :slight_smile:

1 Like

Thanks @jjpe - so that’s an endorsement for linefeed I suppose :slight_smile:.

I’m 99.9% certain my usecase will stay linux-only but I certainly take your point (and it’s valuable for others reading this that may have similar requirements but want other platform support).

1 Like

Also, linefeed doesn’t directly do colored output (that I know of), but that is really easy to achieve with the colored crate.
It can take a little experimentation to get the contrast right since user-applied themes in the terminal emulator matter, but it’s nothing too fancy or difficult.

It does imply that it is likely a wise move to make the actual colors being output configurable in e.g. a .toml file.

I started with ansi_term, in huge part because a linefeed example used it, but I did notice an abundance of coloring crates (why do we have so many??). Is colored better in your opinion?

One thing I noticed with ansi_term is it more easily allows keeping the color turned on for the remainder of a line. For example, if I want user-entered text on the prompt line to be also the color of the prompt, that’s easy with ansi_term because it explicitly gives you the ansi color’s prefix and suffix, so you can delineate where the coloring takes effect.

But, perhaps I overlooked a better way to do that with linefeed (I’ve not studied it extensively just yet).

Indeed there are a number of competitors.
I honestly don’t know if colored is the superior coloring crate, per se; the crate page does mention that the authors learned from ansi_term.
I simply happened to try it, and I liked it as it colors text cross platform, and without fuss.
So I never really bothered to check out anything else.

As for keeping the stylings indefinitely, the API docs seem to suggest that is isn’t meant for that (and indeed, that is not my personal use case).
So if you need that perhaps ansi_term is more appropriate.

1 Like