Disable telnet output colors on command TelnetColor 0

This commit is contained in:
Theo Arends 2025-03-24 12:04:01 +01:00
parent 9d6640a42e
commit 52f3306f15

View File

@ -21,10 +21,12 @@
* TelnetColor - Show prompt, response and log colors * TelnetColor - Show prompt, response and log colors
* TelnetColor 0 - Disable color codes from output * TelnetColor 0 - Disable color codes from output
* TelnetColor 1 - Set colors to defined colors * TelnetColor 1 - Set colors to defined colors
* TelnetColor 2 - Enable last set colors
* TelnetColor 33,32,37 - Set prompt (yellow), response (green) and log (white) colors * TelnetColor 33,32,37 - Set prompt (yellow), response (green) and log (white) colors
* *
* To start telnet at restart add a rule like * To start telnet at restart add one of below rules like
* on system#boot do backlog telnetcolor 33,32,36; telnet 1 endon * on system#boot do backlog telnetcolor 33,32,36; telnet 1 endon
* on system#boot do backlog telnetcolor 0; telnet 1 endon
* *
* Supported ANSI Escape Color codes: * Supported ANSI Escape Color codes:
* Normal Bright * Normal Bright
@ -67,12 +69,13 @@ struct {
uint8_t prompt; uint8_t prompt;
uint8_t color[3]; uint8_t color[3];
bool ip_filter_enabled; bool ip_filter_enabled;
bool color_disable;
} Telnet; } Telnet;
/********************************************************************************************/ /********************************************************************************************/
void TelnetWriteColor(uint32_t color) { void TelnetWriteColor(uint32_t color) {
if (color != 39) { // No default color so use ANSI color escape codes if (!Telnet.color_disable) {
Telnet.client.printf("\x1b[%dm", color); Telnet.client.printf("\x1b[%dm", color);
} }
} }
@ -130,7 +133,7 @@ void TelnetLoop(void) {
uint32_t index = 1; uint32_t index = 1;
char* line; char* line;
size_t len; size_t len;
while (GetLog(TasmotaGlobal.seriallog_level, &index, &line, &len)) { while (GetLog(Settings->seriallog_level, &index, &line, &len)) {
TelnetWrite(line, len -1); TelnetWrite(line, len -1);
} }
Telnet.prompt = 0; Telnet.prompt = 0;
@ -156,7 +159,7 @@ void TelnetLoop(void) {
char* line; char* line;
size_t len; size_t len;
bool any_line = false; bool any_line = false;
while (GetLog(TasmotaGlobal.seriallog_level, &index, &line, &len)) { while (GetLog(Settings->seriallog_level, &index, &line, &len)) {
any_line = true; any_line = true;
TelnetWrite(line, len -1); TelnetWrite(line, len -1);
} }
@ -305,15 +308,15 @@ void CmndTelnetColor(void) {
// TelnetColor - Show prompt, response and log colors // TelnetColor - Show prompt, response and log colors
// TelnetColor 0 - Disable color codes from output // TelnetColor 0 - Disable color codes from output
// TelnetColor 1 - Set colors to defined colors // TelnetColor 1 - Set colors to defined colors
// TelnetColor 2 - Enable last set colors
// TelnetColor 33,32,37 - Set prompt (yellow), response (green) and log (white) colors // TelnetColor 33,32,37 - Set prompt (yellow), response (green) and log (white) colors
if (XdrvMailbox.data_len > 0) { if (XdrvMailbox.data_len > 0) {
uint32_t colors[sizeof(Telnet.color)]; uint32_t colors[sizeof(Telnet.color)];
uint32_t count = ParseParameters(sizeof(Telnet.color), colors); uint32_t count = ParseParameters(sizeof(Telnet.color), colors);
Telnet.color_disable = false;
if (1 == count) { if (1 == count) {
if (0 == colors[0]) { // TelnetColor 0 if (0 == colors[0]) { // TelnetColor 0
Telnet.color[0] = 39; Telnet.color_disable = true;
Telnet.color[1] = 39;
Telnet.color[2] = 39;
} }
else if (1 == colors[0]) { // TelnetColor 1 else if (1 == colors[0]) { // TelnetColor 1
Telnet.color[0] = TELNET_COL_PROMPT; Telnet.color[0] = TELNET_COL_PROMPT;
@ -327,9 +330,13 @@ void CmndTelnetColor(void) {
} }
} }
} }
if (Telnet.color_disable) {
ResponseCmndStateText(!Telnet.color_disable);
} else {
Response_P(PSTR("{\"%s\":[%d,%d,%d]}"), Response_P(PSTR("{\"%s\":[%d,%d,%d]}"),
XdrvMailbox.command, Telnet.color[0], Telnet.color[1], Telnet.color[2]); XdrvMailbox.command, Telnet.color[0], Telnet.color[1], Telnet.color[2]);
} }
}
/*********************************************************************************************\ /*********************************************************************************************\
* Interface * Interface