4
4
/// This is an custom made input buffer so that we can get the output even if the user have not completed typing.
5
5
/// coded by @pradosh-arduino (github)
6
6
/// </summary>
7
- public class prad_buffer {
7
+ public class PradBuffer {
8
8
private char [ ] buffer ;
9
- private int buffer_size ;
9
+ private int BufferSize ;
10
10
11
11
/// <summary>
12
12
/// Stores the current index of the input buffer.
13
13
/// </summary>
14
- public int buffer_index = 0 ;
14
+ public int BufferIndex = 0 ;
15
15
16
16
/// <summary>
17
17
/// Stores the total length of the input buffer.
18
18
/// </summary>
19
- public int length = 0 ;
19
+ public int Length = 0 ;
20
20
21
21
/// <summary>
22
22
/// Constructor to initialize the buffer with its size.
23
23
/// </summary>
24
- public prad_buffer ( )
24
+ public PradBuffer ( )
25
25
{
26
- buffer_size = 1024 ;
27
- buffer = new char [ buffer_size ] ;
26
+ BufferSize = 1024 ;
27
+ buffer = new char [ BufferSize ] ;
28
28
}
29
29
30
30
/// <summary>
31
31
/// Constructor to initialize the buffer with your own size.
32
32
/// </summary>
33
33
/// <param name="size">The size of the buffer.</param>
34
- public prad_buffer ( int size )
34
+ public PradBuffer ( int size )
35
35
{
36
- buffer_size = size ;
37
- buffer = new char [ buffer_size ] ;
36
+ BufferSize = size ;
37
+ buffer = new char [ BufferSize ] ;
38
38
}
39
39
40
40
/// <summary>
41
41
/// Function to add a character to the buffer.
42
42
/// </summary>
43
43
/// <param name="c">The character to be added.</param>
44
- public void add_char ( char c ) {
45
- if ( buffer_index >= buffer . Length )
44
+ public void AddChar ( char c ) {
45
+ if ( BufferIndex >= buffer . Length )
46
46
return ;
47
47
48
- buffer [ buffer_index ] = c ;
49
- buffer_index ++ ;
50
- length ++ ;
48
+ buffer [ BufferIndex ] = c ;
49
+ BufferIndex ++ ;
50
+ Length ++ ;
51
51
}
52
52
53
53
/// <summary>
54
54
/// Clears the buffer for next usage, This function will not be automatically called, you have to call by yourself.
55
55
/// </summary>
56
- public void clear_buffer ( ) {
56
+ public void ClearBuffer ( ) {
57
57
for ( int i = 0 ; i < buffer . Length ; i ++ ) {
58
58
buffer [ i ] = '\0 ' ;
59
59
}
60
60
61
- buffer_index = 0 ;
62
- length = 0 ;
61
+ BufferIndex = 0 ;
62
+ Length = 0 ;
63
63
}
64
64
65
65
/// <summary>
66
66
/// Gets the input and stores it in the input buffer array cleanly. It does <b>NOT</b> return the buffer.
67
67
/// </summary>
68
- public void get_input ( ) {
68
+ public void GetInput ( ) {
69
69
ConsoleKeyInfo current ;
70
70
71
71
while ( true )
@@ -76,12 +76,12 @@ public void get_input(){
76
76
77
77
if ( current . Key == ConsoleKey . Enter )
78
78
{
79
- if ( length != 0 )
79
+ if ( Length != 0 )
80
80
Console . WriteLine ( ) ;
81
81
82
- for ( int i = 0 ; i < length ; i ++ ) {
82
+ for ( int i = 0 ; i < Length ; i ++ ) {
83
83
if ( buffer [ i ] == '\0 ' ) {
84
- length = i ;
84
+ Length = i ;
85
85
break ;
86
86
}
87
87
}
@@ -90,36 +90,36 @@ public void get_input(){
90
90
}
91
91
else if ( current . Key == ConsoleKey . Backspace )
92
92
{
93
- if ( buffer_index > 0 )
93
+ if ( BufferIndex > 0 )
94
94
{
95
- buffer_index -- ;
96
- length -- ;
95
+ BufferIndex -- ;
96
+ Length -- ;
97
97
Console . Write ( "\b \b " ) ;
98
98
}
99
99
}
100
100
else if ( current . Key == ConsoleKey . LeftArrow ) {
101
101
if ( Console . CursorLeft > 0 ) {
102
102
Console . CursorLeft -- ;
103
- buffer_index -- ;
103
+ BufferIndex -- ;
104
104
}
105
105
}
106
106
else if ( current . Key == ConsoleKey . RightArrow ) {
107
- if ( Console . CursorLeft < length ) {
107
+ if ( Console . CursorLeft < Length ) {
108
108
Console . CursorLeft ++ ;
109
- buffer_index ++ ;
109
+ BufferIndex ++ ;
110
110
}
111
111
}
112
112
else if ( current . Key == ConsoleKey . Home ) {
113
113
Console . Write ( "\r " ) ;
114
- buffer_index = 0 ;
114
+ BufferIndex = 0 ;
115
115
}
116
116
else if ( current . Key == ConsoleKey . End ) {
117
- Console . CursorLeft = length ;
118
- buffer_index = length ;
117
+ Console . CursorLeft = Length ;
118
+ BufferIndex = Length ;
119
119
}
120
120
else
121
121
{
122
- add_char ( current . KeyChar ) ;
122
+ AddChar ( current . KeyChar ) ;
123
123
Console . Write ( current . KeyChar ) ;
124
124
}
125
125
}
@@ -129,7 +129,7 @@ public void get_input(){
129
129
/// Gets the input and stores it in the input buffer array cleanly. It does <b>NOT</b> return the buffer. We can add a prefix to the input.
130
130
/// </summary>
131
131
/// <param name="prefix">The actual prefix needed to be displayed</param>
132
- public void get_input ( string prefix ) {
132
+ public void GetInput ( string prefix ) {
133
133
ConsoleKeyInfo current ;
134
134
135
135
Console . Write ( prefix ) ;
@@ -142,12 +142,12 @@ public void get_input(string prefix){
142
142
143
143
if ( current . Key == ConsoleKey . Enter )
144
144
{
145
- if ( length != 0 )
145
+ if ( Length != 0 )
146
146
Console . WriteLine ( ) ;
147
147
148
- for ( int i = 0 ; i < length ; i ++ ) {
148
+ for ( int i = 0 ; i < Length ; i ++ ) {
149
149
if ( buffer [ i ] == '\0 ' ) {
150
- length = i ;
150
+ Length = i ;
151
151
break ;
152
152
}
153
153
}
@@ -156,37 +156,37 @@ public void get_input(string prefix){
156
156
}
157
157
else if ( current . Key == ConsoleKey . Backspace )
158
158
{
159
- if ( buffer_index > 0 )
159
+ if ( BufferIndex > 0 )
160
160
{
161
- buffer_index -- ;
162
- length -- ;
161
+ BufferIndex -- ;
162
+ Length -- ;
163
163
Console . Write ( "\b \b " ) ;
164
164
}
165
165
}
166
166
else if ( current . Key == ConsoleKey . LeftArrow ) {
167
167
if ( Console . CursorLeft > prefix . Length ) {
168
168
Console . CursorLeft -- ;
169
- buffer_index -- ;
169
+ BufferIndex -- ;
170
170
}
171
171
}
172
172
else if ( current . Key == ConsoleKey . RightArrow ) {
173
- if ( Console . CursorLeft < length + prefix . Length ) {
173
+ if ( Console . CursorLeft < Length + prefix . Length ) {
174
174
Console . CursorLeft ++ ;
175
- buffer_index ++ ;
175
+ BufferIndex ++ ;
176
176
}
177
177
}
178
178
else if ( current . Key == ConsoleKey . Home ) {
179
179
Console . Write ( "\r " ) ;
180
180
Console . CursorLeft += prefix . Length ;
181
- buffer_index = 0 ;
181
+ BufferIndex = 0 ;
182
182
}
183
183
else if ( current . Key == ConsoleKey . End ) {
184
- Console . CursorLeft = length + prefix . Length ;
185
- buffer_index = length ;
184
+ Console . CursorLeft = Length + prefix . Length ;
185
+ BufferIndex = Length ;
186
186
}
187
187
else
188
188
{
189
- add_char ( current . KeyChar ) ;
189
+ AddChar ( current . KeyChar ) ;
190
190
Console . Write ( current . KeyChar ) ;
191
191
}
192
192
}
@@ -196,34 +196,34 @@ public void get_input(string prefix){
196
196
/// Function to get the buffer values.
197
197
/// </summary>
198
198
/// <returns>It returns the buffer as an character array.</returns>
199
- public char [ ] get_buffer ( ) {
199
+ public char [ ] GetBuffer ( ) {
200
200
return buffer ;
201
201
}
202
202
203
203
/// <summary>
204
204
/// Function to get the buffer array as a string.
205
205
/// </summary>
206
206
/// <returns>A proper string with buffer values.</returns>
207
- public string get_buffer_as_string ( ) {
208
- return new string ( buffer , 0 , length ) ;
207
+ public string GetBufferAsString ( ) {
208
+ return new string ( buffer , 0 , Length ) ;
209
209
}
210
210
211
211
/// <summary>
212
212
/// Function to get the allocated buffer size.
213
213
/// </summary>
214
214
/// <returns>The buffer size in integer.</returns>
215
- public int get_buffer_size ( ) {
216
- return buffer_size ;
215
+ public int GetBufferSize ( ) {
216
+ return BufferSize ;
217
217
}
218
218
219
219
/// <summary>
220
220
/// Function to set the buffer size.
221
221
/// This function will <b>CLEAR</b> the buffer and reallocate the buffer with the new size.
222
222
/// </summary>
223
223
/// <param name="size">The size of buffer (default is 1024)</param>
224
- public void set_buffer_size ( int size ) {
225
- buffer_size = size ;
226
- buffer = new char [ buffer_size ] ;
224
+ public void SetBufferSize ( int size ) {
225
+ BufferSize = size ;
226
+ buffer = new char [ BufferSize ] ;
227
227
}
228
228
}
229
229
}
0 commit comments