package net.morimekta.testapp;

import net.morimekta.console.InputSelection;
import net.morimekta.console.Terminal;
import net.morimekta.console.chr.Char;
import net.morimekta.util.Strings;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * Test application for testing out the console functionality.
 * Since much of the console IO is dependent on a unix-like
 * terminal to work, it cannot be truly tested in a unit.
 */
public class Interactive {
    public static void main(String[] args) throws IOException {
        try (Terminal term = new Terminal()) {
            List<String> entries = new ArrayList<>();
            for (int i = 0; i < 100; ++i) {
                entries.add("line number --- " + (i + 1) + "...");
            }

            List<InputSelection.Command<String>> commands = new ArrayList<>();

            commands.add(new InputSelection.Command<>(Char.CR, "select", (e, p) -> InputSelection.Reaction.SELECT, true));
            commands.add(new InputSelection.Command<>('r', "reverse", (e, p) -> {
                Collections.reverse(entries);
                return InputSelection.Reaction.UPDATE_KEEP_ITEM;
            }));
            commands.add(new InputSelection.Command<>('q', "quit", (e, p) -> InputSelection.Reaction.EXIT));

            InputSelection.EntryPrinter<String> printer = (e, c) -> e;

            InputSelection<String> input = new InputSelection<>(term, "Select a line...", entries, commands, printer);
            String line = input.select();
            if (line != null) {
                term.formatln(" -- Got: \"%s\"", Strings.escape(line));
            }
        }
    }
}

@@ -148,16 +148,141 @@
 r.Char;%0A
+import net.morimekta.console.chr.CharUtil;%0Aimport net.morimekta.console.chr.Unicode;%0Aimport net.morimekta.util.ExtraStreams;%0A
 import n
@@ -308,16 +308,16 @@
 trings;%0A
-
 %0Aimport 
@@ -369,33 +369,8 @@
 st;%0A
-import java.util.Arrays;%0A
 impo
@@ -417,16 +417,92 @@
 il.List;
+%0Aimport java.util.stream.Collectors;%0A%0Aimport static java.lang.String.format;
 %0A%0A/**%0A *
@@ -857,35 +857,254 @@
 tries = 
-new ArrayList%3C%3E();%0A
+ExtraStreams.range(0x0000, 0x10000, 4)%0A                                               .mapToObj(i -%3E %7B%0A                                                   StringBuilder builder = new StringBuilder();%0A                                       
         
@@ -1120,27 +1120,29 @@
 int 
-i = 0; i %3C 100
+c = i; c %3C i + 4
 ; ++
-i
+c
 ) %7B%0A
@@ -1161,73 +1161,1261 @@
     
-entries.add(%22line number --- %22 + (i + 1) + %22...%22);%0A            %7D%0A
+                                       Unicode u = new Unicode(c);%0A                                                       String cs = u.toString();%0A%0A                                                       // Actual control chars.%0A                                                       if (u.asInteger() %3C 0x100 && u.printableWidth() == 0) %7B%0A                                                           cs = %22%3C*%3E%22;%0A                                                       %7D%0A%0A                                                       builder.append(%22%7C %22);%0A                                                       builder.append(CharUtil.leftJust(format(%0A                                                               %220x%2504x:  %25-8s  %5C%22%25s%5C%22%22,%0A                                                               u.asInteger(),%0A                                                               %22'%22 + u.asString() + %22'%22,%0A                                                               cs), 26));%0A                                                   %7D%0A                                                   builder.append('%7C');%0A                                                   return builder.toString();%0A                                               %7D).collect(Collectors.toList());
 %0A   

Use interactive test to display all unicode chars.