Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class SettingsRepository(context: Context) {
private val _accessoryBarSingleRow = MutableStateFlow(prefs.getBoolean(KEY_ACCESSORY_BAR_SINGLE_ROW, false))
val accessoryBarSingleRow: StateFlow<Boolean> = _accessoryBarSingleRow.asStateFlow()

private val _termuxStyleAccessoryBar = MutableStateFlow(prefs.getBoolean(KEY_TERMUX_STYLE_ACCESSORY_BAR, false))
val termuxStyleAccessoryBar: StateFlow<Boolean> = _termuxStyleAccessoryBar.asStateFlow()

private val _appLockEnabled = MutableStateFlow(prefs.getBoolean(KEY_APP_LOCK_ENABLED, false))
val appLockEnabled: StateFlow<Boolean> = _appLockEnabled.asStateFlow()

Expand Down Expand Up @@ -93,6 +96,11 @@ class SettingsRepository(context: Context) {
_accessoryBarSingleRow.value = enabled
}

fun setTermuxStyleAccessoryBar(enabled: Boolean) {
prefs.edit().putBoolean(KEY_TERMUX_STYLE_ACCESSORY_BAR, enabled).apply()
_termuxStyleAccessoryBar.value = enabled
}

fun setTerminalTabMode(mode: TerminalTabMode) {
prefs.edit().putString(KEY_TAB_MODE, mode.name).apply()
_terminalTabMode.value = mode
Expand Down Expand Up @@ -144,13 +152,38 @@ class SettingsRepository(context: Context) {

private fun loadAccessoryLayoutIds(): List<String> {
val stored = prefs.getString(KEY_ACCESSORY_LAYOUT, null)
?: return TerminalAccessoryLayoutStore.defaultLayoutIds()
if (stored == null) {
markScreenActionsBackfilled()
return TerminalAccessoryLayoutStore.defaultLayoutIds()
}
if (stored.isBlank()) {
markScreenActionsBackfilled()
return emptyList()
}
return TerminalAccessoryLayoutStore.normalizeIds(
val ids = TerminalAccessoryLayoutStore.normalizeIds(
stored.split(',').map(String::trim).filter(String::isNotEmpty),
)
return backfillScreenActions(ids)
}

/**
* Runs the screen-action backfill once, then records that it happened so a user who later
* removes those keys on purpose does not get them back on the next launch.
*/
private fun backfillScreenActions(ids: List<String>): List<String> {
if (prefs.getBoolean(KEY_ACCESSORY_SCREEN_ACTIONS_BACKFILLED, false)) {
return ids
}
val migrated = TerminalAccessoryLayoutStore.backfillScreenActions(ids)
prefs.edit()
.putString(KEY_ACCESSORY_LAYOUT, migrated.joinToString(separator = ","))
.putBoolean(KEY_ACCESSORY_SCREEN_ACTIONS_BACKFILLED, true)
.apply()
return migrated
}

private fun markScreenActionsBackfilled() {
prefs.edit().putBoolean(KEY_ACCESSORY_SCREEN_ACTIONS_BACKFILLED, true).apply()
}

private fun loadTerminalCustomKeyGroups(): List<TerminalCustomKeyGroup> {
Expand All @@ -164,6 +197,9 @@ class SettingsRepository(context: Context) {
private const val KEY_ACCESSORY_LAYOUT = "terminal_accessory_layout"
private const val KEY_TERMINAL_CUSTOM_ACTIONS = "terminal_custom_actions"
private const val KEY_ACCESSORY_BAR_SINGLE_ROW = "terminal_accessory_bar_single_row"
private const val KEY_TERMUX_STYLE_ACCESSORY_BAR = "terminal_termux_style_accessory_bar"
private const val KEY_ACCESSORY_SCREEN_ACTIONS_BACKFILLED =
"terminal_accessory_screen_actions_backfilled"
private const val KEY_TAB_MODE = "terminal_tab_mode"
private const val KEY_APP_LOCK_ENABLED = "app_lock_enabled"
private const val KEY_REQUIRE_AUTH_ON_CONNECT = "require_auth_on_connect"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ fun ApplicationNavController() {
val requireAuthOnConnect by settingsRepo.requireAuthOnConnect.collectAsStateWithLifecycle()
val accessoryLayoutIds by settingsRepo.accessoryLayoutIds.collectAsStateWithLifecycle()
val accessoryBarSingleRow by settingsRepo.accessoryBarSingleRow.collectAsStateWithLifecycle()
val termuxStyleAccessoryBar by settingsRepo.termuxStyleAccessoryBar.collectAsStateWithLifecycle()
val customKeyGroups by settingsRepo.terminalCustomKeyGroups.collectAsStateWithLifecycle()
val tabMode by settingsRepo.terminalTabMode.collectAsStateWithLifecycle()
val localShellEnabled by settingsRepo.localShellEnabled.collectAsStateWithLifecycle()
Expand All @@ -136,6 +137,7 @@ fun ApplicationNavController() {
localShellEnabled = localShellEnabled,
currentAccessoryLayoutIds = accessoryLayoutIds,
accessoryBarSingleRow = accessoryBarSingleRow,
termuxStyleAccessoryBar = termuxStyleAccessoryBar,
currentTerminalCustomKeyGroups = customKeyGroups,
currentTabMode = tabMode,
onTabModeChanged = settingsRepo::setTerminalTabMode,
Expand All @@ -150,6 +152,7 @@ fun ApplicationNavController() {
onLocalShellEnabledChanged = settingsRepo::setLocalShellEnabled,
onAccessoryLayoutChanged = settingsRepo::setAccessoryLayoutIds,
onAccessoryBarSingleRowChanged = settingsRepo::setAccessoryBarSingleRow,
onTermuxStyleAccessoryBarChanged = settingsRepo::setTermuxStyleAccessoryBar,
currentTerminalFontSize = terminalFontSize,
onTerminalFontSizeChanged = settingsRepo::setTerminalFontSize,
onTerminalCustomActionsChanged = settingsRepo::setTerminalCustomKeyGroups,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ fun SettingsScreen(
localShellEnabled: Boolean,
currentAccessoryLayoutIds: List<String>,
accessoryBarSingleRow: Boolean,
termuxStyleAccessoryBar: Boolean,
currentTerminalCustomKeyGroups: List<TerminalCustomKeyGroup>,
currentTabMode: TerminalTabMode = TerminalTabMode.Classic,
onTabModeChanged: (TerminalTabMode) -> Unit = {},
Expand All @@ -62,6 +63,7 @@ fun SettingsScreen(
onLocalShellEnabledChanged: (Boolean) -> Unit,
onAccessoryLayoutChanged: (List<String>) -> Unit,
onAccessoryBarSingleRowChanged: (Boolean) -> Unit,
onTermuxStyleAccessoryBarChanged: (Boolean) -> Unit,
currentTerminalFontSize: Float = 14f,
onTerminalFontSizeChanged: (Float) -> Unit = {},
onTerminalCustomActionsChanged: (List<TerminalCustomKeyGroup>) -> Unit,
Expand Down Expand Up @@ -169,6 +171,8 @@ fun SettingsScreen(
onEditAccessoryLayout = { showAccessoryEditor = true },
accessoryBarSingleRow = accessoryBarSingleRow,
onAccessoryBarSingleRowChanged = onAccessoryBarSingleRowChanged,
termuxStyleAccessoryBar = termuxStyleAccessoryBar,
onTermuxStyleAccessoryBarChanged = onTermuxStyleAccessoryBarChanged,
currentTerminalFontSize = currentTerminalFontSize,
onTerminalFontSizeChanged = onTerminalFontSizeChanged,
currentTerminalCustomKeyGroups = currentTerminalCustomKeyGroups,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ internal fun TerminalSettings(
onEditAccessoryLayout: () -> Unit,
accessoryBarSingleRow: Boolean,
onAccessoryBarSingleRowChanged: (Boolean) -> Unit,
termuxStyleAccessoryBar: Boolean,
onTermuxStyleAccessoryBarChanged: (Boolean) -> Unit,
currentTerminalFontSize: Float = 14f,
onTerminalFontSizeChanged: (Float) -> Unit = {},
currentTerminalCustomKeyGroups: List<TerminalCustomKeyGroup>,
Expand Down Expand Up @@ -331,6 +333,28 @@ internal fun TerminalSettings(
)
}

Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
) {
Column(
modifier = Modifier.weight(1f),
verticalArrangement = Arrangement.spacedBy(2.dp),
) {
ChuText("termux-style accessory bar", style = typography.label)
ChuText(
"equal-width keys, no borders, tighter spacing",
style = typography.bodySmall,
color = colors.textMuted,
)
}
ChuSwitch(
checked = termuxStyleAccessoryBar,
onCheckedChange = onTermuxStyleAccessoryBarChanged,
)
}

if (selectedEntries.isEmpty()) {
ChuText(
"choose the accessory keys you want in the terminal bar.",
Expand All @@ -348,6 +372,7 @@ internal fun TerminalSettings(
modifierState = ModifierState(),
onAction = {},
useSingleRow = accessoryBarSingleRow,
termuxStyle = termuxStyleAccessoryBar,
modifier = Modifier.fillMaxWidth(),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,9 @@ fun CommandPalette(
accessoryEntries: List<ResolvedAccessoryEntry>,
accessoryModifierState: ModifierState,
onAccessoryAction: (AccessoryAction) -> Unit,
onChuchuKey: () -> Unit,
chuchuKeyActive: Boolean,
onOpenFiles: () -> Unit,
onOpenSettings: () -> Unit,
useSingleRowAccessoryBar: Boolean,
termuxStyleAccessoryBar: Boolean = false,
onSelectTab: (String) -> Unit,
onCloseTab: (String) -> Unit,
onAddTab: () -> Unit,
Expand Down Expand Up @@ -254,11 +252,9 @@ fun CommandPalette(
entries = accessoryEntries,
modifierState = accessoryModifierState,
onAction = onAccessoryAction,
onSettings = onOpenSettings,
onChuchuKey = onChuchuKey,
chuchuKeyActive = chuchuKeyActive,
onOpenFiles = onOpenFiles,
useSingleRow = useSingleRowAccessoryBar,
termuxStyle = termuxStyleAccessoryBar,
modifier =
Modifier.align(Alignment.BottomCenter)
.windowInsetsPadding(WindowInsets.safeDrawing)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ fun TerminalScreen(
val tabMode by settingsRepo.terminalTabMode.collectAsStateWithLifecycle()
val currentAccessoryLayoutIds by settingsRepo.accessoryLayoutIds.collectAsStateWithLifecycle()
val useSingleRowAccessoryBar by settingsRepo.accessoryBarSingleRow.collectAsStateWithLifecycle()
val useTermuxStyleAccessoryBar by settingsRepo.termuxStyleAccessoryBar.collectAsStateWithLifecycle()
val currentTerminalCustomKeyGroups by
settingsRepo.terminalCustomKeyGroups.collectAsStateWithLifecycle()
val settingsFontSize by settingsRepo.terminalFontSize.collectAsStateWithLifecycle()
Expand Down Expand Up @@ -826,6 +827,26 @@ fun TerminalScreen(


fun dispatchAccessoryAction(action: AccessoryAction) {
when (action) {
AccessoryAction.Settings -> {
onOpenSettings()
return
}
AccessoryAction.ChuchuKey -> {
chuchuKeys.togglePrefix()
requestInputFocus()
return
}
AccessoryAction.OpenFiles -> {
if (filesSupported) {
vm.selectConnectionTab(ConnectionTab.Files)
} else {
showLocalShellFilesUnsupported()
}
return
}
else -> Unit
}
if (
action is AccessoryAction.SendText && chuchuKeys.handleText(action.text)
) {
Expand Down Expand Up @@ -1502,7 +1523,10 @@ fun TerminalScreen(
}
}

Spacer(modifier = Modifier.height(6.dp))
// The termux-style bar sits flush against the terminal, so it drops the gap.
if (!(selectedTab == ConnectionTab.Terminal && useTermuxStyleAccessoryBar)) {
Spacer(modifier = Modifier.height(6.dp))
}
if (selectedTab == ConnectionTab.Terminal) {
if (activeHostCount > 1 && currentHostName != null) {
Row(
Expand Down Expand Up @@ -1560,21 +1584,14 @@ fun TerminalScreen(
entries = accessoryLayout,
modifierState = modifierState,
onAction = ::dispatchAccessoryAction,
onSettings = onOpenSettings,
onChuchuKey = {
chuchuKeys.togglePrefix()
requestInputFocus()
},
chuchuKeyActive = chuchuKeys.isPrefixActive,
onOpenFiles = {
if (filesSupported) {
vm.selectConnectionTab(ConnectionTab.Files)
} else {
showLocalShellFilesUnsupported()
}
},
useSingleRow = useSingleRowAccessoryBar,
modifier = Modifier.padding(bottom = 2.dp),
termuxStyle = useTermuxStyleAccessoryBar,
modifier = if (useTermuxStyleAccessoryBar) {
Modifier
} else {
Modifier.padding(bottom = 2.dp)
},
)
}
}
Expand All @@ -1585,7 +1602,27 @@ fun TerminalScreen(
UploadProgressDialog(progress = uploadProgress)
}
if (showTabSheet) {
val paletteAccessoryAction: (AccessoryAction) -> Unit = { action ->
val paletteAccessoryAction: (AccessoryAction) -> Unit = fun(action: AccessoryAction) {
when (action) {
AccessoryAction.Settings -> {
onOpenSettings()
return
}
AccessoryAction.ChuchuKey -> {
chuchuKeys.togglePrefix()
return
}
AccessoryAction.OpenFiles -> {
if (filesSupported) {
vm.selectConnectionTab(ConnectionTab.Files)
showTabSheet = false
} else {
showLocalShellFilesUnsupported()
}
return
}
else -> Unit
}
if (
!(action is AccessoryAction.SendText &&
chuchuKeys.handleText(action.text))
Expand Down Expand Up @@ -1655,18 +1692,9 @@ fun TerminalScreen(
accessoryEntries = accessoryLayout,
accessoryModifierState = modifierState,
onAccessoryAction = paletteAccessoryAction,
onChuchuKey = { chuchuKeys.togglePrefix() },
chuchuKeyActive = chuchuKeys.isPrefixActive,
onOpenFiles = {
if (filesSupported) {
vm.selectConnectionTab(ConnectionTab.Files)
showTabSheet = false
} else {
showLocalShellFilesUnsupported()
}
},
onOpenSettings = onOpenSettings,
useSingleRowAccessoryBar = useSingleRowAccessoryBar,
termuxStyleAccessoryBar = useTermuxStyleAccessoryBar,
onSelectTab = {
vm.selectTab(it)
showTabSheet = false
Expand Down
Loading