Profile: Support profile name
This commit is contained in:
@ -1,3 +1,4 @@
|
|||||||
profile-shell: {
|
profile-shell: {
|
||||||
|
name: "Simple Profile"
|
||||||
bell: true
|
bell: true
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package io.neoterm.component.profile
|
package io.neoterm.component.profile
|
||||||
|
|
||||||
|
import io.neolang.visitor.ConfigVisitor
|
||||||
import io.neoterm.component.codegen.CodeGenParameter
|
import io.neoterm.component.codegen.CodeGenParameter
|
||||||
import io.neoterm.component.codegen.generators.NeoProfileGenerator
|
import io.neoterm.component.codegen.generators.NeoProfileGenerator
|
||||||
import io.neoterm.component.codegen.interfaces.CodeGenObject
|
import io.neoterm.component.codegen.interfaces.CodeGenObject
|
||||||
@ -10,9 +11,37 @@ import io.neoterm.frontend.component.helper.ConfigFileBasedObject
|
|||||||
* @author kiva
|
* @author kiva
|
||||||
*/
|
*/
|
||||||
abstract class NeoProfile : CodeGenObject, ConfigFileBasedObject {
|
abstract class NeoProfile : CodeGenObject, ConfigFileBasedObject {
|
||||||
|
companion object {
|
||||||
|
private const val PROFILE_NAME = "name"
|
||||||
|
}
|
||||||
|
|
||||||
abstract val profileMetaName: String
|
abstract val profileMetaName: String
|
||||||
|
private val profileMetaPath
|
||||||
|
get() = arrayOf(profileMetaName)
|
||||||
|
|
||||||
|
var profileName = "Unknown Profile"
|
||||||
|
|
||||||
|
override fun onConfigLoaded(configVisitor: ConfigVisitor) {
|
||||||
|
profileName = configVisitor.getProfileString(PROFILE_NAME, profileName)
|
||||||
|
}
|
||||||
|
|
||||||
override fun getCodeGenerator(parameter: CodeGenParameter): CodeGenerator {
|
override fun getCodeGenerator(parameter: CodeGenParameter): CodeGenerator {
|
||||||
return NeoProfileGenerator(parameter)
|
return NeoProfileGenerator(parameter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected fun ConfigVisitor.getProfileString(key: String, fallback: String): String {
|
||||||
|
return getProfileString(key) ?: fallback
|
||||||
|
}
|
||||||
|
|
||||||
|
protected fun ConfigVisitor.getProfileBoolean(key: String, fallback: Boolean): Boolean {
|
||||||
|
return getProfileBoolean(key) ?: fallback
|
||||||
|
}
|
||||||
|
|
||||||
|
protected fun ConfigVisitor.getProfileString(key: String): String? {
|
||||||
|
return this.getStringValue(profileMetaPath, key)
|
||||||
|
}
|
||||||
|
|
||||||
|
protected fun ConfigVisitor.getProfileBoolean(key: String): Boolean? {
|
||||||
|
return this.getBooleanValue(profileMetaPath, key)
|
||||||
|
}
|
||||||
}
|
}
|
@ -27,8 +27,6 @@ class ShellProfile : NeoProfile() {
|
|||||||
private const val FONT = "font"
|
private const val FONT = "font"
|
||||||
private const val COLOR_SCHEME = "color-scheme"
|
private const val COLOR_SCHEME = "color-scheme"
|
||||||
private const val WORD_BASED_IME = "word-based-ime"
|
private const val WORD_BASED_IME = "word-based-ime"
|
||||||
|
|
||||||
private val PROFILE_META_PATH = arrayOf(PROFILE_META_NAME)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override val profileMetaName = PROFILE_META_NAME
|
override val profileMetaName = PROFILE_META_NAME
|
||||||
@ -68,6 +66,7 @@ class ShellProfile : NeoProfile() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onConfigLoaded(configVisitor: ConfigVisitor) {
|
override fun onConfigLoaded(configVisitor: ConfigVisitor) {
|
||||||
|
super.onConfigLoaded(configVisitor)
|
||||||
loginShell = configVisitor.getProfileString(LOGIN_SHELL, loginShell)
|
loginShell = configVisitor.getProfileString(LOGIN_SHELL, loginShell)
|
||||||
initialCommand = configVisitor.getProfileString(INITIAL_COMMAND, initialCommand)
|
initialCommand = configVisitor.getProfileString(INITIAL_COMMAND, initialCommand)
|
||||||
enableBell = configVisitor.getProfileBoolean(BELL, enableBell)
|
enableBell = configVisitor.getProfileBoolean(BELL, enableBell)
|
||||||
@ -81,20 +80,4 @@ class ShellProfile : NeoProfile() {
|
|||||||
profileFont = configVisitor.getProfileString(FONT, profileFont)
|
profileFont = configVisitor.getProfileString(FONT, profileFont)
|
||||||
profileColorScheme = configVisitor.getProfileString(COLOR_SCHEME, profileColorScheme)
|
profileColorScheme = configVisitor.getProfileString(COLOR_SCHEME, profileColorScheme)
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user