Skip to content

Commit

Permalink
StringInput better unicode handling
Browse files Browse the repository at this point in the history
- 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.
- Fixes #1115
  • Loading branch information
jvalkeal committed Aug 13, 2024
1 parent 9021238 commit 2786b01
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -94,6 +94,7 @@ protected boolean read(BindingReader bindingReader, KeyMap<String> keyMap, Strin
}
String input;
switch (operation) {
case OPERATION_UNICODE:
case OPERATION_CHAR:
String lastBinding = bindingReader.getLastBinding();
input = context.getInput();
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -60,6 +60,7 @@ public abstract class AbstractComponent<T extends ComponentContext<T>> 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";
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -62,6 +62,7 @@ protected void bindKeyMap(KeyMap<String> keyMap) {
for (char i = 32; i < KeyMap.KEYMAP_LENGTH - 1; i++) {
keyMap.bind(OPERATION_CHAR, Character.toString(i));
}
keyMap.setUnicode(OPERATION_UNICODE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -166,6 +166,29 @@ public void testResultUserInput() throws InterruptedException {
assertThat(run1Context.getResultValue()).isEqualTo("test");
}

@Test
public void testResultUserInputUnicode() throws InterruptedException {
ComponentContext<?> 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();
Expand Down

0 comments on commit 2786b01

Please sign in to comment.