Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

pradosh-arduino/buffer

Repository files navigation

⚡️ Better Input for C# with buffer

Buffer package in action

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.


✨ Features

  • Real-time updates while users type
  • 📜 Real-time Syntax highlighting.
  • 🧠 Manual control over the input buffer
  • 🧵 Thread-safe & supports multithreading
  • 🔠 Access buffer as char[] or string
  • 💻 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

🚀 Quick Start

🧩 Installation

Add it via CLI:

dotnet add package buffer

Or visit the NuGet page →


🔧 How It Works

  1. Initialize the input buffer
    • With a buffer size
    • Without a buffer size
  2. Start listening for input
  3. Read the buffer manually as char[] or string
  4. Clear the buffer when you’re done

🧪 Example

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();

🧩 Manual Buffer Size Example

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();

Here is a demo of Limited Buffer Size of 10 characters

buffer-limit

🧩 Syntax Highlighting in Real-time

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}\"");
}

Demo of Syntax Highlighting

Syntax Highlighting Demo

🚀 Using its maximum potential

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.


🛠 Overloaded Input Methods

Option 1 – No prompt

InputBuffer.GetInput();
<waits here for input>

Option 2 – With custom prompt

InputBuffer.GetInput("command > ");
command > <waits here for input>

🤝 Contributing

Contributions are always welcome!

Steps

# 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

Please:

  • Stick to the existing code style
  • Write helpful commit messages
  • Document new features
  • Add tests when possible ✅

🔗 Links


Give it a ⭐ if you like it and share it with your fellow devs!

About

A fast, completely controllable input method solution for C#.

Topics

Resources

License

Stars

Watchers

Forks

Languages

AltStyle によって変換されたページ (->オリジナル) /