From 1406f96fe47dbd453c92feb5b9641364c032518d Mon Sep 17 00:00:00 2001 From: DmitriyMX Date: Fri, 18 Dec 2015 10:44:37 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=20=D0=B2?= =?UTF-8?q?=D1=8B=D0=B2=D0=BE=D0=B4=D0=B0=20ShellPrintStream?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ru/dmitriymx/shell/ShellPrintStream.java | 52 +++++++++++++------ 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/src/main/java/ru/dmitriymx/shell/ShellPrintStream.java b/src/main/java/ru/dmitriymx/shell/ShellPrintStream.java index 5a2141f..8e49cdf 100644 --- a/src/main/java/ru/dmitriymx/shell/ShellPrintStream.java +++ b/src/main/java/ru/dmitriymx/shell/ShellPrintStream.java @@ -34,30 +34,50 @@ public class ShellPrintStream extends PrintStream { this.formatter = formatter; } + private void _print(String s) { + writer.print(ConsoleReader.RESET_LINE); + if (formatter != null) { //TODO убрать проверку null + s = formatter.format(s); + } + writer.print(s); + cleanTrashLine(s); + writer.println(); + try { + consoleReader.drawLine(); + } catch (IOException e) { + // ignore + } + writer.flush(); + } + @Override public void write(byte[] bytes, int off, int len) { if (consoleReader != null) { - String s = new String(bytes); - - writer.print(ConsoleReader.RESET_LINE); - if (formatter != null) { - writer.print(formatter.format(s)); - } else { - writer.print(s); - } - cleanTrashLine(s); - writer.println(); - try { - consoleReader.drawLine(); - } catch (IOException e) { - // ignore - } - writer.flush(); + if ((char)bytes[len-1] == '\n') len--; //TODO проверить в windows + _print(new String(bytes, off, len)); } else { super.write(bytes, off, len); } } + @Override + public void print(String s) { + if (consoleReader != null) { + _print(s); + } else { + super.print(s); + } + } + + @Override + public void println(String s) { + if (consoleReader != null) { + _print(s); + } else { + super.println(s); + } + } + /** * Очистка печатной строки от мусора */