Refine terminal keys and send input
Gitea Smoke / smoke (push) Successful in 0s
Gitea Android APK / build (push) Failing after 8m37s

This commit is contained in:
Codex
2026-07-08 23:19:48 +00:00
parent 18ad29b501
commit 87729df01f
@@ -59,6 +59,7 @@ public final class MainActivity extends Activity {
private static final int MAX_TERMINAL_COLS = 140; private static final int MAX_TERMINAL_COLS = 140;
private static final int MIN_TERMINAL_ROWS = 8; private static final int MIN_TERMINAL_ROWS = 8;
private static final int MAX_TERMINAL_ROWS = 80; private static final int MAX_TERMINAL_ROWS = 80;
private static final int TERMINAL_KEYS_HEIGHT_DP = 76;
private static final int STATUS_NORMAL = 0; private static final int STATUS_NORMAL = 0;
private static final int STATUS_BUSY = 1; private static final int STATUS_BUSY = 1;
private static final int STATUS_SUCCESS = 2; private static final int STATUS_SUCCESS = 2;
@@ -73,6 +74,7 @@ public final class MainActivity extends Activity {
private static final String PAGE_TOOLS = "Tools"; private static final String PAGE_TOOLS = "Tools";
private static final String PAGE_UPDATE = "Update"; private static final String PAGE_UPDATE = "Update";
private static final String PAGE_ABOUT = "About"; private static final String PAGE_ABOUT = "About";
private static final String TERMINAL_ENTER = "\n";
private static final String[] SERVER_PROFILES = { private static final String[] SERVER_PROFILES = {
"http://100.89.0.116:3000", "http://100.89.0.116:3000",
"http://100.89.0.2:3000", "http://100.89.0.2:3000",
@@ -1134,7 +1136,7 @@ public final class MainActivity extends Activity {
root.addView(terminalComposerBar, matchWrap()); root.addView(terminalComposerBar, matchWrap());
root.addView(createAccessoryBar(), new LinearLayout.LayoutParams( root.addView(createAccessoryBar(), new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT,
dp(48) dp(TERMINAL_KEYS_HEIGHT_DP)
)); ));
terminalScroll.post(() -> { terminalScroll.post(() -> {
resizeTerminalToViewport(false); resizeTerminalToViewport(false);
@@ -1325,12 +1327,18 @@ public final class MainActivity extends Activity {
inputField.setCursorVisible(true); inputField.setCursorVisible(true);
inputField.setFocusableInTouchMode(true); inputField.setFocusableInTouchMode(true);
inputField.setGravity(Gravity.TOP | Gravity.START); inputField.setGravity(Gravity.TOP | Gravity.START);
inputField.setImeOptions(EditorInfo.IME_ACTION_NONE); inputField.setImeOptions(EditorInfo.IME_ACTION_SEND | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
inputField.setInputType(InputType.TYPE_CLASS_TEXT inputField.setInputType(InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_MULTI_LINE
| InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
styleComposerInput(inputField); styleComposerInput(inputField);
inputField.setOnEditorActionListener((view, actionId, event) -> { inputField.setOnEditorActionListener((view, actionId, event) -> {
if (actionId == EditorInfo.IME_ACTION_SEND
|| actionId == EditorInfo.IME_ACTION_GO
|| actionId == EditorInfo.IME_ACTION_DONE) {
sendLine();
return true;
}
if (event != null if (event != null
&& event.getKeyCode() == KeyEvent.KEYCODE_ENTER && event.getKeyCode() == KeyEvent.KEYCODE_ENTER
&& event.isShiftPressed() && event.isShiftPressed()
@@ -1903,21 +1911,41 @@ public final class MainActivity extends Activity {
scroller.setHorizontalScrollBarEnabled(false); scroller.setHorizontalScrollBarEnabled(false);
scroller.setBackgroundColor(Color.rgb(22, 27, 34)); scroller.setBackgroundColor(Color.rgb(22, 27, 34));
LinearLayout row = new LinearLayout(this); LinearLayout pad = new LinearLayout(this);
row.setOrientation(LinearLayout.HORIZONTAL); pad.setOrientation(LinearLayout.VERTICAL);
row.setGravity(Gravity.CENTER_VERTICAL); pad.setPadding(dp(5), dp(4), dp(5), dp(4));
row.setPadding(dp(6), dp(4), dp(6), dp(4));
addAccessoryButton(row, "<", view -> setTerminalKeyPage(terminalKeyPage - 1)); LinearLayout firstRow = terminalKeyRow();
addPageLabel(row); LinearLayout secondRow = terminalKeyRow();
addAccessoryPageKeys(row); addAccessoryButton(firstRow, "<", view -> setTerminalKeyPage(terminalKeyPage - 1));
addAccessoryButton(row, ">", view -> setTerminalKeyPage(terminalKeyPage + 1)); addPageLabel(firstRow);
scroller.addView(row, new HorizontalScrollView.LayoutParams( addAccessoryPageKeys(firstRow, secondRow);
addAccessoryButton(firstRow, ">", view -> setTerminalKeyPage(terminalKeyPage + 1));
pad.addView(firstRow, new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
0,
1
));
pad.addView(secondRow, new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
0,
1
));
scroller.addView(pad, new HorizontalScrollView.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.MATCH_PARENT ViewGroup.LayoutParams.MATCH_PARENT
)); ));
return scroller; return scroller;
} }
private LinearLayout terminalKeyRow() {
LinearLayout row = new LinearLayout(this);
row.setOrientation(LinearLayout.HORIZONTAL);
row.setGravity(Gravity.CENTER_VERTICAL);
return row;
}
private void addPageLabel(LinearLayout row) { private void addPageLabel(LinearLayout row) {
TextView label = new TextView(this); TextView label = new TextView(this);
label.setText(accessoryPageName()); label.setText(accessoryPageName());
@@ -1925,62 +1953,64 @@ public final class MainActivity extends Activity {
label.setTextSize(11); label.setTextSize(11);
label.setGravity(Gravity.CENTER); label.setGravity(Gravity.CENTER);
label.setTypeface(Typeface.DEFAULT_BOLD); label.setTypeface(Typeface.DEFAULT_BOLD);
row.addView(label, new LinearLayout.LayoutParams(dp(58), ViewGroup.LayoutParams.MATCH_PARENT)); row.addView(label, new LinearLayout.LayoutParams(dp(44), ViewGroup.LayoutParams.MATCH_PARENT));
} }
private void addAccessoryPageKeys(LinearLayout row) { private void addAccessoryPageKeys(LinearLayout topRow, LinearLayout bottomRow) {
switch (terminalKeyPage) { switch (terminalKeyPage) {
case 1: case 1:
addSoftKey(row, "Esc", "\u001b"); addSoftKey(topRow, "Esc", "\u001b");
addSoftKey(row, "Tab", "\t"); addSoftKey(topRow, "Tab", "\t");
addSoftKey(row, "^C", "\u0003"); addSoftKey(topRow, "^C", "\u0003");
addSoftKey(row, "^D", "\u0004"); addSoftKey(topRow, "^D", "\u0004");
addSoftKey(row, "^L", "\u000c"); addSoftKey(topRow, "^L", "\u000c");
addSoftKey(row, "^R", "\u0012"); addSoftKey(bottomRow, "^R", "\u0012");
addSoftKey(row, "^A", "\u0001"); addSoftKey(bottomRow, "^A", "\u0001");
addSoftKey(row, "^E", "\u0005"); addSoftKey(bottomRow, "^E", "\u0005");
addSoftKey(bottomRow, "^U", "\u0015");
addSoftKey(bottomRow, "^K", "\u000b");
break; break;
case 2: case 2:
addSoftKey(row, "Left", "\u001b[D"); addSoftKey(topRow, "", "\u001b[D");
addSoftKey(row, "Right", "\u001b[C"); addSoftKey(topRow, "", "\u001b[C");
addSoftKey(row, "Up", "\u001b[A"); addSoftKey(topRow, "", "\u001b[A");
addSoftKey(row, "Down", "\u001b[B"); addSoftKey(topRow, "", "\u001b[B");
addSoftKey(row, "Home", "\u001b[H"); addSoftKey(topRow, "Home", "\u001b[H");
addSoftKey(row, "End", "\u001b[F"); addSoftKey(bottomRow, "End", "\u001b[F");
addSoftKey(row, "PgUp", "\u001b[5~"); addSoftKey(bottomRow, "PgUp", "\u001b[5~");
addSoftKey(row, "PgDn", "\u001b[6~"); addSoftKey(bottomRow, "PgDn", "\u001b[6~");
addSoftKey(row, "Tmux", "\u0002"); addSoftKey(bottomRow, "Tmux", "\u0002");
addSoftKey(row, "Detach", "\u0002d"); addSoftKey(bottomRow, "Detach", "\u0002d");
addSoftKey(row, "New", "\u0002c"); addSoftKey(bottomRow, "New", "\u0002c");
addSoftKey(row, "Prev", "\u0002p"); addSoftKey(bottomRow, "Prev", "\u0002p");
addSoftKey(row, "Next", "\u0002n"); addSoftKey(bottomRow, "Next", "\u0002n");
break; break;
case 3: case 3:
addTextKey(row, "/", "/"); addTextKey(topRow, "/", "/");
addTextKey(row, "-", "-"); addTextKey(topRow, "-", "-");
addTextKey(row, "_", "_"); addTextKey(topRow, "_", "_");
addTextKey(row, ".", "."); addTextKey(topRow, ".", ".");
addTextKey(row, "~", "~"); addTextKey(topRow, "~", "~");
addTextKey(row, "|", "|"); addTextKey(bottomRow, "|", "|");
addTextKey(row, "&", "&"); addTextKey(bottomRow, "&", "&");
addTextKey(row, ";", ";"); addTextKey(bottomRow, ";", ";");
addTextKey(row, "$", "$"); addTextKey(bottomRow, "$", "$");
addTextKey(row, "Space", " "); addTextKey(bottomRow, "Space", " ");
break; break;
case 0: case 0:
default: default:
addComposerButton(row, "Left", () -> moveComposerCursor(-1)); addComposerButton(topRow, "", () -> moveComposerCursor(-1));
addComposerButton(row, "Right", () -> moveComposerCursor(1)); addComposerButton(topRow, "", () -> moveComposerCursor(1));
addSoftKey(row, "Up", "\u001b[A"); addSoftKey(topRow, "", "\u001b[A");
addSoftKey(row, "Down", "\u001b[B"); addSoftKey(topRow, "", "\u001b[B");
addSoftKey(row, "Enter", "\r"); addSoftKey(topRow, "Enter", TERMINAL_ENTER);
addAccessoryButton(row, "NL", view -> insertComposerText("\n")); addAccessoryButton(topRow, "NL", view -> insertComposerText("\n"));
addSoftButton(row, "Paste", view -> pasteClipboard()); addSoftButton(bottomRow, "Paste", view -> pasteClipboard());
addAccessoryButton(row, "Back", view -> backspaceComposerText()); addAccessoryButton(bottomRow, "Back", view -> backspaceComposerText());
addAccessoryButton(row, "Kbd", view -> showKeyboard()); addAccessoryButton(bottomRow, "Kbd", view -> showKeyboard());
addAccessoryButton(row, "Hide", view -> hideKeyboard()); addAccessoryButton(bottomRow, "Hide", view -> hideKeyboard());
addAccessoryButton(row, "Bottom", view -> scrollTerminalBottom()); addAccessoryButton(bottomRow, "Bottom", view -> scrollTerminalBottom());
addAccessoryButton(row, "Select", view -> toggleTerminalSelection()); addAccessoryButton(bottomRow, "Select", view -> toggleTerminalSelection());
break; break;
} }
} }
@@ -2081,17 +2111,16 @@ public final class MainActivity extends Activity {
} }
String text = inputField.getText().toString(); String text = inputField.getText().toString();
if (text.isEmpty()) { if (text.isEmpty()) {
sendTerminalInput("\r"); sendTerminalInput(TERMINAL_ENTER);
return; return;
} }
String normalized = text.replace("\r\n", "\n").replace('\r', '\n').replace('\n', '\r'); String normalized = text.replace("\r\n", "\n").replace('\r', '\n');
if (!normalized.endsWith("\r")) { if (!normalized.endsWith(TERMINAL_ENTER)) {
normalized = normalized + "\r"; normalized = normalized + TERMINAL_ENTER;
} }
terminalFollowOutput = true; terminalFollowOutput = true;
sendTerminalInput(normalized); sendTerminalInput(normalized);
inputField.setText(""); inputField.setText("");
hideKeyboard();
setStatus("Sent " + text.length() + " chars"); setStatus("Sent " + text.length() + " chars");
} }
@@ -2238,7 +2267,7 @@ public final class MainActivity extends Activity {
root.removeViewAt(composerIndex + 1); root.removeViewAt(composerIndex + 1);
root.addView(createAccessoryBar(), composerIndex + 1, new LinearLayout.LayoutParams( root.addView(createAccessoryBar(), composerIndex + 1, new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT,
dp(48) dp(TERMINAL_KEYS_HEIGHT_DP)
)); ));
} }
@@ -2431,14 +2460,24 @@ public final class MainActivity extends Activity {
private void addSoftButton(LinearLayout row, String label, View.OnClickListener listener) { private void addSoftButton(LinearLayout row, String label, View.OnClickListener listener) {
Button button = toolbarButton(label, listener); Button button = toolbarButton(label, listener);
button.setTextSize(11); button.setTextSize(isArrowLabel(label) ? 17 : 10);
button.setPadding(dp(8), 0, dp(8), 0); button.setPadding(dp(5), 0, dp(5), 0);
button.setMinWidth(dp("Space".equals(label) ? 72 : 50)); int width = "Space".equals(label) ? 64 : (isArrowLabel(label) ? 38 : 44);
button.setMinimumWidth(dp("Space".equals(label) ? 72 : 50)); button.setMinWidth(dp(width));
row.addView(button, new LinearLayout.LayoutParams( button.setMinimumWidth(dp(width));
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.MATCH_PARENT ViewGroup.LayoutParams.MATCH_PARENT
)); );
params.leftMargin = dp(2);
params.rightMargin = dp(2);
params.topMargin = dp(1);
params.bottomMargin = dp(1);
row.addView(button, params);
}
private boolean isArrowLabel(String label) {
return "".equals(label) || "".equals(label) || "".equals(label) || "".equals(label);
} }
private TextView bodyText(String text) { private TextView bodyText(String text) {