Skip to content

Commit 419eab4

Browse files
Initial commit of this awesome project!
0 parents  commit 419eab4

File tree

6 files changed

+418
-0
lines changed

6 files changed

+418
-0
lines changed

.gitignore

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
## Ignore Visual Studio temporary files, build results, and
2+
## files generated by popular Visual Studio add-ons.
3+
4+
# User-specific files
5+
*.suo
6+
*.user
7+
*.sln.docstates
8+
9+
# Build results
10+
11+
[Dd]ebug/
12+
[Rr]elease/
13+
x64/
14+
[Bb]in/
15+
[Oo]bj/
16+
17+
# MSTest test Results
18+
[Tt]est[Rr]esult*/
19+
[Bb]uild[Ll]og.*
20+
21+
*_i.c
22+
*_p.c
23+
*_i.h
24+
*.ilk
25+
*.meta
26+
*.obj
27+
*.pch
28+
*.pdb
29+
*.pgc
30+
*.pgd
31+
*.rsp
32+
*.sbr
33+
*.tlb
34+
*.tli
35+
*.tlh
36+
*.tmp
37+
*.tmp_proj
38+
*.log
39+
*.vspscc
40+
*.vssscc
41+
.builds
42+
*.pidb
43+
*.log
44+
*.svclog
45+
*.scc
46+
47+
# Visual C++ cache files
48+
ipch/
49+
*.aps
50+
*.ncb
51+
*.opensdf
52+
*.sdf
53+
*.cachefile
54+
55+
# Visual Studio profiler
56+
*.psess
57+
*.vsp
58+
*.vspx
59+
60+
# Guidance Automation Toolkit
61+
*.gpState
62+
63+
# ReSharper is a .NET coding add-in
64+
_ReSharper*/
65+
*.[Rr]e[Ss]harper
66+
*.DotSettings.user
67+
68+
# Click-Once directory
69+
publish/
70+
71+
# Publish Web Output
72+
*.Publish.xml
73+
*.pubxml
74+
*.azurePubxml
75+
76+
# NuGet Packages Directory
77+
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
78+
packages/
79+
## TODO: If the tool you use requires repositories.config, also uncomment the next line
80+
!packages/repositories.config
81+
82+
# Windows Azure Build Output
83+
csx/
84+
*.build.csdef
85+
86+
# Windows Store app package directory
87+
AppPackages/
88+
89+
# Others
90+
sql/
91+
*.Cache
92+
ClientBin/
93+
[Ss]tyle[Cc]op.*
94+
![Ss]tyle[Cc]op.targets
95+
~$*
96+
*~
97+
*.dbmdl
98+
*.[Pp]ublish.xml
99+
100+
*.publishsettings
101+
102+
# RIA/Silverlight projects
103+
Generated_Code/
104+
105+
# Backup & report files from converting an old project file to a newer
106+
# Visual Studio version. Backup files are not needed, because we have git ;-)
107+
_UpgradeReport_Files/
108+
Backup*/
109+
UpgradeLog*.XML
110+
UpgradeLog*.htm
111+
112+
# SQL Server files
113+
App_Data/*.mdf
114+
App_Data/*.ldf
115+
116+
# =========================
117+
# Windows detritus
118+
# =========================
119+
120+
# Windows image file caches
121+
Thumbs.db
122+
ehthumbs.db
123+
124+
# Folder config file
125+
Desktop.ini
126+
127+
# Recycle Bin used on file shares
128+
$RECYCLE.BIN/
129+
130+
# Mac desktop service store files
131+
.DS_Store
132+
133+
_NCrunch*

Program.cs

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
namespace prad
2+
{
3+
/// <summary>
4+
/// This is an custom made input buffer so that we can get the output even if the user have not completed typing.
5+
/// coded by @pradosh-arduino (github)
6+
/// </summary>
7+
class superbuffer {
8+
private char[] buffer = new char[1024];
9+
10+
/// <summary>
11+
/// Stores the current index of the input buffer.
12+
/// </summary>
13+
public int buffer_index = 0;
14+
15+
/// <summary>
16+
/// Stores the total length of the input buffer.
17+
/// </summary>
18+
public int length = 0;
19+
20+
/// <summary>
21+
/// Function to add a character to the buffer.
22+
/// </summary>
23+
/// <param name="c">The character to be added.</param>
24+
public void add_char(char c){
25+
if(buffer_index >= buffer.Length)
26+
return;
27+
28+
buffer[buffer_index] = c;
29+
buffer_index++;
30+
length++;
31+
}
32+
33+
/// <summary>
34+
/// Clears the buffer for next usage, This function will not be automatically called, you have to call by yourself.
35+
/// </summary>
36+
public void clear_buffer(){
37+
for(int i = 0; i < buffer.Length; i++){
38+
buffer[i] = '\0';
39+
}
40+
41+
buffer_index = 0;
42+
length = 0;
43+
}
44+
45+
/// <summary>
46+
/// Gets the input and stores it in the input buffer array cleanly. It does not return the buffer.
47+
/// </summary>
48+
public void get_input(){
49+
ConsoleKeyInfo current;
50+
51+
while (true)
52+
{
53+
if(!Console.KeyAvailable) continue;
54+
55+
current = Console.ReadKey(true);
56+
57+
if (current.Key == ConsoleKey.Enter)
58+
{
59+
if(length != 0)
60+
Console.WriteLine();
61+
62+
for(int i=0; i<length;i++){
63+
if(buffer[i] == '\0'){
64+
length = i;
65+
break;
66+
}
67+
}
68+
69+
break;
70+
}
71+
else if (current.Key == ConsoleKey.Backspace)
72+
{
73+
if (buffer_index > 0)
74+
{
75+
buffer_index--;
76+
length--;
77+
Console.Write("\b \b");
78+
}
79+
}
80+
else if(current.Key == ConsoleKey.LeftArrow){
81+
if(Console.CursorLeft > 0){
82+
Console.CursorLeft--;
83+
buffer_index--;
84+
}
85+
}
86+
else if(current.Key == ConsoleKey.RightArrow){
87+
if(Console.CursorLeft < length){
88+
Console.CursorLeft++;
89+
buffer_index++;
90+
}
91+
}
92+
else if(current.Key == ConsoleKey.Home){
93+
Console.Write("\r");
94+
buffer_index = 0;
95+
}
96+
else if(current.Key == ConsoleKey.End){
97+
Console.CursorLeft = length;
98+
buffer_index = length;
99+
}
100+
else
101+
{
102+
add_char(current.KeyChar);
103+
Console.Write(current.KeyChar);
104+
}
105+
}
106+
}
107+
108+
/// <summary>
109+
/// Gets the input and stores it in the input buffer array cleanly. It does not return the buffer. We can add a prefix to the input.
110+
/// </summary>
111+
/// <param name="prefix">The actual prefix needed to be displayed</param>
112+
public void get_input(string prefix){
113+
ConsoleKeyInfo current;
114+
115+
Console.Write(prefix);
116+
117+
while (true)
118+
{
119+
if(!Console.KeyAvailable) continue;
120+
121+
current = Console.ReadKey(true);
122+
123+
if (current.Key == ConsoleKey.Enter)
124+
{
125+
if(length != 0)
126+
Console.WriteLine();
127+
128+
for(int i=0; i<length;i++){
129+
if(buffer[i] == '\0'){
130+
length = i;
131+
break;
132+
}
133+
}
134+
135+
break;
136+
}
137+
else if (current.Key == ConsoleKey.Backspace)
138+
{
139+
if (buffer_index > 0)
140+
{
141+
buffer_index--;
142+
length--;
143+
Console.Write("\b \b");
144+
}
145+
}
146+
else if(current.Key == ConsoleKey.LeftArrow){
147+
if(Console.CursorLeft > prefix.Length){
148+
Console.CursorLeft--;
149+
buffer_index--;
150+
}
151+
}
152+
else if(current.Key == ConsoleKey.RightArrow){
153+
if(Console.CursorLeft < length + prefix.Length){
154+
Console.CursorLeft++;
155+
buffer_index++;
156+
}
157+
}
158+
else if(current.Key == ConsoleKey.Home){
159+
Console.Write("\r");
160+
Console.CursorLeft += prefix.Length;
161+
buffer_index = 0;
162+
}
163+
else if(current.Key == ConsoleKey.End){
164+
Console.CursorLeft = length + prefix.Length;
165+
buffer_index = length;
166+
}
167+
else
168+
{
169+
add_char(current.KeyChar);
170+
Console.Write(current.KeyChar);
171+
}
172+
}
173+
}
174+
175+
/// <summary>
176+
/// Function to get the buffer values.
177+
/// </summary>
178+
/// <returns>It returns the buffer as an character array.</returns>
179+
public char[] get_buffer(){
180+
return buffer;
181+
}
182+
183+
/// <summary>
184+
/// Function to get the buffer array as a string.
185+
/// </summary>
186+
/// <returns>A proper string with buffer values.</returns>
187+
public string get_buffer_as_string(){
188+
return new string(buffer, 0, length);
189+
}
190+
}
191+
}

buffer.csproj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Library</OutputType>
5+
<TargetFramework>net7.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
9+
10+
<Version>1.1.0</Version>
11+
<Authors>Pradosh (helloImPR)</Authors>
12+
<Description>A fast, completely controllable input method solution for C#.</Description>
13+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
14+
<RepositoryUrl>https://github.com/pradosh-arduino/buffer</RepositoryUrl>
15+
<RepositoryType>git</RepositoryType>
16+
</PropertyGroup>
17+
18+
</Project>

buffer.sln

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Microsoft Visual Studio Solution File, Format Version 12.00
2+
# Visual Studio Version 17
3+
VisualStudioVersion = 17.5.2.0
4+
MinimumVisualStudioVersion = 10.0.40219.1
5+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "buffer", "buffer.csproj", "{E759E9F4-C162-BCB5-0357-673432E0B2E3}"
6+
EndProject
7+
Global
8+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
9+
Debug|Any CPU = Debug|Any CPU
10+
Release|Any CPU = Release|Any CPU
11+
EndGlobalSection
12+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
13+
{E759E9F4-C162-BCB5-0357-673432E0B2E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
14+
{E759E9F4-C162-BCB5-0357-673432E0B2E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
15+
{E759E9F4-C162-BCB5-0357-673432E0B2E3}.Release|Any CPU.ActiveCfg = Release|Any CPU
16+
{E759E9F4-C162-BCB5-0357-673432E0B2E3}.Release|Any CPU.Build.0 = Release|Any CPU
17+
EndGlobalSection
18+
GlobalSection(SolutionProperties) = preSolution
19+
HideSolutionNode = FALSE
20+
EndGlobalSection
21+
GlobalSection(ExtensibilityGlobals) = postSolution
22+
SolutionGuid = {1637F7DF-F89F-4246-8C8C-D3A294077E0F}
23+
EndGlobalSection
24+
EndGlobal

0 commit comments

Comments
 (0)