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

serial-monitor: Support LF line-ending mode and fix split-up line-endings #894

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,26 @@ public void actionPerformed(final @NotNull AnActionEvent e) {
}
}

private byte lastByte = '\0';

public void append(byte[] dataChunk) {
// todo quick and dirty fix for https://bitbucket.org/dmitry_cherkas/intellij-serial-monitor/issues/1
//todo crlf
String text = new String(dataChunk, getCharset()).replaceAll("\r", "");
Charset charset = getCharset();
StringBuilder sb = new StringBuilder();

// handle the case where \r\n is split across chunks
if (lastByte == '\r' && dataChunk.length > 0 && dataChunk[0] == '\n') {
sb.append(new String(dataChunk, 1, dataChunk.length - 1, charset));
}
else {
sb.append(new String(dataChunk, charset));
}

// update the last byte of the chunk
if (dataChunk.length > 0) {
lastByte = dataChunk[dataChunk.length - 1];
}

String text = sb.toString().replaceAll("\r\n?", "\n");
getPrimaryConsoleView().print(text, ConsoleViewContentType.NORMAL_OUTPUT);
getSecondaryConsoleView().output(dataChunk);
}
Expand Down