From 1dbb35a8a784f627dcddfd41f1b8df478be9f8a6 Mon Sep 17 00:00:00 2001 From: Janne Valkealahti Date: Tue, 13 Aug 2024 14:26:32 +0100 Subject: [PATCH] StringInput better unicode handling - Add unicode handling in flow components in AbstractTextComponent which allows StringInput to process unicode given from jline. - This add basic non-english character support for input. - Backport #1115 - Fixes #1116 --- .../shell/component/StringInput.java | 3 ++- .../component/support/AbstractComponent.java | 3 ++- .../support/AbstractTextComponent.java | 3 ++- .../shell/component/StringInputTests.java | 25 ++++++++++++++++++- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/spring-shell-core/src/main/java/org/springframework/shell/component/StringInput.java b/spring-shell-core/src/main/java/org/springframework/shell/component/StringInput.java index e0855b91..5a972c1b 100644 --- a/spring-shell-core/src/main/java/org/springframework/shell/component/StringInput.java +++ b/spring-shell-core/src/main/java/org/springframework/shell/component/StringInput.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -94,6 +94,7 @@ public class StringInput extends AbstractTextComponent> implement public final static String OPERATION_EXIT = "EXIT"; public final static String OPERATION_BACKSPACE = "BACKSPACE"; public final static String OPERATION_CHAR = "CHAR"; + public final static String OPERATION_UNICODE = "UNICODE"; public final static String OPERATION_SELECT = "SELECT"; public final static String OPERATION_DOWN = "DOWN"; public final static String OPERATION_UP = "UP"; diff --git a/spring-shell-core/src/main/java/org/springframework/shell/component/support/AbstractTextComponent.java b/spring-shell-core/src/main/java/org/springframework/shell/component/support/AbstractTextComponent.java index 8d214bd1..6dc26589 100644 --- a/spring-shell-core/src/main/java/org/springframework/shell/component/support/AbstractTextComponent.java +++ b/spring-shell-core/src/main/java/org/springframework/shell/component/support/AbstractTextComponent.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -62,6 +62,7 @@ public abstract class AbstractTextComponent empty = ComponentContext.empty(); + StringInput component1 = new StringInput(getTerminal(), "component1", "component1ResultValue"); + component1.setResourceLoader(new DefaultResourceLoader()); + component1.setTemplateExecutor(getTemplateExecutor()); + + service.execute(() -> { + StringInputContext run1Context = component1.run(empty); + result1.set(run1Context); + latch1.countDown(); + }); + + TestBuffer testBuffer = new TestBuffer().append("😂").cr(); + write(testBuffer.getBytes()); + + latch1.await(2, TimeUnit.SECONDS); + StringInputContext run1Context = result1.get(); + + assertThat(run1Context).isNotNull(); + assertThat(run1Context.getResultValue()).isEqualTo("😂"); + } + @Test public void testPassingViaContext() throws InterruptedException { ComponentContext empty = ComponentContext.empty();