File tree 1 file changed +18
-2
lines changed
1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ using chip::Shell::streamer_get;
31
31
32
32
namespace {
33
33
34
- void ReadLine (char * buffer, size_t max)
34
+ ssize_t ReadLine (char * buffer, size_t max)
35
35
{
36
36
ssize_t read = 0 ;
37
37
bool done = false ;
@@ -56,6 +56,15 @@ void ReadLine(char * buffer, size_t max)
56
56
*inptr = 0 ; // null terminate
57
57
done = true ;
58
58
break ;
59
+ case 0x04 :
60
+ // Delete EOT character.
61
+ inptr -= 1 ;
62
+ // Stop the read loop if the input is still empty.
63
+ if (inptr == buffer - 1 )
64
+ {
65
+ done = true ;
66
+ }
67
+ break ;
59
68
case 0x7F :
60
69
// delete backspace character + 1 more
61
70
inptr -= 2 ;
@@ -84,6 +93,9 @@ void ReadLine(char * buffer, size_t max)
84
93
read --;
85
94
}
86
95
}
96
+
97
+ // Return the length of the buffer including the terminating null byte.
98
+ return inptr - buffer;
87
99
}
88
100
89
101
bool IsSeparator (char ch)
@@ -186,7 +198,11 @@ void Engine::RunMainLoop()
186
198
while (true )
187
199
{
188
200
char * line = static_cast <char *>(Platform::MemoryAlloc (CHIP_SHELL_MAX_LINE_SIZE));
189
- ReadLine (line, CHIP_SHELL_MAX_LINE_SIZE);
201
+ if (ReadLine (line, CHIP_SHELL_MAX_LINE_SIZE) == 0 )
202
+ {
203
+ // Stop loop in case of empty read (Ctrl-D).
204
+ break ;
205
+ }
190
206
#if CONFIG_DEVICE_LAYER
191
207
DeviceLayer::PlatformMgr ().ScheduleWork (ProcessShellLine, reinterpret_cast <intptr_t >(line));
192
208
#else
You can’t perform that action at this time.
0 commit comments