generated from ali/HarmonyTemplate
提交 Haven Android 仓库源码 v5.87.79
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
plugins {
|
||||
alias(libs.plugins.android.library)
|
||||
alias(libs.plugins.kotlin.compose)
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "sh.haven.core.terminal"
|
||||
compileSdk = 37
|
||||
|
||||
defaultConfig {
|
||||
minSdk = 26
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
buildFeatures {
|
||||
compose = true
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(libs.termlib)
|
||||
|
||||
implementation(platform(libs.compose.bom))
|
||||
implementation(libs.compose.ui)
|
||||
implementation(libs.compose.ui.tooling.preview)
|
||||
|
||||
implementation(libs.core.ktx)
|
||||
implementation(libs.coroutines.android)
|
||||
}
|
||||
|
||||
kotlin {
|
||||
compilerOptions {
|
||||
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17)
|
||||
}
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
package sh.haven.core.terminal
|
||||
|
||||
/**
|
||||
* How Haven wants the soft keyboard to behave inside the terminal. Folded
|
||||
* into one sealed type so call sites pass a single value instead of a pair
|
||||
* of booleans — and so future modes (e.g. "accessibility") have a single
|
||||
* place to land.
|
||||
*
|
||||
* Translates to termlib's existing `allowStandardKeyboard` and
|
||||
* `rawKeyboardMode` flags on the public [org.connectbot.terminal.Terminal]
|
||||
* composable. Mapping lives in [HavenTerminal]; callers never touch the
|
||||
* termlib booleans directly.
|
||||
*/
|
||||
sealed interface HavenKeyboardMode {
|
||||
/**
|
||||
* Default. `TYPE_NULL`-class input with `NO_SUGGESTIONS` and
|
||||
* `NO_PERSONALIZED_LEARNING` — Gboard's mic, suggestion strip, and
|
||||
* on-device writing assist all stay off. CJK composition still works
|
||||
* because the terminal hosts its own composition flow on top.
|
||||
*/
|
||||
data object Secure : HavenKeyboardMode
|
||||
|
||||
/**
|
||||
* Standard Android soft keyboard. Voice input, swipe typing, and
|
||||
* autocomplete are all enabled. Useful when the user is typing long
|
||||
* free-form prose into a shell editor and wants full IME features.
|
||||
*/
|
||||
data object Standard : HavenKeyboardMode
|
||||
|
||||
/**
|
||||
* No `InputConnection` at all — the IME has nothing to attach to and
|
||||
* Gboard's decorations disappear entirely. Physical keyboards still
|
||||
* work via `View.dispatchKeyEvent`. Soft-keyboard input comes through
|
||||
* as raw key events only, which means no IME composition, so this is
|
||||
* for users who want the hardest possible IME lock-out and don't need
|
||||
* CJK. Equivalent to ConnectBot's old `TYPE_NULL` behaviour.
|
||||
*/
|
||||
data object Raw : HavenKeyboardMode
|
||||
|
||||
/**
|
||||
* User-configured EditorInfo flag set. Same plumbing as Secure but
|
||||
* with each underlying bit individually toggleable so power users
|
||||
* can tune around IME-specific quirks (#115 follow-up): get voice
|
||||
* input on Gboard while keeping autocorrect off, or unblock
|
||||
* Samsung's commit-text gate without enabling autocap, etc.
|
||||
*/
|
||||
data class Custom(val flags: ImeFlagSet) : HavenKeyboardMode
|
||||
}
|
||||
|
||||
/**
|
||||
* Individual IME flag toggles for [HavenKeyboardMode.Custom]. Each
|
||||
* boolean maps to one EditorInfo bit; [ImeInputView] reads this struct
|
||||
* and assembles `inputType` / `imeOptions` from it directly when the
|
||||
* mode is Custom.
|
||||
*
|
||||
* Defaults match what the Secure preset would have set, so flipping
|
||||
* into Custom mode without further tweaks preserves behaviour.
|
||||
*/
|
||||
data class ImeFlagSet(
|
||||
/** `TYPE_TEXT_FLAG_NO_SUGGESTIONS` — hide the suggestion strip. */
|
||||
val noSuggestions: Boolean = true,
|
||||
/**
|
||||
* `TYPE_TEXT_VARIATION_VISIBLE_PASSWORD` — strongest "don't rewrite
|
||||
* my input" hint. Universally honoured by Gboard; keeps autocap,
|
||||
* autospace, and word-substitution autocorrect off. Mutually
|
||||
* exclusive with composition (CJK / voice / swipe) on most IMEs.
|
||||
*/
|
||||
val visiblePassword: Boolean = true,
|
||||
/**
|
||||
* `TYPE_TEXT_FLAG_AUTO_CORRECT` — required by Samsung Honeyboard's
|
||||
* IMM gate to dispatch input at all (#110), but explicitly enables
|
||||
* autocorrect-on-space on Gboard. Off by default.
|
||||
*/
|
||||
val autoCorrect: Boolean = false,
|
||||
/**
|
||||
* Give `BaseInputConnection` a real Editable so the IME can do
|
||||
* composition (voice input, swipe typing). Implies
|
||||
* non-`VISIBLE_PASSWORD` input type — the user picks one or the
|
||||
* other.
|
||||
*/
|
||||
val fullEditor: Boolean = false,
|
||||
/** `IME_FLAG_NO_EXTRACT_UI` — suppress fullscreen IME in landscape. */
|
||||
val noExtractUi: Boolean = true,
|
||||
/** `IME_FLAG_NO_PERSONALIZED_LEARNING` — privacy: IME doesn't learn input. */
|
||||
val noPersonalizedLearning: Boolean = true,
|
||||
)
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
package sh.haven.core.terminal
|
||||
|
||||
import android.graphics.Typeface
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.unit.TextUnit
|
||||
import androidx.compose.ui.unit.sp
|
||||
import org.connectbot.terminal.ComposeController
|
||||
import org.connectbot.terminal.ModifierManager
|
||||
import org.connectbot.terminal.SelectionController
|
||||
import org.connectbot.terminal.Terminal
|
||||
import org.connectbot.terminal.TerminalEmulator
|
||||
import org.connectbot.terminal.TerminalGestureCallback
|
||||
|
||||
/**
|
||||
* Haven-owned wrapper around termlib's [Terminal] composable.
|
||||
*
|
||||
* The long-term goal is to keep termlib's surface upstream-shaped and land
|
||||
* Haven's opinionated UX (keyboard modes, future IME composer overlay
|
||||
* placement, toolbar wiring) here instead. Today the wrapper adapts Haven's
|
||||
* [HavenKeyboardMode] enum onto termlib's pair of booleans; the floating
|
||||
* IME composer overlay still lives inside termlib's Canvas draw block
|
||||
* because it needs internal cursor/char metrics. Once upstream exposes
|
||||
* those (PR-G in the realignment plan) the overlay moves here too and
|
||||
* termlib's fork patch drops.
|
||||
*/
|
||||
@Composable
|
||||
fun HavenTerminal(
|
||||
terminalEmulator: TerminalEmulator,
|
||||
modifier: Modifier = Modifier,
|
||||
typeface: Typeface = Typeface.MONOSPACE,
|
||||
initialFontSize: TextUnit = 11.sp,
|
||||
minFontSize: TextUnit = 6.sp,
|
||||
maxFontSize: TextUnit = 30.sp,
|
||||
backgroundColor: Color = Color.Black,
|
||||
foregroundColor: Color = Color.White,
|
||||
/** Alpha for the terminal's screen-fill background (0.0–1.0). Below 1 the
|
||||
* empty areas reveal whatever sits behind the Canvas. Default 1 = opaque. */
|
||||
backgroundOpacity: Float = 1f,
|
||||
keyboardEnabled: Boolean = false,
|
||||
showSoftKeyboard: Boolean = true,
|
||||
imeRestoreTick: Int = 0,
|
||||
focusRequester: FocusRequester = remember { FocusRequester() },
|
||||
onTerminalTap: () -> Unit = {},
|
||||
onTerminalDoubleTap: () -> Unit = {},
|
||||
onImeVisibilityChanged: (Boolean) -> Unit = {},
|
||||
forcedSize: Pair<Int, Int>? = null,
|
||||
modifierManager: ModifierManager? = null,
|
||||
onSelectionControllerAvailable: ((SelectionController) -> Unit)? = null,
|
||||
onHyperlinkClick: (String) -> Unit = {},
|
||||
onComposeControllerAvailable: ((ComposeController) -> Unit)? = null,
|
||||
onFontSizeChanged: ((TextUnit) -> Unit)? = null,
|
||||
gestureCallback: TerminalGestureCallback? = null,
|
||||
/** See Terminal's scrollQuantumMultiplier — >1 = coarser swipe-to-key steps (#524). */
|
||||
scrollQuantumMultiplier: Float = 1f,
|
||||
onPasteShortcut: (() -> Unit)? = null,
|
||||
onPasteRequest: (() -> Unit)? = null,
|
||||
keyboardMode: HavenKeyboardMode = HavenKeyboardMode.Secure,
|
||||
tapToPositionCursorOnPrompt: Boolean = false,
|
||||
onScrollControllerAvailable: ((org.connectbot.terminal.ScrollController) -> Unit)? = null,
|
||||
onGestureInjectorReady: ((org.connectbot.terminal.GestureInjector) -> Unit)? = null,
|
||||
reflowOnKeyboard: Boolean = false,
|
||||
/** True while the remote app has mouse tracking on — see Terminal. (#435) */
|
||||
mouseModeActive: Boolean = false,
|
||||
) {
|
||||
Terminal(
|
||||
terminalEmulator = terminalEmulator,
|
||||
modifier = modifier,
|
||||
typeface = typeface,
|
||||
initialFontSize = initialFontSize,
|
||||
minFontSize = minFontSize,
|
||||
maxFontSize = maxFontSize,
|
||||
backgroundColor = backgroundColor,
|
||||
foregroundColor = foregroundColor,
|
||||
backgroundOpacity = backgroundOpacity,
|
||||
keyboardEnabled = keyboardEnabled,
|
||||
showSoftKeyboard = showSoftKeyboard,
|
||||
imeRestoreTick = imeRestoreTick,
|
||||
focusRequester = focusRequester,
|
||||
onTerminalTap = onTerminalTap,
|
||||
onTerminalDoubleTap = onTerminalDoubleTap,
|
||||
onImeVisibilityChanged = onImeVisibilityChanged,
|
||||
forcedSize = forcedSize,
|
||||
modifierManager = modifierManager,
|
||||
onSelectionControllerAvailable = onSelectionControllerAvailable,
|
||||
onHyperlinkClick = onHyperlinkClick,
|
||||
onComposeControllerAvailable = onComposeControllerAvailable,
|
||||
onFontSizeChanged = onFontSizeChanged,
|
||||
gestureCallback = gestureCallback,
|
||||
scrollQuantumMultiplier = scrollQuantumMultiplier,
|
||||
mouseModeActive = mouseModeActive,
|
||||
allowStandardKeyboard = keyboardMode is HavenKeyboardMode.Standard,
|
||||
rawKeyboardMode = keyboardMode is HavenKeyboardMode.Raw,
|
||||
customImeFlags = (keyboardMode as? HavenKeyboardMode.Custom)?.let {
|
||||
org.connectbot.terminal.ImeFlagBundle(
|
||||
noSuggestions = it.flags.noSuggestions,
|
||||
visiblePassword = it.flags.visiblePassword,
|
||||
autoCorrect = it.flags.autoCorrect,
|
||||
fullEditor = it.flags.fullEditor,
|
||||
noExtractUi = it.flags.noExtractUi,
|
||||
noPersonalizedLearning = it.flags.noPersonalizedLearning,
|
||||
)
|
||||
},
|
||||
onPasteShortcut = onPasteShortcut,
|
||||
onPasteRequest = onPasteRequest,
|
||||
tapToPositionCursorOnPrompt = tapToPositionCursorOnPrompt,
|
||||
onScrollControllerAvailable = onScrollControllerAvailable,
|
||||
onGestureInjectorReady = onGestureInjectorReady,
|
||||
reflowOnKeyboard = reflowOnKeyboard,
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user