MCPcopy Create free account
hub / github.com/SmingHub/Sming / processKey

Method processKey

Sming/Core/Data/Buffer/LineBuffer.cpp:27–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25}
26
27LineBufferBase::Action LineBufferBase::processKey(char key, ReadWriteStream* output)
28{
29 auto prevKey = previousKey;
30 previousKey = key;
31
32 switch(key) {
33 case '\x1b': // ESC -> delete current commandLine
34 clear();
35 if(output) {
36 output->println();
37 }
38 return Action::clear;
39
40 case '\b': // delete (backspace)
41 case '\x7f': // xterm ctrl-?
42 if(!backspace()) {
43 return Action::none;
44 }
45 if(output) {
46 output->print("\b \b");
47 }
48 return Action::backspace;
49
50 case '\r':
51 case '\n':
52 // For "\r\n" or "\n\r" sequence ignore second key
53 if(prevKey != key && (prevKey == '\r' || prevKey == '\n')) {
54 previousKey = '\0';
55 return Action::none;
56 }
57 if(output) {
58 output->println();
59 }
60 return Action::submit;
61
62 default:
63 if(!addChar(key)) {
64 return Action::none;
65 }
66 if(output) {
67 output->print(key);
68 }
69 return Action::echo;
70 }
71}
72
73char LineBufferBase::addChar(char c)
74{

Callers 1

processMethod · 0.80

Calls 2

printlnMethod · 0.80
printMethod · 0.45

Tested by

no test coverage detected