diff --git a/NeoLang/src/main/java/io/neolang/visitor/ConfigVisitor.kt b/NeoLang/src/main/java/io/neolang/visitor/ConfigVisitor.kt index 045acbd..eec1c77 100644 --- a/NeoLang/src/main/java/io/neolang/visitor/ConfigVisitor.kt +++ b/NeoLang/src/main/java/io/neolang/visitor/ConfigVisitor.kt @@ -30,6 +30,16 @@ class ConfigVisitor : IVisitorCallback { return NeoLangArray.createFromContext(getContext(contextPath).getChild(arrayName)) } + fun getStringValue(path: Array, name: String): String? { + val value = this.getAttribute(path, name) + return if (value.isValid()) value.asString() else null + } + + fun getBooleanValue(path: Array, name: String): Boolean? { + val value = this.getAttribute(path, name) + return if (value.isValid()) value.asString() == "true" else null + } + override fun onStart() { currentContext = NeoLangContext("global") rootContext = currentContext @@ -60,9 +70,4 @@ class ConfigVisitor : IVisitorCallback { override fun getCurrentContext(): NeoLangContext { return currentContext!! } - - fun getStringValue(path: Array, name: String): String? { - val value = this.getAttribute(path, name) - return if (value.isValid()) value.asString() else null - } } \ No newline at end of file diff --git a/app/src/main/java/io/neoterm/frontend/session/shell/ShellProfile.kt b/app/src/main/java/io/neoterm/frontend/session/shell/ShellProfile.kt index 23fa0a0..3282a27 100644 --- a/app/src/main/java/io/neoterm/frontend/session/shell/ShellProfile.kt +++ b/app/src/main/java/io/neoterm/frontend/session/shell/ShellProfile.kt @@ -15,7 +15,7 @@ class ShellProfile : NeoProfile() { companion object { const val PROFILE_META_NAME = "profile-shell" - private const val LOGIN_SHELL_NAME = "login-shell" + private const val LOGIN_SHELL = "login-shell" private const val INITIAL_COMMAND = "init-command" private const val BELL = "bell" private const val VIBRATE = "vibrate" @@ -26,6 +26,8 @@ class ShellProfile : NeoProfile() { private const val EXTRA_KEYS = "extra-keys" private const val FONT = "font" private const val COLOR_SCHEME = "color-scheme" + + private val PROFILE_META_PATH = arrayOf(PROFILE_META_NAME) } override val profileMetaName = PROFILE_META_NAME @@ -38,34 +40,58 @@ class ShellProfile : NeoProfile() { var enableExecveWrapper = DefaultValues.enableExecveWrapper var enableSpecialVolumeKeys = DefaultValues.enableSpecialVolumeKeys var enableAutoCompletion = DefaultValues.enableAutoCompletion - var enableBackButtonBeMappedToEscape = DefaultValues.enableBackButtonBeMappedToEscape + var enableBackKeyToEscape = DefaultValues.enableBackButtonBeMappedToEscape var enableExtraKeys = DefaultValues.enableExtraKeys var profileFont: String var profileColorScheme: String init { -// val fontComp = ComponentManager.getComponent() -// val colorComp = ComponentManager.getComponent() -// -// profileFont = fontComp.getCurrentFontName() -// profileColorScheme = colorComp.getCurrentColorSchemeName() + val fontComp = ComponentManager.getComponent() + val colorComp = ComponentManager.getComponent() - profileFont = "" - profileColorScheme = "" + profileFont = fontComp.getCurrentFontName() + profileColorScheme = colorComp.getCurrentColorSchemeName() -// loginShell = NeoPreference.getLoginShellPath() -// initialCommand = NeoPreference.getInitialCommand() -// enableBell = NeoPreference.isBellEnabled() -// enableVibrate = NeoPreference.isVibrateEnabled() -// enableExecveWrapper = NeoPreference.isExecveWrapperEnabled() -// enableSpecialVolumeKeys = NeoPreference.isSpecialVolumeKeysEnabled() -// enableAutoCompletion = NeoPreference.isAutoCompletionEnabled() -// enableBackButtonBeMappedToEscape = NeoPreference.isBackButtonBeMappedToEscapeEnabled() -// enableExtraKeys = NeoPreference.isExtraKeysEnabled() + loginShell = NeoPreference.getLoginShellPath() + initialCommand = NeoPreference.getInitialCommand() + enableBell = NeoPreference.isBellEnabled() + enableVibrate = NeoPreference.isVibrateEnabled() + enableExecveWrapper = NeoPreference.isExecveWrapperEnabled() + enableSpecialVolumeKeys = NeoPreference.isSpecialVolumeKeysEnabled() + enableAutoCompletion = NeoPreference.isAutoCompletionEnabled() + enableBackKeyToEscape = NeoPreference.isBackButtonBeMappedToEscapeEnabled() + enableExtraKeys = NeoPreference.isExtraKeysEnabled() } - override fun onProfileLoaded(visitor: ConfigVisitor): Boolean { + override fun onProfileLoaded(V: ConfigVisitor): Boolean { + loginShell = V.getProfileString(LOGIN_SHELL, loginShell) + initialCommand = V.getProfileString(INITIAL_COMMAND, initialCommand) + enableBell = V.getProfileBoolean(BELL, enableBell) + enableVibrate = V.getProfileBoolean(VIBRATE, enableVibrate) + enableExecveWrapper = V.getProfileBoolean(EXECVE_WRAPPER, enableExecveWrapper) + enableSpecialVolumeKeys = V.getProfileBoolean(SPECIAL_VOLUME_KEYS, enableSpecialVolumeKeys) + enableAutoCompletion = V.getProfileBoolean(AUTO_COMPLETION, enableAutoCompletion) + enableBackKeyToEscape = V.getProfileBoolean(BACK_KEY_TO_ESC, enableBackKeyToEscape) + enableExtraKeys = V.getProfileBoolean(EXTRA_KEYS, enableExtraKeys) + profileFont = V.getProfileString(FONT, profileFont) + profileColorScheme = V.getProfileString(COLOR_SCHEME, profileColorScheme) return true } + + private fun ConfigVisitor.getProfileString(key: String, fallback: String): String { + return getProfileString(key) ?: fallback + } + + private fun ConfigVisitor.getProfileBoolean(key: String, fallback: Boolean): Boolean { + return getProfileBoolean(key) ?: fallback + } + + private fun ConfigVisitor.getProfileString(key: String): String? { + return this.getStringValue(PROFILE_META_PATH, key) + } + + private fun ConfigVisitor.getProfileBoolean(key: String): Boolean? { + return this.getBooleanValue(PROFILE_META_PATH, key) + } } \ No newline at end of file diff --git a/app/src/main/java/io/neoterm/frontend/session/shell/client/TermViewClient.kt b/app/src/main/java/io/neoterm/frontend/session/shell/client/TermViewClient.kt index 30024cc..0136318 100644 --- a/app/src/main/java/io/neoterm/frontend/session/shell/client/TermViewClient.kt +++ b/app/src/main/java/io/neoterm/frontend/session/shell/client/TermViewClient.kt @@ -43,7 +43,7 @@ class TermViewClient(val context: Context) : TerminalViewClient { override fun shouldBackButtonBeMappedToEscape(): Boolean { val shellSession = termData?.termSession as ShellTermSession? ?: return false - return shellSession.shellProfile.enableBackButtonBeMappedToEscape + return shellSession.shellProfile.enableBackKeyToEscape } override fun copyModeChanged(copyMode: Boolean) { diff --git a/app/src/test/java/io/neoterm/ConfigureFileTest.kt b/app/src/test/java/io/neoterm/ConfigureFileTest.kt index ad17251..51a8173 100644 --- a/app/src/test/java/io/neoterm/ConfigureFileTest.kt +++ b/app/src/test/java/io/neoterm/ConfigureFileTest.kt @@ -60,6 +60,8 @@ class ConfigureFileTest { val comp = ComponentManager.getComponent() val profile = comp.loadConfigure(File("NeoLang/example/profile.nl")) + + return } @Test