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

69 configurable newline #70

Merged
merged 12 commits into from
Oct 3, 2024
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased (but available on Github)

- Added option to change the newLine character via `getNewlineCharacter()` and `setNewlineCharacter()` as suggest by [Roy](https://github.com/FunDeckHermit) in [#69](https://github.com/LennartHennigs/ESPTelnet/pull/69)

**Note:** Unreleased changes are checked in but not part of an official release (available through the Arduino IDE or PlatfomIO) yet. This allows you to test WiP features and give feedback to them.

## [2.2.1] – 2024-02-17
Expand Down
15 changes: 14 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 @@ -148,6 +149,12 @@ These are the constructors and the member functions the library provides:
void setKeepAliveInterval(int ms);
int getKeepAliveInterval();

bool isLineModeSet();
void setLineMode(bool value = true);

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

void onConnect(CallbackFunction f);
void onConnectionAttempt(CallbackFunction f);
void onReconnect(CallbackFunction f);
Expand Down Expand Up @@ -193,6 +200,12 @@ 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:

``` json
lennarthennigs/ESP Telnet@^2.2.2
```

## License

MIT License
Expand Down
4 changes: 3 additions & 1 deletion keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ flush KEYWORD2
write KEYWORD2
printf KEYWORD2
getTimeoutInterval KEYWORD2
setTimeoutInterval KEYWORD2
setTimeoutInterval KEYWORD2
getNewlineCharacter KEYWORD2
setNewlineCharacter KEYWORD2
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