NuGet Downloads GitHub Actions Workflow Status NuGet Version
Ever wished Console.ReadLine()
could give you real-time input? Want full control over what the user types as they type it?
Introducing buffer
— a lightweight NuGet package that gives you real-time input handling and total buffer control in C#. Perfect for building interactive CLI tools, REPLs, or anything where ReadLine()
just doesn’t cut it.
✅
Real-time updates while users type📜
Real-time Syntax highlighting.🧠
Manual control over the input buffer🧵
Thread-safe & supports multithreading🔠
Access buffer aschar[]
orstring
💻
Compatible with a wide range of .NET Frameworks🎉
Emoji support for fun prompts🔒
Secure input handling🛠️
Easy to use and integrate📦
Lightweight and fast🔧
Customizable buffer size
Add it via CLI:
dotnet add package buffer
Or visit the NuGet page →
- Initialize the input buffer
- With a buffer size
- Without a buffer size
- Start listening for input
- Read the buffer manually as
char[]
orstring
- Clear the buffer when you’re done
using Prad.Buffer; ... PradBuffer InputBuffer = new PradBuffer(); // Start capturing input (does NOT return value) InputBuffer.GetInput(); // Read it manually string value = InputBuffer.GetBufferAsString(); // Clear when done InputBuffer.ClearBuffer();
using Prad.Buffer; ... PradBuffer InputBuffer = new PradBuffer(10); // Start capturing input (does NOT return value) InputBuffer.GetInput(); // Only 10 characters can be stored. (0 to 9) // Read it manually string value = InputBuffer.GetBufferAsString(); // Clear when done InputBuffer.ClearBuffer();
PradBuffer Buffer = new PradBuffer(); Console.WriteLine("Enter something to get started, "); string s = ""; // Supports Console Colors Buffer.SyntaxHighlights.Add("prad", ConsoleColor.Red); // Supports Integers, color will be selected with respective to ConsoleColor enum. Buffer.SyntaxHighlights.Add("static", 9); // Directly supports ANSI Escape codes. **Beware any mistakes CAN and WILL break the input.** Buffer.SyntaxHighlights.Add("public", "\x1b[32m"); // Green ANSI Escape code. // ! Throws exception if any other data type is being used. // Buffer.SyntaxHighlights.Add("=", 56.3d); Buffer.EnableSyntaxHighlighting = true; while(true){ Buffer.GetInput("> "); s = Buffer.GetBufferAsString(); Buffer.ClearBuffer(); if(s == "exit") break; Console.WriteLine($"Value Entered : \"{s}\""); }
Here is a code example which uses Multithreading to get the input buffer in real-time.
using Prad.Buffer; class sample_program { static PradBuffer buffer = new PradBuffer(); static void Main(string[] args) { Thread thread = new Thread(invoker); thread.Start(); buffer.GetInput("command > "); string value = buffer.GetBufferAsString(); buffer.ClearBuffer(); Console.WriteLine(value); } static void invoker(){ if(buffer.Length > 0) Console.WriteLine(buffer.GetBufferAsString()); Thread.Sleep(1000); invoker(); } }
🛠️ Unlock the full power of buffer
by using multi-threading to get realtime data even before the user has completed typing.
InputBuffer.GetInput();
<waits here for input>
InputBuffer.GetInput("command > ");
command > <waits here for input>
Contributions are always welcome!
# 1. Fork the repo # 2. Create a branch git checkout -b feature-name # 3. Make changes & commit git commit -m "Add feature-name" # 4. Push and open PR git push origin feature-name
- Stick to the existing code style
- Write helpful commit messages
- Document new features
- Add tests when possible ✅
- 📦 NuGet Package
- 🧑💻 GitHub Source
- 📝 Blog Post
Give it a ⭐ if you like it and share it with your fellow devs!