Compare commits

...
2 Commits
Author SHA1 Message Date
Codex f1db46ecbe Replace heuristic reading with chat toggle
Gitea Smoke / smoke (push) Successful in 0s
Gitea Android APK / build (push) Successful in 12m3s
2026-07-12 09:45:38 +00:00
Codex c0904e6aaa Show live terminal status in chat
Gitea Smoke / smoke (push) Successful in 1s
Gitea Android APK / build (push) Successful in 12m9s
2026-07-12 09:03:14 +00:00
2 changed files with 98 additions and 48 deletions
@@ -23,7 +23,6 @@ import android.os.Looper;
import android.provider.Settings;
import android.text.TextUtils;
import android.text.InputType;
import android.text.method.LinkMovementMethod;
import android.view.Gravity;
import android.view.HapticFeedbackConstants;
import android.view.KeyEvent;
@@ -73,8 +72,7 @@ public final class MainActivity extends Activity {
private static final int STATUS_SUCCESS = 2;
private static final int STATUS_ERROR = 3;
private static final int TERMINAL_VIEW_CHAT = 0;
private static final int TERMINAL_VIEW_READING = 1;
private static final int TERMINAL_VIEW_FULL = 2;
private static final int TERMINAL_VIEW_FULL = 1;
private static final long TERMINAL_RENDER_INTERVAL_MS = 80L;
private static final long[] SOCKET_RECONNECT_DELAYS_MS = {1000L, 2000L, 4000L, 8000L, 15000L};
private static final int COLOR_APP_BG = Color.rgb(18, 20, 24);
@@ -132,6 +130,8 @@ public final class MainActivity extends Activity {
private Button terminalReadingButton;
private ScrollView terminalScroll;
private LinearLayout terminalChatList;
private TextView terminalLiveStatusText;
private TextView terminalLiveOutputText;
private EditText inputField;
private final Button[] terminalAccessoryTabButtons = new Button[4];
private View terminalAccessoryBar;
@@ -151,7 +151,6 @@ public final class MainActivity extends Activity {
private int lastActiveSessionCount = -1;
private TerminalScreenBuffer terminalScreen = new TerminalScreenBuffer(DEFAULT_TERMINAL_COLS, DEFAULT_TERMINAL_ROWS);
private final StringBuilder queuedTerminalInput = new StringBuilder();
private final Set<String> terminalExpandedBlocks = new HashSet<>();
private final Set<String> terminalExpandedMessages = new HashSet<>();
private final List<ConversationMessage> terminalConversationMessages = new ArrayList<>();
private boolean terminalConnected;
@@ -1611,9 +1610,10 @@ public final class MainActivity extends Activity {
terminalSelectionEnabled = false;
terminalFollowOutput = true;
terminalKeyPage = 0;
terminalExpandedBlocks.clear();
terminalExpandedMessages.clear();
terminalConversationMessages.clear();
terminalLiveStatusText = null;
terminalLiveOutputText = null;
terminalImagePath = "";
terminalImagePreviewBar = null;
terminalImagePreview = null;
@@ -1762,25 +1762,17 @@ public final class MainActivity extends Activity {
dp(13)
));
bar.addView(titleBlock, new LinearLayout.LayoutParams(0, dp(32), 1));
terminalReadingButton = terminalToolButton("", view -> showTerminalViewPicker());
terminalReadingButton.setContentDescription("Choose chat or terminal view");
terminalReadingButton = terminalToolButton("", view -> showTerminalView(
terminalViewMode == TERMINAL_VIEW_CHAT ? TERMINAL_VIEW_FULL : TERMINAL_VIEW_CHAT,
true
));
terminalReadingButton.setContentDescription("Toggle chat and terminal view");
styleTerminalReadingButton();
bar.addView(terminalReadingButton);
bar.addView(terminalToolButton("", view -> showTerminalActions(sessionName)));
return bar;
}
private void showTerminalViewPicker() {
String[] items = {"Chat", "Chinese reading", "Full terminal"};
new AlertDialog.Builder(this)
.setTitle("Session view")
.setSingleChoiceItems(items, terminalViewMode, (dialog, which) -> {
showTerminalView(which, true);
dialog.dismiss();
})
.show();
}
private void showTerminalView(int mode, boolean announce) {
terminalViewMode = mode;
if (terminalScroll == null || terminalText == null || terminalChatList == null) {
@@ -1795,10 +1787,9 @@ public final class MainActivity extends Activity {
));
renderTerminalConversation();
} else {
boolean reading = mode == TERMINAL_VIEW_READING;
terminalText.setHorizontallyScrolling(!reading);
terminalText.setGravity((reading ? Gravity.TOP : Gravity.BOTTOM) | Gravity.START);
terminalText.setMovementMethod(reading ? LinkMovementMethod.getInstance() : null);
terminalText.setHorizontallyScrolling(true);
terminalText.setGravity(Gravity.BOTTOM | Gravity.START);
terminalText.setMovementMethod(null);
terminalScroll.addView(terminalText, new ScrollView.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
@@ -1807,9 +1798,7 @@ public final class MainActivity extends Activity {
}
styleTerminalReadingButton();
if (announce) {
setStatus(mode == TERMINAL_VIEW_CHAT
? "Chat view"
: mode == TERMINAL_VIEW_READING ? "Chinese reading mode" : "Full terminal mode");
setStatus(mode == TERMINAL_VIEW_CHAT ? "Chat view" : "Full terminal mode");
}
}
@@ -1817,11 +1806,10 @@ public final class MainActivity extends Activity {
if (terminalReadingButton == null) {
return;
}
terminalReadingButton.setText(terminalViewMode == TERMINAL_VIEW_CHAT
? "" : terminalViewMode == TERMINAL_VIEW_READING ? "" : "");
terminalReadingButton.setTextColor(terminalViewMode != TERMINAL_VIEW_FULL
terminalReadingButton.setText(terminalViewMode == TERMINAL_VIEW_CHAT ? "" : "");
terminalReadingButton.setTextColor(terminalViewMode == TERMINAL_VIEW_CHAT
? Color.rgb(14, 38, 24) : COLOR_TEXT_MUTED);
terminalReadingButton.setBackground(terminalViewMode != TERMINAL_VIEW_FULL
terminalReadingButton.setBackground(terminalViewMode == TERMINAL_VIEW_CHAT
? rounded(COLOR_ACCENT, 7, COLOR_ACCENT, 1)
: buttonBackground());
}
@@ -1959,13 +1947,15 @@ public final class MainActivity extends Activity {
if (terminalConversationMessages.isEmpty()) {
TextView empty = bodyText("No structured messages yet");
empty.setGravity(Gravity.CENTER);
empty.setPadding(dp(12), dp(32), dp(12), dp(32));
empty.setPadding(dp(12), dp(24), dp(12), dp(24));
terminalChatList.addView(empty, matchWrap());
return;
}
for (ConversationMessage message : terminalConversationMessages) {
terminalChatList.addView(conversationMessageRow(message));
} else {
for (ConversationMessage message : terminalConversationMessages) {
terminalChatList.addView(conversationMessageRow(message));
}
}
terminalChatList.addView(conversationLiveTerminalPanel(), matchWrap());
updateTerminalLivePanel();
if (terminalViewMode == TERMINAL_VIEW_CHAT && terminalFollowOutput && terminalScroll != null) {
terminalScroll.post(() -> terminalScroll.fullScroll(View.FOCUS_DOWN));
}
@@ -2066,7 +2056,62 @@ public final class MainActivity extends Activity {
private String conversationStatusPart(ConversationMessage message) {
String status = message.status.trim();
return status.isEmpty() || "complete".equals(status) ? "" : " · " + status;
return status.isEmpty() ? "" : " · " + status;
}
private View conversationLiveTerminalPanel() {
LinearLayout panel = new LinearLayout(this);
panel.setOrientation(LinearLayout.VERTICAL);
panel.setPadding(dp(12), dp(9), dp(12), dp(10));
panel.setBackground(rounded(COLOR_FIELD, 8, COLOR_BORDER, 1));
panel.setOnClickListener(view -> showTerminalView(TERMINAL_VIEW_FULL, true));
LinearLayout heading = new LinearLayout(this);
heading.setOrientation(LinearLayout.HORIZONTAL);
heading.setGravity(Gravity.CENTER_VERTICAL);
TextView title = new TextView(this);
title.setText("Live terminal");
title.setTextColor(COLOR_TEXT);
title.setTextSize(11);
title.setTypeface(Typeface.DEFAULT_BOLD);
heading.addView(title, new LinearLayout.LayoutParams(0, dp(22), 1));
terminalLiveStatusText = new TextView(this);
terminalLiveStatusText.setTextSize(9);
terminalLiveStatusText.setTypeface(Typeface.MONOSPACE);
terminalLiveStatusText.setSingleLine(true);
heading.addView(terminalLiveStatusText, new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
dp(22)
));
panel.addView(heading, matchWrap());
terminalLiveOutputText = new TextView(this);
terminalLiveOutputText.setTextColor(COLOR_TEXT_MUTED);
terminalLiveOutputText.setTextSize(10);
terminalLiveOutputText.setTypeface(Typeface.MONOSPACE);
terminalLiveOutputText.setMaxLines(6);
terminalLiveOutputText.setEllipsize(TextUtils.TruncateAt.END);
terminalLiveOutputText.setPadding(0, dp(5), 0, 0);
panel.addView(terminalLiveOutputText, matchWrap());
TextView hint = bodyText("Tap for full terminal");
hint.setTextSize(9);
hint.setTextColor(COLOR_TEXT_DIM);
hint.setPadding(0, dp(6), 0, 0);
panel.addView(hint, matchWrap());
return panel;
}
private void updateTerminalLivePanel() {
if (terminalLiveStatusText == null || terminalLiveOutputText == null) {
return;
}
String socket = terminalSocketStatus.toLowerCase(java.util.Locale.ROOT);
boolean connected = socket.contains("connected") && !socket.contains("disconnected");
terminalLiveStatusText.setText(connected ? "● connected" : "" + defaultValue(socket, "connecting"));
terminalLiveStatusText.setTextColor(connected ? COLOR_SUCCESS
: socket.contains("error") || socket.contains("disconnected") ? COLOR_DANGER : COLOR_ACCENT_WARM);
terminalLiveOutputText.setText(terminalScreen.renderTail(6));
}
private void updateTerminalMeta() {
@@ -2085,6 +2130,7 @@ public final class MainActivity extends Activity {
terminalConnectionText.setText("● connecting");
terminalConnectionText.setTextColor(COLOR_ACCENT_WARM);
}
updateTerminalLivePanel();
}
private String compactTerminalPath(String path) {
@@ -3545,19 +3591,9 @@ public final class MainActivity extends Activity {
return;
}
lastTerminalRenderMs = System.currentTimeMillis();
if (terminalViewMode == TERMINAL_VIEW_READING) {
terminalText.setMovementMethod(LinkMovementMethod.getInstance());
terminalText.setHighlightColor(Color.TRANSPARENT);
terminalText.setText(terminalScreen.renderFocused(terminalExpandedBlocks, key -> {
if (!terminalExpandedBlocks.add(key)) {
terminalExpandedBlocks.remove(key);
}
renderTerminalNow();
}));
} else {
terminalText.setMovementMethod(null);
terminalText.setText(terminalScreen.render());
}
terminalText.setMovementMethod(null);
terminalText.setText(terminalScreen.render());
updateTerminalLivePanel();
if (terminalViewMode != TERMINAL_VIEW_CHAT && terminalFollowOutput) {
terminalScroll.post(() -> terminalScroll.fullScroll(View.FOCUS_DOWN));
}
@@ -130,6 +130,20 @@ final class TerminalScreenBuffer {
return output;
}
String renderTail(int maxRows) {
List<String> visible = new ArrayList<>();
for (int row = rows - 1; row >= 0 && visible.size() < maxRows; row--) {
String text = rowText(row).trim();
if (!text.isEmpty()) {
visible.add(0, text);
}
}
if (visible.isEmpty()) {
return "Waiting for terminal output";
}
return String.join("\n", visible);
}
CharSequence renderFocused(Set<String> expandedBlocks, FocusToggle toggle) {
SpannableStringBuilder output = new SpannableStringBuilder();
List<String> hiddenRows = new ArrayList<>();