|
1 |
| - |
| 1 | +# ⚡️ Better Input for C# with `buffer` |
2 | 2 |
|
3 |
| -## Better Input for C# |
| 3 | + |
4 | 4 |
|
5 |
| -Have you ever wondered if you could get the values of what users are typing in real time with `Console.ReadLine()` function? or do you want full control of input? |
| 5 | +Ever wished `Console.ReadLine()` could give you real-time input? Want full control over what the user types *as they type it*? |
6 | 6 |
|
7 |
| -Well don't worry! This `buffer` nuget package aims to solve the issues of `ReadLine()` and gives more control to the user! |
| 7 | +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. |
8 | 8 |
|
9 |
| -### Features |
10 |
| -- Data updates in real time. |
11 |
| -- Control of buffer when to clear and when to call next time. |
12 |
| -- Directly get the buffer as a character array. |
13 |
| -- Supports multithreading to have extra control. |
14 |
| -- Supports a wide range of .NET Frameworks. |
| 9 | +--- |
15 | 10 |
|
16 |
| -### Usage |
| 11 | +## ✨ Features |
17 | 12 |
|
18 |
| -#### Process |
19 |
| -```md |
20 |
| -1. Initialize the object |
21 |
| -2. Get the input from the user (does **not** return the value) |
22 |
| -3. Read the buffer to get the values by using two methods |
23 |
| - 1. Get the buffer as char[] itself. |
24 |
| - 2. Get the buffer as a string. |
25 |
| -4. Clear the buffer (you have to do it **manually** by invoking a method) |
| 13 | +- ✅ Real-time updates while users type |
| 14 | +- 🧠 Manual control over the input buffer |
| 15 | +- 🧵 Thread-safe & supports multithreading |
| 16 | +- 🔠 Access buffer as `char[]` or `string` |
| 17 | +- 💻 Compatible with a wide range of .NET Frameworks |
| 18 | + |
| 19 | +--- |
| 20 | + |
| 21 | +## 🚀 Quick Start |
| 22 | + |
| 23 | +### 🧩 Installation |
| 24 | + |
| 25 | +Add it via CLI: |
| 26 | + |
| 27 | +```bash |
| 28 | +dotnet add package buffer |
26 | 29 | ```
|
27 | 30 |
|
28 |
| -#### Example Usage |
| 31 | +Or visit the [NuGet page →](https://www.nuget.org/packages/buffer) |
| 32 | + |
| 33 | +--- |
| 34 | + |
| 35 | +## 🔧 How It Works |
| 36 | + |
| 37 | +1. Initialize the input buffer |
| 38 | + - With a buffer size |
| 39 | + - Without a buffer size |
| 40 | +2. Start listening for input |
| 41 | +3. Read the buffer manually as `char[]` or `string` |
| 42 | +4. Clear the buffer when you’re done |
| 43 | + |
| 44 | +### 🧪 Example |
| 45 | + |
29 | 46 | ```cpp
|
30 | 47 | PradBuffer InputBuffer = new PradBuffer();
|
31 | 48 |
|
| 49 | +// Start capturing input (does NOT return value) |
32 | 50 | InputBuffer.GetInput();
|
33 | 51 |
|
| 52 | +// Read it manually |
34 | 53 | string value = InputBuffer.GetBufferAsString();
|
35 | 54 |
|
| 55 | +// Clear when done |
36 | 56 | InputBuffer.ClearBuffer();
|
37 | 57 | ```
|
38 | 58 |
|
39 |
| -### Input process |
40 |
| -The input function is overloaded so there are two different ways to use it. |
| 59 | +### 🧩 Manual Buffer Size Example |
| 60 | + |
| 61 | +```csharp |
| 62 | +PradBuffer InputBuffer = new PradBuffer(10); |
| 63 | + |
| 64 | +// Start capturing input (does NOT return value) |
| 65 | +InputBuffer.GetInput(); // Only 10 characters can be stored. (0 to 9) |
| 66 | +
|
| 67 | +// Read it manually |
| 68 | +string value = InputBuffer.GetBufferAsString(); |
| 69 | + |
| 70 | +// Clear when done |
| 71 | +InputBuffer.ClearBuffer(); |
| 72 | +``` |
| 73 | + |
| 74 | +### 🚀 Using its maximum potential |
| 75 | + |
| 76 | +Here is a code example which uses Multithreading to get the input buffer in real-time. |
41 | 77 |
|
42 |
| -#### Method 1 |
43 |
| -`code.cs` |
44 | 78 | ```cpp
|
45 |
| -InputBuffer.GetInput(); |
| 79 | +using prad; |
| 80 | + |
| 81 | +class sample_program { |
| 82 | + static PradBuffer buffer = new PradBuffer(); |
| 83 | + |
| 84 | + static void Main(string[] args) { |
| 85 | + Thread thread = new Thread(invoker); |
| 86 | + thread.Start(); |
| 87 | + |
| 88 | + buffer.GetInput("command > "); |
| 89 | + |
| 90 | + string value = buffer.GetBufferAsString(); |
| 91 | + |
| 92 | + buffer.ClearBuffer(); |
| 93 | + |
| 94 | + Console.WriteLine(value); |
| 95 | + } |
| 96 | + |
| 97 | + static void invoker(){ |
| 98 | + if(buffer.Length > 0) |
| 99 | + Console.WriteLine(buffer.GetBufferAsString()); |
| 100 | + |
| 101 | + Thread.Sleep(1000); |
| 102 | + invoker(); |
| 103 | + } |
| 104 | +} |
46 | 105 | ```
|
47 | 106 |
|
48 |
| -`output:` |
| 107 | +🛠️ Unlock the full power of `buffer` by using multi-threading to get realtime data even before the user has completed typing. |
| 108 | + |
| 109 | +--- |
| 110 | + |
| 111 | +## 🛠 Overloaded Input Methods |
| 112 | + |
| 113 | +### Option 1 – No prompt |
| 114 | +```cpp |
| 115 | +InputBuffer.GetInput(); |
49 | 116 | ```
|
| 117 | +```txt |
50 | 118 | <waits here for input>
|
51 | 119 | ```
|
52 | 120 |
|
53 |
| -#### Method 2 |
54 |
| -`code.cs` |
| 121 | +### Option 2 – With custom prompt |
55 | 122 | ```cpp
|
56 | 123 | InputBuffer.GetInput("command > ");
|
57 | 124 | ```
|
58 |
| - |
59 |
| -`output:` |
60 |
| -``` |
| 125 | +```txt |
61 | 126 | command > <waits here for input>
|
62 | 127 | ```
|
63 | 128 |
|
64 |
| -### Importing the package |
65 |
| -You can check out the [nuget.org](https://www.nuget.org/packages/buffer) site for extra detailed installation. |
| 129 | +--- |
| 130 | + |
| 131 | +## 🤝 Contributing |
| 132 | + |
| 133 | +Contributions are always welcome! |
66 | 134 |
|
67 |
| -For simply just dotnet : |
| 135 | +### Steps |
68 | 136 | ```bash
|
69 |
| -dotnet add package buffer |
| 137 | +# 1. Fork the repo |
| 138 | +# 2. Create a branch |
| 139 | +git checkout -b feature-name |
| 140 | + |
| 141 | +# 3. Make changes & commit |
| 142 | +git commit -m "Add feature-name" |
| 143 | + |
| 144 | +# 4. Push and open PR |
| 145 | +git push origin feature-name |
70 | 146 | ```
|
71 | 147 |
|
72 |
| -### Contributing |
73 |
| - |
74 |
| -Contributions are welcome! Please follow these steps: |
75 |
| - |
76 |
| -1. Fork the repository. |
77 |
| -2. Create a new branch: |
78 |
| - ```bash |
79 |
| - git checkout -b feature-name |
80 |
| - ``` |
81 |
| -3. Commit your changes: |
82 |
| - ```bash |
83 |
| - git commit -m "Add feature-name" |
84 |
| - ``` |
85 |
| -4. Push to your branch: |
86 |
| - ```bash |
87 |
| - git push origin feature-name |
88 |
| - ``` |
89 |
| -5. Open a pull request. |
90 |
| - |
91 |
| -### Contribution guidelines |
92 |
| -- Follow the existing code style. |
93 |
| -- Write clear and concise commit messages. |
94 |
| -- Ensure that your code is well-documented. |
95 |
| -- Write tests for new features and ensure all tests pass before submitting a pull request. |
96 |
| - |
97 |
| -### Links |
98 |
| -- [NuGet Package](https://www.nuget.org/packages/buffer) |
99 |
| -- [Github source code](https://github.com/pradosh-arduino/buffer) |
100 |
| -- [Blog Post](https://dev.to/pradcode/better-input-method-for-c-4hnb) |
| 148 | +### Please: |
| 149 | +- Stick to the existing code style |
| 150 | +- Write helpful commit messages |
| 151 | +- Document new features |
| 152 | +- Add tests when possible ✅ |
| 153 | + |
| 154 | +--- |
| 155 | + |
| 156 | +## 🔗 Links |
| 157 | + |
| 158 | +- 📦 [NuGet Package](https://www.nuget.org/packages/buffer) |
| 159 | +- 🧑💻 [GitHub Source](https://github.com/pradosh-arduino/buffer) |
| 160 | +- 📝 [Blog Post](https://dev.to/pradcode/better-input-method-for-c-4hnb) |
| 161 | + |
| 162 | +--- |
| 163 | + |
| 164 | +Give it a ⭐ if you like it and share it with your fellow devs! |
0 commit comments