remix logo

Hacker Remix

Show HN: Shelgon: A Framework for Building Interactive REPL Shells in Rust

125 points by cat-whisperer 3 days ago | 24 comments

I've been working on Shelgon, a framework that lets you build your own custom REPL shells and interactive CLI applications in Rust.

You can use Shelgon to:

- Create a custom shell with only a few lines of code - Build interactive debugging tools with persistent state between commands - Develop domain-specific language interpreters with shell-like interfaces - Add REPL capabilities to existing applications

Getting started is straightforward - implement a single trait that handles your command execution logic, and Shelgon takes care of the terminal UI, input handling, and async runtime integration.

For example, a simple echo shell takes less than 50 lines of code, including a full implementation of command history, cursor movement, and tab completion.

Repository: https://github.com/nishantjoshi00/shelgon

bfLives 3 days ago

Looks really interesting. I like the approach of writing pure functions that return descriptions of IO tasks to perform. A couple of questions:

1. Why async?

2. Why couple to anyhow instead of using an associated error type?

cmrdporcupine 3 days ago

+1 for #1. In general, I would recommend providing non-async alternative APIs, with the async runtime as an option rather than assumed default. Not all of us drink the kool-aid there. And no, I don't mean just providing a "sync" API that uses "block_on" behind the scenes but still uses tokio...

Also, for async don't mandate tokio, use the "agnostic" crate to abstract it so people can use alternative runtimes.

And yes, don't use anyhow in a library like this. Anyhow is for your internal code, not public libraries/crates. Define a set of error enums, or use thiserror for it if you have to.

cat-whisperer 3 days ago

Yup, I am planning to use thiserror and error-stack for this in the future updates. But, anyhow provides an insanely easy interface for the person using this library, and keeps their mind off the error handling and rather in managing the domain stuff.

dhon_ 3 days ago

Could you elaborate on why using block_on wouldn't be an acceptable solution for users that want a blocking API?

cmrdporcupine 3 days ago

Why would I want to add tokio as a dependency if I don't use it?

dhon_ 2 days ago

Yes you're right. I'd assumed that tokio was used internally in the UI but from a cursory read it doesn't seem to be the case.

cat-whisperer 2 days ago

I was thinking of making it a opt-in feature, but I saw most of the usecases that I might have, might need concurrency and a runtime.

cat-whisperer 2 days ago

it definitely would be, that was my intention. By passing in a runtime you can either block or schedule. Giving you control on what you want to be concurrent and what you don’t.

cmrdporcupine 3 days ago

Neat. I'll check it out.

One suggestions: the README advertises lovely TUIs. Show us a screenshot, or screencast, so we can see what you mean!

tmpfs 3 days ago

Yes, a screenshot would be good to get a visual on this.

I have done a simple shell using Rustyline and Clap and this could be something I might be interested in but it's hard to say without a visual idea, asccinema would be perfect!

cat-whisperer 3 days ago

asccinema is a killer idea! but I am still chasing my perfect shell . If you end up implementing an insane looking shell with this, contributions are always open.

tmpfs 1 day ago

I don't have the time to look deeper into it right now as I am quite happy with my current setup but if you do want to make an ascinema recording here is a little tool I wrote to help testing and recording CLIs

https://github.com/tmpfs/anticipate/

faizshah 2 days ago

This is awesome, there’s a really nice one in python called prompt toolkit that has some a nice api as well: https://python-prompt-toolkit.readthedocs.io/en/master/

serial_dev 2 days ago

Interesting stuff!

Video or gif would be nice! It’s like a UI library need at least a screenshot, this thing needs a video demo of sorts.

Q: why write that the docs is by LLM? In my opinion if it’s correct, and it makes sense, I don’t care even if an alien gave it to you.

cat-whisperer 2 days ago

giving credit where credit is due.