!747 !awt { m { static JTextArea textArea; static float fontSize = 24f; static S fontSnippet = //"#1000970" "#1000973" // Classic Trash 1 ; static S thinking = "[...]"; static Font loadFont() ctex { return Font.createFont(Font.TRUETYPE_FONT, loadLibrary(fontSnippet)).deriveFont(fontSize); } p { print("Chat ID: " + get(getJavaX(), "chatSend_id")); textArea = new JTextArea(); textArea.setFont(loadFont()); textArea.setMargin(new Insets(10, 10, 10, 10)); textArea.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER && e.getModifiers() == 0) { enterPressed(); } } }); makeFrame("Dialog 2", new JScrollPane(textArea)); sleep(); // important for auto-logging as of now } static void enterPressed() { S text = textArea.getText(); int idx = textArea.getCaretPosition(); // move to end of line first while (idx < text.length() && text.charAt(idx) != '\n') ++idx; textArea.setCaretPosition(idx); //print(quote(text.substring(0, idx))); int lineStart = text.lastIndexOf("\n", idx-1); //print(lineStart + " " + idx); final S line = text.substring(lineStart+1, idx); print("?? " + line); type(thinking); thread { processLine(line); } } static void processLine(S line) { sleep(1000); answer("hihi"); } static void answer(final S s) { awt { print("!! " + s); S text = textArea.getText(); int idx = text.indexOf(thinking); if (idx < 0) { print("Weird! Maybe user edited?"); return; } int cursor = textArea.getCaretPosition(); textArea.replaceRange(s, idx, idx+thinking.length()); if (cursor > idx+thinking.length()) textArea.setCaretPosition(cursor+s.length()-thinking.length()); } } static void type(S bla) { print("!! " + bla); textArea.insert("\n" + bla, textArea.getCaretPosition()); } }