News for hackers. Stuff that matters.

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

https://github.com/NishantJoshi00/shelgon

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

( 25 comments | 40 points | on HN )
Re:Show HN: Shelgon: A Framework for Building Interactive RE... by ilikegreen on Thursday March 06, 2025 @04:17PM (#43285161)
Please don't mind my possibly simplistic question — but is this something that would bring Rust development closer to a Lisp environment? Seems like an interesting project.
Re:Show HN: Shelgon: A Framework for Building Interactive RE... by fredrikholm on Friday March 07, 2025 @04:57AM (#43288801)
This is more in line with building a REPL for your own language.

Lisp environments are just that; environments. That is to say that there is a runtime that holds your code in memory, which then enables a REPL to replace parts of the code in memory while the program is running.

This implies an interpreted language (that might or might not also be compiled further at runtime), which Rust is not. It also heavily implies a garbage collector, which Rust doesn't have. Lastly, type guarantees in these languages tend to be less strong as the system almost by definition is already very dynamic.

Re:Show HN: Shelgon: A Framework for Building Interactive RE... by bfLives on Thursday March 06, 2025 @03:52PM (#43284964)
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?

Re:Show HN: Shelgon: A Framework for Building Interactive RE... by cmrdporcupine on Thursday March 06, 2025 @03:58PM (#43285005)
+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.

Re:Show HN: Shelgon: A Framework for Building Interactive RE... by cat-whisperer on Thursday March 06, 2025 @08:37PM (#43286761)
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.
Re:Show HN: Shelgon: A Framework for Building Interactive RE... by dhon_ on Thursday March 06, 2025 @09:01PM (#43286868)
Could you elaborate on why using block_on wouldn't be an acceptable solution for users that want a blocking API?
Re:Show HN: Shelgon: A Framework for Building Interactive RE... by cat-whisperer on Thursday March 06, 2025 @11:03PM (#43287314)
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.
Re:Show HN: Shelgon: A Framework for Building Interactive RE... by cmrdporcupine on Thursday March 06, 2025 @09:38PM (#43287006)
Why would I want to add tokio as a dependency if I don't use it?
Re:Show HN: Shelgon: A Framework for Building Interactive RE... by dhon_ on Thursday March 06, 2025 @10:58PM (#43287293)
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.
Re:Show HN: Shelgon: A Framework for Building Interactive RE... by cat-whisperer on Friday March 07, 2025 @01:01AM (#43287673)
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.
Re:Show HN: Shelgon: A Framework for Building Interactive RE... by hkalbasi on Thursday March 06, 2025 @03:45PM (#43284908)
How it compares to other libraries in this space, e.g. reedline or rustyline?
Re:Show HN: Shelgon: A Framework for Building Interactive RE... by cat-whisperer on Thursday March 06, 2025 @08:45PM (#43286795)
Wow! rustyline has intensive support for a lot of the actions and things the user can do. Though I wanted to provide a more restrictive yet powerful abstraction that’s my I chose a trait based approach. It provides the exact control needed on certain aspects of the shell while providing ample control because of the shared state. Initially, I was planning to make the functions async, but I rather choose to pass the async runtime instead. It solves for 2 cool use-cases; 1 we can call block_on and manage an async task in the flow, or 2 queue in the action and consider pooling it when needed.
Re:Show HN: Shelgon: A Framework for Building Interactive RE... by Y_Y on Thursday March 06, 2025 @03:49PM (#43284944)
That's a one-liner in lisp
Re:Show HN: Shelgon: A Framework for Building Interactive RE... by gertlex on Thursday March 06, 2025 @05:57PM (#43285881)
Classic bagon comment! :)
Re:Show HN: Shelgon: A Framework for Building Interactive RE... by cmrdporcupine on Thursday March 06, 2025 @03:50PM (#43284949)
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!

Re:Show HN: Shelgon: A Framework for Building Interactive RE... by tmpfs on Thursday March 06, 2025 @04:11PM (#43285121)
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!

Re:Show HN: Shelgon: A Framework for Building Interactive RE... by cat-whisperer on Thursday March 06, 2025 @08:48PM (#43286816)
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.
Re:Show HN: Shelgon: A Framework for Building Interactive RE... by tmpfs on Saturday March 08, 2025 @06:41AM (#43299426)
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/

[dead]
Re:Show HN: Shelgon: A Framework for Building Interactive RE... by gertlex on Thursday March 06, 2025 @05:59PM (#43285891)
I wonder if they could get away with an extra L and using ascii art of the pokemon...
Re:Show HN: Shelgon: A Framework for Building Interactive RE... by cat-whisperer on Friday March 07, 2025 @05:56AM (#43289138)
ascii art for the win
Re:Show HN: Shelgon: A Framework for Building Interactive RE... by dartos on Thursday March 06, 2025 @05:50PM (#43285829)
Right up until they start charging
Re:Show HN: Shelgon: A Framework for Building Interactive RE... by serial_dev on Friday March 07, 2025 @12:28AM (#43287568)
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.

Re:Show HN: Shelgon: A Framework for Building Interactive RE... by cat-whisperer on Friday March 07, 2025 @01:16PM (#43292592)
giving credit where credit is due.
Re:Show HN: Shelgon: A Framework for Building Interactive RE... by faizshah on Friday March 07, 2025 @04:10AM (#43288492)
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/
Re:Show HN: Shelgon: A Framework for Building Interactive RE... by hajimuz on Monday March 10, 2025 @11:29PM (#43328894)
A quick demo or screenshot would be nice!