string rewriting IME wip

This commit is contained in:
minjaesong
2021-11-12 14:42:18 +09:00
parent 59b7126254
commit 092d95a5a3
7 changed files with 604 additions and 25 deletions

View File

@@ -33,7 +33,8 @@ data class TerrarumIMEConf(
val name: String,
val copying: String,
val candidates: TerrarumIMEViewCount,
val symbols: Keysyms
val symbols: Keysyms,
val mode: TerrarumIMEMode
)
enum class TerrarumIMEViewCount {
@@ -46,6 +47,10 @@ enum class TerrarumIMEViewCount {
}
}
enum class TerrarumIMEMode {
CANDIDATES, REWRITE
}
/**
* Key Layout File Structure for Low Layer:
* - n: Displayed name of the keyboard layout
@@ -151,7 +156,13 @@ object IME {
}
private fun String.toCanditates(): List<String> =
this.split(',').mapNotNull { it.ifBlank { null } }
this.split(IMEDictionary.CAND_DELIM).mapNotNull { it.ifBlank { null } }
private fun String.toIMEMode(): TerrarumIMEMode =
when (this.lowercase()) {
"rewrite" -> TerrarumIMEMode.REWRITE
"candidates" -> TerrarumIMEMode.CANDIDATES
else -> throw IllegalArgumentException("Unknown operation mode: $this")
}
private fun parseImeFile(file: File): TerrarumIME {
val code = file.readText(Charsets.UTF_8)
@@ -160,6 +171,7 @@ object IME {
val candidatesCount = jsval.getMember("v").asString().toViewCount()
val copying = jsval.getMember("c").asString()
val keysyms = Array(256) { Array<String?>(4) { null } }
val mode = jsval.getMember("m").asString().toIMEMode()
for (keycode in 0L until 256L) {
val a = jsval.getMember("t").getArrayElement(keycode)
@@ -177,7 +189,7 @@ object IME {
return TerrarumIME(
name,
TerrarumIMEConf(name, copying, candidatesCount, keysyms),
TerrarumIMEConf(name, copying, candidatesCount, keysyms, mode),
{ headkey, shifted, alted, lowLayerKeysym ->
val a = jsval.invokeMember("accept", headkey, shifted, alted, lowLayerKeysym)
a.getArrayElement(0).asString().toCanditates() to a.getArrayElement(1).asString()