Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made the newline character configurable #69

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ If you find this library helpful please consider giving it a ⭐️ at [GitHub](

### Output and Input

* Via `print()` and `println()` you can output text on the telnet server.
* Via `print()`, `printf()` and `println()` you can output text on the telnet server.
* To receive and parse input from the telnet client you can add a handler via `onInputReceived()`.
* By default, the library waits for a newline character from the client, and sends data to the callback handler one line at a time. This behaviour can be deactivated by calling `setlineMode(false)`.
* A default newline character `'\n'` is used to determine the end of a line. This can be overridden by by calling `setNewlineCharacter('\r')` where `'\r'` can be swapped with any character.

### Using stream functions

Expand Down Expand Up @@ -193,6 +194,11 @@ These are the constructors and the member functions the library provides:
Open the Arduino IDE choose "Sketch > Include Library" and search for "ESPTelnet".
Or download the [ZIP archive](https://github.com/lennarthennigs/ESPTelnet/zipball/master), and choose "Sketch > Include Library > Add .ZIP Library..." and select the downloaded file.

The "ESPTelnet" library is also available on the PlatformIO registry and can be included by adding the following line to the leb_deps option of the platformio.ini file:
```
lennarthennigs/ESP Telnet@^2.2.2
```

## License

MIT License
Expand Down
16 changes: 14 additions & 2 deletions src/ESPTelnet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ void ESPTelnet::handleInput() {
char c = client.read();
// collect string
if (_lineMode) {
if (c != '\n') {
if (c != _newlineCharacter) {
if (c >= 32 && c < 127) {
input += c;
}
Expand Down Expand Up @@ -81,4 +81,16 @@ void ESPTelnet::setLineMode(bool value /* = true */) {
_lineMode = value;
}

/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////

char ESPTelnet::getNewlineCharacter() {
return _newlineCharacter;
}

/////////////////////////////////////////////////////////////////

void ESPTelnet::setNewlineCharacter(char value /* = '\n' */) {
_newlineCharacter = value;
}

/////////////////////////////////////////////////////////////////
6 changes: 5 additions & 1 deletion src/ESPTelnet.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,12 @@ class ESPTelnet : public ESPTelnetBase {
bool isLineModeSet();
void setLineMode(bool value = true);

protected:
char getNewlineCharacter();
void setNewlineCharacter(char value = '\n');

protected:
bool _lineMode = true;
char _newlineCharacter = '\n';

void handleInput();
};
Expand Down