Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7e87adfc8d | ||
|
|
87729df01f | ||
|
|
18ad29b501 |
@@ -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",
|
||||||
@@ -97,6 +99,7 @@ public final class MainActivity extends Activity {
|
|||||||
private ScrollView terminalScroll;
|
private ScrollView terminalScroll;
|
||||||
private EditText inputField;
|
private EditText inputField;
|
||||||
private View terminalComposerBar;
|
private View terminalComposerBar;
|
||||||
|
private LinearLayout terminalGroupRow;
|
||||||
private String activeSessionName;
|
private String activeSessionName;
|
||||||
private String activeMainPage = PAGE_SERVERS;
|
private String activeMainPage = PAGE_SERVERS;
|
||||||
private String pendingImageUploadSession;
|
private String pendingImageUploadSession;
|
||||||
@@ -1085,6 +1088,7 @@ public final class MainActivity extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void openTerminal(String sessionName) {
|
private void openTerminal(String sessionName) {
|
||||||
|
closeTerminalSocket();
|
||||||
activeSessionName = sessionName;
|
activeSessionName = sessionName;
|
||||||
projectList = null;
|
projectList = null;
|
||||||
terminalScreen = new TerminalScreenBuffer(DEFAULT_TERMINAL_COLS, DEFAULT_TERMINAL_ROWS);
|
terminalScreen = new TerminalScreenBuffer(DEFAULT_TERMINAL_COLS, DEFAULT_TERMINAL_ROWS);
|
||||||
@@ -1099,6 +1103,10 @@ public final class MainActivity extends Activity {
|
|||||||
terminalRows = DEFAULT_TERMINAL_ROWS;
|
terminalRows = DEFAULT_TERMINAL_ROWS;
|
||||||
root.removeAllViews();
|
root.removeAllViews();
|
||||||
root.addView(createTerminalTopBar(sessionName), matchWrap());
|
root.addView(createTerminalTopBar(sessionName), matchWrap());
|
||||||
|
root.addView(createTerminalGroupBar(), new LinearLayout.LayoutParams(
|
||||||
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
|
dp(38)
|
||||||
|
));
|
||||||
|
|
||||||
terminalScroll = new ScrollView(this);
|
terminalScroll = new ScrollView(this);
|
||||||
terminalScroll.setFillViewport(true);
|
terminalScroll.setFillViewport(true);
|
||||||
@@ -1134,11 +1142,12 @@ 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);
|
||||||
connectTerminal(sessionName);
|
connectTerminal(sessionName);
|
||||||
|
refreshTerminalGroupSessions(sessionName);
|
||||||
});
|
});
|
||||||
inputField.post(() -> {
|
inputField.post(() -> {
|
||||||
inputField.requestFocus();
|
inputField.requestFocus();
|
||||||
@@ -1150,21 +1159,136 @@ public final class MainActivity extends Activity {
|
|||||||
LinearLayout bar = new LinearLayout(this);
|
LinearLayout bar = new LinearLayout(this);
|
||||||
bar.setOrientation(LinearLayout.HORIZONTAL);
|
bar.setOrientation(LinearLayout.HORIZONTAL);
|
||||||
bar.setGravity(Gravity.CENTER_VERTICAL);
|
bar.setGravity(Gravity.CENTER_VERTICAL);
|
||||||
bar.setPadding(dp(8), dp(6), dp(8), dp(6));
|
bar.setPadding(dp(5), dp(5), dp(5), dp(5));
|
||||||
bar.setBackgroundColor(Color.rgb(17, 20, 24));
|
bar.setBackgroundColor(Color.rgb(17, 20, 24));
|
||||||
bar.addView(toolbarButton("Back", view -> openSessionPage()));
|
bar.addView(terminalToolButton("‹", view -> openSessionPage()));
|
||||||
TextView title = new TextView(this);
|
TextView title = new TextView(this);
|
||||||
title.setText(sessionName);
|
title.setText(sessionName);
|
||||||
title.setTextColor(Color.WHITE);
|
title.setTextColor(Color.WHITE);
|
||||||
title.setTextSize(16);
|
title.setTextSize(15);
|
||||||
title.setTypeface(Typeface.DEFAULT_BOLD);
|
title.setTypeface(Typeface.DEFAULT_BOLD);
|
||||||
title.setPadding(dp(10), 0, dp(10), 0);
|
title.setSingleLine(true);
|
||||||
bar.addView(title, new LinearLayout.LayoutParams(0, dp(42), 1));
|
title.setPadding(dp(8), 0, dp(8), 0);
|
||||||
bar.addView(toolbarButton("Reconnect", view -> connectTerminal(sessionName)));
|
bar.addView(title, new LinearLayout.LayoutParams(0, dp(36), 1));
|
||||||
bar.addView(toolbarButton("More", view -> showTerminalActions(sessionName)));
|
bar.addView(terminalToolButton("↻", view -> connectTerminal(sessionName)));
|
||||||
|
bar.addView(terminalToolButton("⋯", view -> showTerminalActions(sessionName)));
|
||||||
return bar;
|
return bar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private HorizontalScrollView createTerminalGroupBar() {
|
||||||
|
HorizontalScrollView scroller = new HorizontalScrollView(this);
|
||||||
|
scroller.setHorizontalScrollBarEnabled(false);
|
||||||
|
scroller.setBackgroundColor(Color.rgb(13, 17, 22));
|
||||||
|
|
||||||
|
terminalGroupRow = new LinearLayout(this);
|
||||||
|
terminalGroupRow.setOrientation(LinearLayout.HORIZONTAL);
|
||||||
|
terminalGroupRow.setGravity(Gravity.CENTER_VERTICAL);
|
||||||
|
terminalGroupRow.setPadding(dp(5), dp(3), dp(5), dp(3));
|
||||||
|
terminalGroupRow.addView(groupLabel("group..."));
|
||||||
|
|
||||||
|
scroller.addView(terminalGroupRow, new HorizontalScrollView.LayoutParams(
|
||||||
|
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||||
|
ViewGroup.LayoutParams.MATCH_PARENT
|
||||||
|
));
|
||||||
|
return scroller;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void refreshTerminalGroupSessions(String sessionName) {
|
||||||
|
executor.execute(() -> {
|
||||||
|
try {
|
||||||
|
String text = api.kanbanProjects();
|
||||||
|
runOnUiThread(() -> renderTerminalGroupSessions(sessionName, text));
|
||||||
|
} catch (Exception error) {
|
||||||
|
runOnUiThread(() -> {
|
||||||
|
if (sessionName.equals(activeSessionName) && terminalGroupRow != null) {
|
||||||
|
terminalGroupRow.removeAllViews();
|
||||||
|
terminalGroupRow.addView(groupLabel("group failed"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderTerminalGroupSessions(String sessionName, String text) {
|
||||||
|
if (!sessionName.equals(activeSessionName) || terminalGroupRow == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
terminalGroupRow.removeAllViews();
|
||||||
|
try {
|
||||||
|
JSONObject rootObject = new JSONObject(text == null || text.isEmpty() ? "{}" : text);
|
||||||
|
JSONArray projects = rootObject.optJSONArray("projects");
|
||||||
|
if (projects == null) {
|
||||||
|
terminalGroupRow.addView(groupLabel("no group"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (int projectIndex = 0; projectIndex < projects.length(); projectIndex++) {
|
||||||
|
JSONObject project = projects.optJSONObject(projectIndex);
|
||||||
|
if (project == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
JSONArray agents = project.optJSONArray("agents");
|
||||||
|
if (!projectContainsSession(agents, sessionName)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
terminalGroupRow.addView(groupLabel(compactLabel(project.optString("name", "group"), 14)));
|
||||||
|
for (int agentIndex = 0; agents != null && agentIndex < agents.length(); agentIndex++) {
|
||||||
|
JSONObject agent = agents.optJSONObject(agentIndex);
|
||||||
|
String agentSession = agentSessionName(agent);
|
||||||
|
if (!agentSession.isEmpty()) {
|
||||||
|
terminalGroupRow.addView(groupSessionButton(agentSession, agentSession.equals(sessionName)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
terminalGroupRow.addView(groupLabel("no group"));
|
||||||
|
} catch (Exception error) {
|
||||||
|
terminalGroupRow.addView(groupLabel("group parse"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean projectContainsSession(JSONArray agents, String sessionName) {
|
||||||
|
if (agents == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (int index = 0; index < agents.length(); index++) {
|
||||||
|
if (sessionName.equals(agentSessionName(agents.optJSONObject(index)))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String agentSessionName(JSONObject agent) {
|
||||||
|
if (agent == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return defaultValue(agent.optString("sessionName", ""), agent.optString("name", ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
private TextView groupLabel(String text) {
|
||||||
|
TextView label = new TextView(this);
|
||||||
|
label.setText(text);
|
||||||
|
label.setTextColor(Color.rgb(139, 148, 158));
|
||||||
|
label.setTextSize(11);
|
||||||
|
label.setTypeface(Typeface.DEFAULT_BOLD);
|
||||||
|
label.setGravity(Gravity.CENTER_VERTICAL);
|
||||||
|
label.setPadding(dp(5), 0, dp(6), 0);
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Button groupSessionButton(String sessionName, boolean active) {
|
||||||
|
Button button = terminalToolButton(compactLabel(sessionName, 12), view -> {
|
||||||
|
if (!sessionName.equals(activeSessionName)) {
|
||||||
|
openTerminal(sessionName);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (active) {
|
||||||
|
button.setTextColor(Color.rgb(8, 12, 18));
|
||||||
|
button.setBackground(rounded(Color.rgb(86, 211, 219), 7, Color.rgb(86, 211, 219), 1));
|
||||||
|
}
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
private void showSessionActions(String sessionName) {
|
private void showSessionActions(String sessionName) {
|
||||||
String[] items = {
|
String[] items = {
|
||||||
"Status",
|
"Status",
|
||||||
@@ -1325,12 +1449,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 +2033,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 +2075,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, "Hm", "\u001b[H");
|
||||||
addSoftKey(row, "End", "\u001b[F");
|
addSoftKey(bottomRow, "End", "\u001b[F");
|
||||||
addSoftKey(row, "PgUp", "\u001b[5~");
|
addSoftKey(bottomRow, "Pg↑", "\u001b[5~");
|
||||||
addSoftKey(row, "PgDn", "\u001b[6~");
|
addSoftKey(bottomRow, "Pg↓", "\u001b[6~");
|
||||||
addSoftKey(row, "Tmux", "\u0002");
|
addSoftKey(bottomRow, "^B", "\u0002");
|
||||||
addSoftKey(row, "Detach", "\u0002d");
|
addSoftKey(bottomRow, "Dch", "\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, "↵", TERMINAL_ENTER);
|
||||||
addAccessoryButton(row, "NL", view -> insertComposerText("\n"));
|
addAccessoryButton(topRow, "NL", view -> insertComposerText("\n"));
|
||||||
addSoftButton(row, "Paste", view -> pasteClipboard());
|
addSoftButton(bottomRow, "Pst", view -> pasteClipboard());
|
||||||
addAccessoryButton(row, "Back", view -> backspaceComposerText());
|
addAccessoryButton(bottomRow, "⌫", view -> backspaceComposerText());
|
||||||
addAccessoryButton(row, "Kbd", view -> showKeyboard());
|
addAccessoryButton(bottomRow, "⌨", view -> showKeyboard());
|
||||||
addAccessoryButton(row, "Hide", view -> hideKeyboard());
|
addAccessoryButton(bottomRow, "⌄", view -> hideKeyboard());
|
||||||
addAccessoryButton(row, "Bottom", view -> scrollTerminalBottom());
|
addAccessoryButton(bottomRow, "⇣", view -> scrollTerminalBottom());
|
||||||
addAccessoryButton(row, "Select", view -> toggleTerminalSelection());
|
addAccessoryButton(bottomRow, "Sel", view -> toggleTerminalSelection());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2081,17 +2233,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 +2389,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)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2368,6 +2519,22 @@ public final class MainActivity extends Activity {
|
|||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Button terminalToolButton(String label, View.OnClickListener listener) {
|
||||||
|
Button button = toolbarButton(label, listener);
|
||||||
|
button.setTextSize(label.length() <= 2 ? 16 : 10);
|
||||||
|
button.setPadding(dp(5), 0, dp(5), 0);
|
||||||
|
button.setMinWidth(dp(label.length() <= 2 ? 36 : 48));
|
||||||
|
button.setMinimumWidth(dp(label.length() <= 2 ? 36 : 48));
|
||||||
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
|
||||||
|
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||||
|
dp(30)
|
||||||
|
);
|
||||||
|
params.leftMargin = dp(2);
|
||||||
|
params.rightMargin = dp(2);
|
||||||
|
button.setLayoutParams(params);
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
private void styleInput(EditText input) {
|
private void styleInput(EditText input) {
|
||||||
input.setTextColor(Color.rgb(240, 246, 252));
|
input.setTextColor(Color.rgb(240, 246, 252));
|
||||||
input.setHintTextColor(Color.rgb(139, 148, 158));
|
input.setHintTextColor(Color.rgb(139, 148, 158));
|
||||||
@@ -2431,14 +2598,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) {
|
||||||
@@ -2457,6 +2634,17 @@ public final class MainActivity extends Activity {
|
|||||||
return value == null || value.isEmpty() ? fallback : value;
|
return value == null || value.isEmpty() ? fallback : value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String compactLabel(String value, int maxChars) {
|
||||||
|
if (value == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
String trimmed = value.trim();
|
||||||
|
if (trimmed.length() <= maxChars) {
|
||||||
|
return trimmed;
|
||||||
|
}
|
||||||
|
return trimmed.substring(0, Math.max(1, maxChars - 1)) + "…";
|
||||||
|
}
|
||||||
|
|
||||||
private LinearLayout.LayoutParams matchWrap() {
|
private LinearLayout.LayoutParams matchWrap() {
|
||||||
return new LinearLayout.LayoutParams(
|
return new LinearLayout.LayoutParams(
|
||||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
|
|||||||
Executable
+115
@@ -0,0 +1,115 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
cat >&2 <<'EOF'
|
||||||
|
Usage: scripts/mirror-gitea-release.sh TAG APK_PATH [VERSION_CODE] [VERSION_NAME]
|
||||||
|
|
||||||
|
Mirrors an already-built APK to the Gitea release for TAG and uploads a
|
||||||
|
Gitea-specific latest.json.
|
||||||
|
|
||||||
|
Token source:
|
||||||
|
TMUX_GITEA_TOKEN environment variable, or hidden stdin prompt.
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ "${1:-}" = "-h" ] || [ "${1:-}" = "--help" ]; then
|
||||||
|
usage
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$#" -lt 2 ] || [ "$#" -gt 4 ]; then
|
||||||
|
usage
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
TAG="$1"
|
||||||
|
APK_PATH="$2"
|
||||||
|
VERSION_NAME="${4:-${TAG#v}}"
|
||||||
|
|
||||||
|
if [ ! -f "$APK_PATH" ]; then
|
||||||
|
echo "APK not found: $APK_PATH" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "${3:-}" ]; then
|
||||||
|
VERSION_CODE="$3"
|
||||||
|
else
|
||||||
|
IFS=. read -r MAJOR MINOR PATCH <<EOF
|
||||||
|
$VERSION_NAME
|
||||||
|
EOF
|
||||||
|
VERSION_CODE=$((MAJOR * 1000000 + MINOR * 1000 + PATCH))
|
||||||
|
fi
|
||||||
|
|
||||||
|
TOKEN="${TMUX_GITEA_TOKEN:-}"
|
||||||
|
if [ -z "$TOKEN" ]; then
|
||||||
|
printf "Gitea token: " >&2
|
||||||
|
IFS= read -rs TOKEN
|
||||||
|
printf "\n" >&2
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$TOKEN" ]; then
|
||||||
|
echo "Missing Gitea token." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
API_ROOT="https://gitea.neatcn.com/api/v1/repos/tmux/tmux-browser-android"
|
||||||
|
RELEASE_PAGE_URL="https://gitea.neatcn.com/tmux/tmux-browser-android/releases/tag/${TAG}"
|
||||||
|
APK_URL="https://gitea.neatcn.com/tmux/tmux-browser-android/releases/download/${TAG}/tmux-android.apk"
|
||||||
|
SHA256="$(sha256sum "$APK_PATH" | cut -d " " -f 1)"
|
||||||
|
WORK_DIR="$(mktemp -d)"
|
||||||
|
trap 'rm -rf "$WORK_DIR"' EXIT
|
||||||
|
|
||||||
|
LATEST_JSON="${WORK_DIR}/latest.json"
|
||||||
|
cat > "$LATEST_JSON" <<JSON
|
||||||
|
{
|
||||||
|
"versionCode": ${VERSION_CODE},
|
||||||
|
"versionName": "${VERSION_NAME}",
|
||||||
|
"apkUrl": "${APK_URL}",
|
||||||
|
"sha256": "${SHA256}",
|
||||||
|
"releasePageUrl": "${RELEASE_PAGE_URL}",
|
||||||
|
"minSdk": 26
|
||||||
|
}
|
||||||
|
JSON
|
||||||
|
|
||||||
|
RELEASE_JSON="${WORK_DIR}/release.json"
|
||||||
|
BODY='{"tag_name":"'"${TAG}"'","target_commitish":"main","name":"tmux Android '"${VERSION_NAME}"'","body":"Android APK for tmux-ui remote testing.","draft":false,"prerelease":false}'
|
||||||
|
|
||||||
|
if ! curl -fsSL \
|
||||||
|
-X POST \
|
||||||
|
-H "Authorization: token ${TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "$BODY" \
|
||||||
|
"${API_ROOT}/releases" \
|
||||||
|
-o "$RELEASE_JSON"; then
|
||||||
|
curl -fsSL \
|
||||||
|
-H "Authorization: token ${TOKEN}" \
|
||||||
|
"${API_ROOT}/releases/tags/${TAG}" \
|
||||||
|
-o "$RELEASE_JSON"
|
||||||
|
fi
|
||||||
|
|
||||||
|
RELEASE_ID="$(sed -n 's/^{"id":\([0-9][0-9]*\),.*/\1/p' "$RELEASE_JSON" | head -1)"
|
||||||
|
if [ -z "$RELEASE_ID" ]; then
|
||||||
|
echo "Cannot resolve Gitea release id for ${TAG}." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
upload_asset() {
|
||||||
|
local file="$1"
|
||||||
|
local name="$2"
|
||||||
|
local type="$3"
|
||||||
|
curl -fsSL \
|
||||||
|
-X POST \
|
||||||
|
-H "Authorization: token ${TOKEN}" \
|
||||||
|
-F "attachment=@${file};type=${type}" \
|
||||||
|
"${API_ROOT}/releases/${RELEASE_ID}/assets?name=${name}" \
|
||||||
|
-o "${WORK_DIR}/${name}.asset.json"
|
||||||
|
}
|
||||||
|
|
||||||
|
upload_asset "$APK_PATH" "tmux-android.apk" "application/vnd.android.package-archive"
|
||||||
|
upload_asset "$LATEST_JSON" "latest.json" "application/json"
|
||||||
|
|
||||||
|
echo "Mirrored ${TAG} to Gitea release ${RELEASE_ID}"
|
||||||
|
echo "versionCode=${VERSION_CODE}"
|
||||||
|
echo "versionName=${VERSION_NAME}"
|
||||||
|
echo "sha256=${SHA256}"
|
||||||
Reference in New Issue
Block a user