You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sk...@apache.org on 2022/08/22 09:52:43 UTC

[ignite-3] branch main updated: IGNITE-17346 Ignite3 CLI long output not readable in windows terminal. Fixes #985

This is an automated email from the ASF dual-hosted git repository.

sk0x50 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/main by this push:
     new 3e475a338c IGNITE-17346 Ignite3 CLI long output not readable in windows terminal. Fixes #985
3e475a338c is described below

commit 3e475a338c15080ba989be9cc757cd9fd36993d3
Author: Vadim Pakhnushev <86...@users.noreply.github.com>
AuthorDate: Mon Aug 22 12:52:29 2022 +0300

    IGNITE-17346 Ignite3 CLI long output not readable in windows terminal. Fixes #985
    
    Signed-off-by: Slava Koptilin <sl...@gmail.com>
---
 .../cli/core/flow/builder/FlowBuilderImpl.java      |  8 +++++++-
 .../repl/context/CommandLineContextProvider.java    | 21 +++++++++++++++++++++
 .../ignite/cli/core/repl/executor/ReplExecutor.java |  7 +++++++
 3 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/modules/cli/src/main/java/org/apache/ignite/cli/core/flow/builder/FlowBuilderImpl.java b/modules/cli/src/main/java/org/apache/ignite/cli/core/flow/builder/FlowBuilderImpl.java
index 2769c667b7..2de366e741 100644
--- a/modules/cli/src/main/java/org/apache/ignite/cli/core/flow/builder/FlowBuilderImpl.java
+++ b/modules/cli/src/main/java/org/apache/ignite/cli/core/flow/builder/FlowBuilderImpl.java
@@ -32,6 +32,7 @@ import org.apache.ignite.cli.core.flow.FlowInterruptException;
 import org.apache.ignite.cli.core.flow.Flowable;
 import org.apache.ignite.cli.core.flow.question.QuestionAnswer;
 import org.apache.ignite.cli.core.flow.question.QuestionAskerFactory;
+import org.apache.ignite.cli.core.repl.context.CommandLineContextProvider;
 
 /**
  * Implementation of {@link FlowBuilder}.
@@ -100,7 +101,12 @@ public class FlowBuilderImpl<I, O> implements FlowBuilder<I, O> {
     public FlowBuilder<I, O> toOutput(PrintWriter output, PrintWriter errorOutput) {
         return new FlowBuilderImpl<>(flow.composite(input -> {
             if (input.hasResult()) {
-                output.println(decoratorRegistry.getDecorator(input.type()).decorate(input.value()).toTerminalString());
+                // Workaround for the https://issues.apache.org/jira/browse/IGNITE-17346
+                // This will turn the tailtips off before printing
+                CommandLineContextProvider.print(() -> {
+                    String out = decoratorRegistry.getDecorator(input.type()).decorate(input.value()).toTerminalString();
+                    output.println(out);
+                });
             } else if (input.hasError()) {
                 exceptionHandlers.handleException(ExceptionWriter.fromPrintWriter(errorOutput), input.errorCause());
                 return Flowable.empty();
diff --git a/modules/cli/src/main/java/org/apache/ignite/cli/core/repl/context/CommandLineContextProvider.java b/modules/cli/src/main/java/org/apache/ignite/cli/core/repl/context/CommandLineContextProvider.java
index 05bcba3ee4..eea15fc474 100644
--- a/modules/cli/src/main/java/org/apache/ignite/cli/core/repl/context/CommandLineContextProvider.java
+++ b/modules/cli/src/main/java/org/apache/ignite/cli/core/repl/context/CommandLineContextProvider.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.cli.core.repl.context;
 
 import java.io.PrintWriter;
+import java.util.function.Consumer;
 import picocli.CommandLine;
 
 /**
@@ -28,6 +29,8 @@ public class CommandLineContextProvider {
 
     private static volatile CommandLine cmd;
 
+    private static volatile Consumer<Runnable> printWrapper = Runnable::run;
+
     /**
      * Getter for {@link CommandLineContext}.
      *
@@ -50,4 +53,22 @@ public class CommandLineContextProvider {
     public static void setCmd(CommandLine cmd) {
         CommandLineContextProvider.cmd = cmd;
     }
+
+    /**
+     * Sets the wrapper which will be used when printing from the flow.
+     *
+     * @param printWrapper print wrapper.
+     */
+    public static void setPrintWrapper(Consumer<Runnable> printWrapper) {
+        CommandLineContextProvider.printWrapper = printWrapper;
+    }
+
+    /**
+     * Passes the @{link Runnable} to the print wrapper.
+     *
+     * @param printer lambda which will be wrapped.
+     */
+    public static void print(Runnable printer) {
+        printWrapper.accept(printer);
+    }
 }
diff --git a/modules/cli/src/main/java/org/apache/ignite/cli/core/repl/executor/ReplExecutor.java b/modules/cli/src/main/java/org/apache/ignite/cli/core/repl/executor/ReplExecutor.java
index b97b9032a6..7d7bf0071f 100644
--- a/modules/cli/src/main/java/org/apache/ignite/cli/core/repl/executor/ReplExecutor.java
+++ b/modules/cli/src/main/java/org/apache/ignite/cli/core/repl/executor/ReplExecutor.java
@@ -103,6 +103,13 @@ public class ReplExecutor {
                 TailTipWidgets widgets = new TailTipWidgets(reader, registry::commandDescription, 5,
                         TailTipWidgets.TipType.COMPLETER);
                 widgets.enable();
+                // Workaround for the https://issues.apache.org/jira/browse/IGNITE-17346
+                // Turn off tailtip widgets before printing to the output
+                CommandLineContextProvider.setPrintWrapper(printer -> {
+                    widgets.disable();
+                    printer.run();
+                    widgets.enable();
+                });
                 // Workaround for jline issue where TailTipWidgets will produce NPE when passed a bracket
                 registry.setScriptDescription(cmdLine -> null);
             }