Feature: ColorScheme

This commit is contained in:
zt515 2017-06-12 15:05:48 +08:00
parent 7a3ec1c924
commit 6a810af698
3 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,24 @@
package io.neoterm.customize
import io.neoterm.terminal.TerminalColors
import io.neoterm.terminal.TerminalSession
/**
* @author kiva
*/
class NeoTermColorScheme {
var foreground: String? = null
var background: String? = null
var cursor: String? = null
var color: MutableMap<Int, String> = mutableMapOf()
fun apply(session: TerminalSession?) {
if (session == null) {
return
}
val termSession = session
TerminalColors.COLOR_SCHEME.updateWith(foreground, background, cursor, color)
termSession.emulator.mColors.reset()
}
}

View File

@ -4,6 +4,7 @@ import android.os.Parcel
import android.os.Parcelable
import android.support.v7.widget.Toolbar
import de.mrapp.android.tabswitcher.Tab
import io.neoterm.customize.NeoTermColorScheme
import io.neoterm.terminal.TerminalSession
/**
@ -20,6 +21,10 @@ class TermTab : Tab {
private constructor(source: Parcel) : super(source)
fun changeColorScheme(colorScheme: NeoTermColorScheme?) {
colorScheme?.apply(termSession)
}
fun cleanup() {
termSession?.finishIfRunning()
viewClient?.termView = null

View File

@ -69,6 +69,17 @@ public final class TerminalColorScheme {
System.arraycopy(DEFAULT_COLORSCHEME, 0, mDefaultColors, 0, TextStyle.NUM_INDEXED_COLORS);
}
public void updateWith(String foreground, String background, String cursor, Map<Integer, String> color) {
Properties prop = new Properties();
prop.put("foreground", foreground);
prop.put("background", background);
prop.put("cursor", cursor);
for (int i : color.keySet()) {
prop.put("color" + i, color.get(i));
}
updateWith(prop);
}
public void updateWith(Properties props) {
reset();
for (Map.Entry<Object, Object> entries : props.entrySet()) {