Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f103e9e065 | ||
|
|
6a1052d437 | ||
|
|
7e028b09d4 |
@@ -2722,7 +2722,7 @@ public final class MainActivity extends Activity {
|
||||
private LinearLayout createAccessoryBar() {
|
||||
LinearLayout panel = new LinearLayout(this);
|
||||
panel.setOrientation(LinearLayout.VERTICAL);
|
||||
panel.setPadding(dp(6), dp(3), dp(6), dp(3));
|
||||
panel.setPadding(dp(4), dp(3), dp(4), dp(3));
|
||||
panel.setBackgroundColor(COLOR_PANEL);
|
||||
|
||||
HorizontalScrollView keyScroller = new HorizontalScrollView(this);
|
||||
@@ -2773,8 +2773,6 @@ public final class MainActivity extends Activity {
|
||||
addSoftKey(row, "End", "\u001b[F");
|
||||
addSoftKey(row, "Pg↑", "\u001b[5~");
|
||||
addSoftKey(row, "Pg↓", "\u001b[6~");
|
||||
addComposerButton(row, "Prev", () -> setTerminalKeyPage(terminalKeyPage - 1));
|
||||
addComposerButton(row, "Next", () -> setTerminalKeyPage(terminalKeyPage + 1));
|
||||
addSoftKey(row, "Clear", "\u000c");
|
||||
addSoftKey(row, "Detach", "\u0002d");
|
||||
break;
|
||||
@@ -2800,12 +2798,12 @@ public final class MainActivity extends Activity {
|
||||
addSoftKey(row, "↓", "\u001b[B");
|
||||
addSoftKey(row, "Esc", "\u001b");
|
||||
addSoftKey(row, "Tab", "\t");
|
||||
addSoftKey(row, "Enter", TERMINAL_ENTER);
|
||||
addSoftKey(row, "↵", TERMINAL_ENTER);
|
||||
addSoftButton(row, "Paste", view -> pasteClipboard());
|
||||
addComposerButton(row, "⌫", this::backspaceComposerText);
|
||||
addTextKey(row, "NL", "\n");
|
||||
addComposerButton(row, "Bottom", this::scrollTerminalBottom);
|
||||
addComposerButton(row, "Select", () -> {
|
||||
addComposerButton(row, "Bot", this::scrollTerminalBottom);
|
||||
addComposerButton(row, "Sel", () -> {
|
||||
terminalSelectionEnabled = !terminalSelectionEnabled;
|
||||
if (terminalText != null) {
|
||||
terminalText.setTextIsSelectable(terminalSelectionEnabled);
|
||||
@@ -3339,9 +3337,9 @@ public final class MainActivity extends Activity {
|
||||
private void addSoftButton(LinearLayout row, String label, View.OnClickListener listener) {
|
||||
Button button = toolbarButton(label, listener);
|
||||
button.setTextSize(isArrowLabel(label) ? 14 : 9);
|
||||
button.setPadding(dp(5), 0, dp(5), 0);
|
||||
button.setMinWidth(dp(38));
|
||||
button.setMinimumWidth(dp(38));
|
||||
button.setPadding(dp(2), 0, dp(2), 0);
|
||||
button.setMinWidth(dp(24));
|
||||
button.setMinimumWidth(dp(24));
|
||||
button.setMinHeight(0);
|
||||
button.setMinimumHeight(0);
|
||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
|
||||
@@ -3349,7 +3347,6 @@ public final class MainActivity extends Activity {
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
0
|
||||
);
|
||||
params.leftMargin = dp(1);
|
||||
params.rightMargin = dp(1);
|
||||
row.addView(button, params);
|
||||
}
|
||||
@@ -3698,9 +3695,14 @@ public final class MainActivity extends Activity {
|
||||
throw new IllegalStateException("Cannot open selected image");
|
||||
}
|
||||
String response = api.uploadImage(sessionName, readAllBytes(input));
|
||||
String imagePath = new JSONObject(response).optString("absolutePath", "").trim();
|
||||
if (imagePath.isEmpty()) {
|
||||
throw new IllegalStateException("Upload response did not include absolutePath");
|
||||
}
|
||||
runOnUiThread(() -> {
|
||||
progressBar.setVisibility(View.GONE);
|
||||
showTextDialog("Image upload", response);
|
||||
insertComposerPath(imagePath);
|
||||
setStatus("Image path inserted");
|
||||
});
|
||||
} catch (Exception error) {
|
||||
runOnUiThread(() -> {
|
||||
@@ -3722,6 +3724,21 @@ public final class MainActivity extends Activity {
|
||||
return output.toByteArray();
|
||||
}
|
||||
|
||||
private void insertComposerPath(String path) {
|
||||
if (inputField == null) {
|
||||
return;
|
||||
}
|
||||
int start = Math.max(0, inputField.getSelectionStart());
|
||||
int end = Math.max(0, inputField.getSelectionEnd());
|
||||
int from = Math.min(start, end);
|
||||
int to = Math.max(start, end);
|
||||
CharSequence current = inputField.getText();
|
||||
String prefix = from > 0 && !Character.isWhitespace(current.charAt(from - 1)) ? " " : "";
|
||||
String suffix = to < current.length() && Character.isWhitespace(current.charAt(to)) ? "" : " ";
|
||||
inputField.getText().replace(from, to, prefix + path + suffix);
|
||||
inputField.requestFocus();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (activeSessionName != null) {
|
||||
|
||||
@@ -14,6 +14,7 @@ import java.util.List;
|
||||
final class TerminalScreenBuffer {
|
||||
private static final int DEFAULT_FG = 0xffe6ebf2;
|
||||
private static final int DEFAULT_BG = Color.TRANSPARENT;
|
||||
private static final int TERMINAL_BG = 0xff0b0e13;
|
||||
|
||||
private int cols;
|
||||
private int rows;
|
||||
@@ -27,6 +28,7 @@ final class TerminalScreenBuffer {
|
||||
private int fg = DEFAULT_FG;
|
||||
private int bg = DEFAULT_BG;
|
||||
private boolean bold;
|
||||
private boolean dim;
|
||||
|
||||
TerminalScreenBuffer(int cols, int rows) {
|
||||
resize(cols, rows);
|
||||
@@ -74,6 +76,7 @@ final class TerminalScreenBuffer {
|
||||
fg = DEFAULT_FG;
|
||||
bg = DEFAULT_BG;
|
||||
bold = false;
|
||||
dim = false;
|
||||
}
|
||||
|
||||
void write(String text) {
|
||||
@@ -257,10 +260,14 @@ final class TerminalScreenBuffer {
|
||||
fg = DEFAULT_FG;
|
||||
bg = DEFAULT_BG;
|
||||
bold = false;
|
||||
dim = false;
|
||||
} else if (value == 1) {
|
||||
bold = true;
|
||||
} else if (value == 2) {
|
||||
dim = true;
|
||||
} else if (value == 22) {
|
||||
bold = false;
|
||||
dim = false;
|
||||
} else if (value == 39) {
|
||||
fg = DEFAULT_FG;
|
||||
} else if (value == 49) {
|
||||
@@ -302,7 +309,7 @@ final class TerminalScreenBuffer {
|
||||
wrapPending = false;
|
||||
newLine();
|
||||
}
|
||||
cells[cursorRow][cursorCol].set(value, fg, bg, bold);
|
||||
cells[cursorRow][cursorCol].set(value, fg, bg, bold, dim);
|
||||
if (cursorCol == cols - 1) {
|
||||
wrapPending = true;
|
||||
} else {
|
||||
@@ -453,15 +460,19 @@ final class TerminalScreenBuffer {
|
||||
int fgColor = first.fg;
|
||||
int bgColor = first.bg;
|
||||
boolean isBold = first.bold;
|
||||
boolean isDim = first.dim;
|
||||
while (col < cols) {
|
||||
Cell cell = cells[row][col];
|
||||
if (cell.fg != fgColor || cell.bg != bgColor || cell.bold != isBold) {
|
||||
if (cell.fg != fgColor || cell.bg != bgColor || cell.bold != isBold || cell.dim != isDim) {
|
||||
break;
|
||||
}
|
||||
output.append(cell.value);
|
||||
col++;
|
||||
}
|
||||
int end = output.length();
|
||||
if (isDim) {
|
||||
fgColor = blendColor(fgColor, bgColor == DEFAULT_BG ? TERMINAL_BG : bgColor, 0.55f);
|
||||
}
|
||||
output.setSpan(new ForegroundColorSpan(fgColor), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
if (bgColor != DEFAULT_BG) {
|
||||
output.setSpan(new BackgroundColorSpan(bgColor), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
@@ -613,6 +624,15 @@ final class TerminalScreenBuffer {
|
||||
return value == 0 ? 0 : 55 + value * 40;
|
||||
}
|
||||
|
||||
private static int blendColor(int foreground, int background, float foregroundRatio) {
|
||||
float backgroundRatio = 1f - foregroundRatio;
|
||||
return Color.rgb(
|
||||
Math.round(Color.red(foreground) * foregroundRatio + Color.red(background) * backgroundRatio),
|
||||
Math.round(Color.green(foreground) * foregroundRatio + Color.green(background) * backgroundRatio),
|
||||
Math.round(Color.blue(foreground) * foregroundRatio + Color.blue(background) * backgroundRatio)
|
||||
);
|
||||
}
|
||||
|
||||
private static int clamp(int value, int min, int max) {
|
||||
return Math.max(min, Math.min(max, value));
|
||||
}
|
||||
@@ -622,19 +642,22 @@ final class TerminalScreenBuffer {
|
||||
int fg = DEFAULT_FG;
|
||||
int bg = DEFAULT_BG;
|
||||
boolean bold;
|
||||
boolean dim;
|
||||
|
||||
void clear() {
|
||||
value = ' ';
|
||||
fg = DEFAULT_FG;
|
||||
bg = DEFAULT_BG;
|
||||
bold = false;
|
||||
dim = false;
|
||||
}
|
||||
|
||||
void set(char nextValue, int nextFg, int nextBg, boolean nextBold) {
|
||||
void set(char nextValue, int nextFg, int nextBg, boolean nextBold, boolean nextDim) {
|
||||
value = nextValue;
|
||||
fg = nextFg;
|
||||
bg = nextBg;
|
||||
bold = nextBold;
|
||||
dim = nextDim;
|
||||
}
|
||||
|
||||
void copyFrom(Cell other) {
|
||||
@@ -642,6 +665,7 @@ final class TerminalScreenBuffer {
|
||||
fg = other.fg;
|
||||
bg = other.bg;
|
||||
bold = other.bold;
|
||||
dim = other.dim;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user