Profile: create sessions with profile
This commit is contained in:
@ -1,5 +1,8 @@
|
|||||||
package io.neoterm.component.profile
|
package io.neoterm.component.profile
|
||||||
|
|
||||||
|
import io.neoterm.component.color.ColorSchemeComponent
|
||||||
|
import io.neoterm.component.font.FontComponent
|
||||||
|
import io.neoterm.frontend.component.ComponentManager
|
||||||
import io.neoterm.frontend.preference.DefaultPreference
|
import io.neoterm.frontend.preference.DefaultPreference
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -13,7 +16,16 @@ class Profile {
|
|||||||
var enableVibrate = DefaultPreference.enableVibrate
|
var enableVibrate = DefaultPreference.enableVibrate
|
||||||
var enableExecveWrapper = DefaultPreference.enableExecveWrapper
|
var enableExecveWrapper = DefaultPreference.enableExecveWrapper
|
||||||
var enableSpecialVolumeKeys = DefaultPreference.enableSpecialVolumeKeys
|
var enableSpecialVolumeKeys = DefaultPreference.enableSpecialVolumeKeys
|
||||||
|
var enableExitMessage = DefaultPreference.enableExitMessage;
|
||||||
|
|
||||||
lateinit var profileFont: String
|
var profileFont: String
|
||||||
lateinit var profileColorScheme: String
|
var profileColorScheme: String
|
||||||
|
|
||||||
|
init {
|
||||||
|
val fontComp = ComponentManager.getComponent<FontComponent>()
|
||||||
|
val colorComp = ComponentManager.getComponent<ColorSchemeComponent>()
|
||||||
|
|
||||||
|
profileFont = fontComp.getCurrentFontName()
|
||||||
|
profileColorScheme = colorComp.getCurrentColorSchemeName()
|
||||||
|
}
|
||||||
}
|
}
|
@ -101,10 +101,6 @@ class SessionComponent : NeoComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun createSession(context: Context, parameter: ShellParameter): ShellTermSession {
|
fun createSession(context: Context, parameter: ShellParameter): ShellTermSession {
|
||||||
val initCommand = parameter.initialCommand ?:
|
|
||||||
NeoPreference.loadString(R.string.key_general_initial_command,
|
|
||||||
DefaultPreference.initialCommand)
|
|
||||||
|
|
||||||
val session = ShellTermSession.Builder()
|
val session = ShellTermSession.Builder()
|
||||||
.executablePath(parameter.executablePath)
|
.executablePath(parameter.executablePath)
|
||||||
.currentWorkingDirectory(parameter.cwd)
|
.currentWorkingDirectory(parameter.cwd)
|
||||||
@ -112,9 +108,10 @@ class SessionComponent : NeoComponent {
|
|||||||
.systemShell(parameter.systemShell)
|
.systemShell(parameter.systemShell)
|
||||||
.envArray(parameter.env)
|
.envArray(parameter.env)
|
||||||
.argArray(parameter.arguments)
|
.argArray(parameter.arguments)
|
||||||
|
.initialCommand(parameter.initialCommand)
|
||||||
|
.profile(parameter.profile)
|
||||||
.create(context)
|
.create(context)
|
||||||
TerminalUtils.setupTerminalSession(session)
|
TerminalUtils.setupTerminalSession(session)
|
||||||
session.initialCommand = initCommand
|
|
||||||
return session
|
return session
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -19,6 +19,7 @@ object DefaultPreference {
|
|||||||
const val enableExplicitExtraKeysWeight = false
|
const val enableExplicitExtraKeysWeight = false
|
||||||
const val enableBackButtonBeMappedToEscape = false
|
const val enableBackButtonBeMappedToEscape = false
|
||||||
const val enableSpecialVolumeKeys = false
|
const val enableSpecialVolumeKeys = false
|
||||||
|
const val enableExitMessage = true
|
||||||
|
|
||||||
const val loginShell = "sh"
|
const val loginShell = "sh"
|
||||||
const val initialCommand = ""
|
const val initialCommand = ""
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package io.neoterm.frontend.session.shell
|
package io.neoterm.frontend.session.shell
|
||||||
|
|
||||||
import io.neoterm.backend.TerminalSession
|
import io.neoterm.backend.TerminalSession
|
||||||
|
import io.neoterm.component.profile.Profile
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author kiva
|
* @author kiva
|
||||||
@ -13,6 +14,7 @@ class ShellParameter {
|
|||||||
var env: Array<Pair<String, String>>? = null
|
var env: Array<Pair<String, String>>? = null
|
||||||
var sessionCallback: TerminalSession.SessionChangedCallback? = null
|
var sessionCallback: TerminalSession.SessionChangedCallback? = null
|
||||||
var systemShell: Boolean = false
|
var systemShell: Boolean = false
|
||||||
|
var profile: Profile? = null
|
||||||
|
|
||||||
fun executablePath(executablePath: String?): ShellParameter {
|
fun executablePath(executablePath: String?): ShellParameter {
|
||||||
this.executablePath = executablePath
|
this.executablePath = executablePath
|
||||||
@ -48,4 +50,9 @@ class ShellParameter {
|
|||||||
this.systemShell = systemShell
|
this.systemShell = systemShell
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun profile(profile: Profile): ShellParameter {
|
||||||
|
this.profile = profile
|
||||||
|
return this
|
||||||
|
}
|
||||||
}
|
}
|
@ -4,6 +4,7 @@ import android.content.Context
|
|||||||
import io.neoterm.App
|
import io.neoterm.App
|
||||||
import io.neoterm.R
|
import io.neoterm.R
|
||||||
import io.neoterm.backend.TerminalSession
|
import io.neoterm.backend.TerminalSession
|
||||||
|
import io.neoterm.component.profile.Profile
|
||||||
import io.neoterm.frontend.preference.DefaultPreference
|
import io.neoterm.frontend.preference.DefaultPreference
|
||||||
import io.neoterm.frontend.session.shell.client.TermSessionCallback
|
import io.neoterm.frontend.session.shell.client.TermSessionCallback
|
||||||
import io.neoterm.frontend.preference.NeoPreference
|
import io.neoterm.frontend.preference.NeoPreference
|
||||||
@ -13,7 +14,12 @@ import java.io.File
|
|||||||
/**
|
/**
|
||||||
* @author kiva
|
* @author kiva
|
||||||
*/
|
*/
|
||||||
open class ShellTermSession private constructor(shellPath: String, cwd: String, args: Array<String>, env: Array<String>, changeCallback: SessionChangedCallback) : TerminalSession(shellPath, cwd, args, env, changeCallback) {
|
open class ShellTermSession private constructor(shellPath: String, cwd: String,
|
||||||
|
args: Array<String>, env: Array<String>,
|
||||||
|
changeCallback: SessionChangedCallback,
|
||||||
|
profile: Profile)
|
||||||
|
: TerminalSession(shellPath, cwd, args, env, changeCallback) {
|
||||||
|
|
||||||
var initialCommand: String? = null
|
var initialCommand: String? = null
|
||||||
var exitPrompt = App.get().getString(R.string.process_exit_prompt)
|
var exitPrompt = App.get().getString(R.string.process_exit_prompt)
|
||||||
|
|
||||||
@ -55,6 +61,20 @@ open class ShellTermSession private constructor(shellPath: String, cwd: String,
|
|||||||
private var env: MutableList<Pair<String, String>>? = null
|
private var env: MutableList<Pair<String, String>>? = null
|
||||||
private var changeCallback: SessionChangedCallback? = null
|
private var changeCallback: SessionChangedCallback? = null
|
||||||
private var systemShell = false
|
private var systemShell = false
|
||||||
|
private var initialCommand: String? = null
|
||||||
|
private var profile = Profile()
|
||||||
|
|
||||||
|
fun profile(profile: Profile?): Builder {
|
||||||
|
if (profile != null) {
|
||||||
|
this.profile = profile
|
||||||
|
}
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun initialCommand(command: String?): Builder {
|
||||||
|
this.initialCommand = command
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
fun executablePath(shell: String?): Builder {
|
fun executablePath(shell: String?): Builder {
|
||||||
this.executablePath = shell
|
this.executablePath = shell
|
||||||
@ -140,7 +160,7 @@ open class ShellTermSession private constructor(shellPath: String, cwd: String,
|
|||||||
val args = this.args ?: mutableListOf(shell)
|
val args = this.args ?: mutableListOf(shell)
|
||||||
val env = transformEnvironment(this.env) ?: buildEnvironment(cwd, systemShell)
|
val env = transformEnvironment(this.env) ?: buildEnvironment(cwd, systemShell)
|
||||||
val callback = changeCallback ?: TermSessionCallback()
|
val callback = changeCallback ?: TermSessionCallback()
|
||||||
return ShellTermSession(shell, cwd, args.toTypedArray(), env, callback)
|
return ShellTermSession(shell, cwd, args.toTypedArray(), env, callback, profile)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun transformEnvironment(env: MutableList<Pair<String, String>>?): Array<String>? {
|
private fun transformEnvironment(env: MutableList<Pair<String, String>>?): Array<String>? {
|
||||||
|
Reference in New Issue
Block a user