mirror of
https://github.com/vale981/tridactyl
synced 2025-03-05 09:31:41 -05:00
Hook mktridactylrc up to native messenger
Still need to doublecheck subconfigs and fallbacks. Also need to make sure that ! overwrites and error out if it isn't supplied.
This commit is contained in:
parent
66de3e815d
commit
bdc6a39180
4 changed files with 107 additions and 57 deletions
|
@ -468,7 +468,8 @@ def handleMessage(message):
|
||||||
reply["code"] = 2
|
reply["code"] = 2
|
||||||
|
|
||||||
elif cmd == "write":
|
elif cmd == "write":
|
||||||
with open(message["file"], "w") as file:
|
path = os.path.expanduser(message["file"])
|
||||||
|
with open(path, "w") as file:
|
||||||
file.write(message["content"])
|
file.write(message["content"])
|
||||||
|
|
||||||
elif cmd == "temp":
|
elif cmd == "temp":
|
||||||
|
|
|
@ -13,12 +13,14 @@ export async function source(filename = "auto") {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function write(conf: string, force = false, filename = "auto") {
|
export async function writeRc(conf: string, force = false, filename = "auto") {
|
||||||
let path: string
|
let path: string
|
||||||
if (filename === "auto") {
|
if (filename === "auto") {
|
||||||
path = await Native.getrcpath()
|
path = await Native.getrcpath()
|
||||||
|
} else {
|
||||||
|
path = filename
|
||||||
}
|
}
|
||||||
|
return await Native.write(path, conf)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function runRc(rc: string) {
|
export async function runRc(rc: string) {
|
||||||
|
|
|
@ -670,7 +670,7 @@ export async function nativeinstall() {
|
||||||
|
|
||||||
TODO: Write documentation.
|
TODO: Write documentation.
|
||||||
Available flags:
|
Available flags:
|
||||||
- `--force` will overwrite the config file if it exists.
|
- `-f` will overwrite the config file if it exists.
|
||||||
@param string[] argArr an optional string of arguments to be parsed.
|
@param string[] argArr an optional string of arguments to be parsed.
|
||||||
@returns the parsed config.
|
@returns the parsed config.
|
||||||
|
|
||||||
|
@ -680,7 +680,7 @@ export async function mktridactylrc(...argArr: string[]) {
|
||||||
let overwrite = false
|
let overwrite = false
|
||||||
|
|
||||||
const argParse = (args: string[]): string[] => {
|
const argParse = (args: string[]): string[] => {
|
||||||
if (args[0] === "--force") {
|
if (args[0] === "-f") {
|
||||||
overwrite = true
|
overwrite = true
|
||||||
args.shift()
|
args.shift()
|
||||||
argParse(args)
|
argParse(args)
|
||||||
|
@ -689,13 +689,12 @@ export async function mktridactylrc(...argArr: string[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const file = argParse(argArr).join(" ") || undefined
|
const file = argParse(argArr).join(" ") || undefined
|
||||||
//TODO: Add actual native messenger code here.
|
|
||||||
//if (await Native.nativegate("0.1.3")) if (!await rc.source(file)) logger.error("Could not find RC file")
|
|
||||||
|
|
||||||
const conf = config.parseConfig()
|
const conf = config.parseConfig()
|
||||||
console.log(conf)
|
console.log(conf)
|
||||||
console.log(file)
|
console.log(file)
|
||||||
console.log(overwrite)
|
console.log(overwrite)
|
||||||
|
if (await Native.nativegate("0.1.3") && (!await rc.writeRc(conf, overwrite, file))) logger.error("Could not write RC file")
|
||||||
|
|
||||||
return conf
|
return conf
|
||||||
}
|
}
|
||||||
|
|
|
@ -1377,71 +1377,119 @@ export function removeChangeListener<P extends keyof default_config>(
|
||||||
|
|
||||||
*/
|
*/
|
||||||
export function parseConfig(): string {
|
export function parseConfig(): string {
|
||||||
// Parse the config into sections, this is my last resort.
|
let p = {
|
||||||
const parsedConf = []
|
conf: [],
|
||||||
const parsedBinds = []
|
binds: [],
|
||||||
const parsedAliases = []
|
aliases: [],
|
||||||
const parsedAucmds = []
|
subconfigs: [],
|
||||||
const parsedAucons = []
|
aucmds: [],
|
||||||
const parsedLogging = []
|
aucons: [],
|
||||||
|
logging: [],
|
||||||
|
}
|
||||||
|
|
||||||
for (const i in USERCONFIG) {
|
p = parseConfigHelper(USERCONFIG, p)
|
||||||
if (typeof USERCONFIG[i] !== "object")
|
|
||||||
parsedConf.push(`set ${i} ${USERCONFIG[i]}`)
|
const s = {
|
||||||
|
general: ``,
|
||||||
|
binds: ``,
|
||||||
|
aliases: ``,
|
||||||
|
aucmds: ``,
|
||||||
|
aucons: ``,
|
||||||
|
subconfigs: ``,
|
||||||
|
logging: ``,
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p.conf.length > 0)
|
||||||
|
s.general = `" General Settings\n${p.conf.join("\n")}\n\n`
|
||||||
|
if (p.binds.length > 0)
|
||||||
|
s.binds = `" Binds\n${p.binds.join("\n")}\n\n`
|
||||||
|
if (p.aliases.length > 0)
|
||||||
|
s.aliases = `" Aliases\n${p.aliases.join("\n")}\n\n`
|
||||||
|
if (p.aucmds.length > 0)
|
||||||
|
s.aucmds = `" Autocmds\n${p.aucmds.join("\n")}\n\n`
|
||||||
|
if (p.aucons.length > 0)
|
||||||
|
s.aucons = `" Autocontainers\n${p.aucons.join("\n")}\n\n`
|
||||||
|
if (p.subconfigs.length > 0)
|
||||||
|
s.subconfigs = `" Subconfig Settings\n${p.subconfigs.join("\n")}\n\n`
|
||||||
|
if (p.logging.length > 0)
|
||||||
|
s.logging = `" Logging\n" + p.logging.join("\n")}\n\n`
|
||||||
|
|
||||||
|
return `${s.general}${s.binds}${s.subconfigs}${s.aliases}${s.aucmds}${s.aucons}${s.logging}`
|
||||||
|
}
|
||||||
|
|
||||||
|
const parseConfigHelper = (pconf, parseobj) => {
|
||||||
|
for (const i in pconf) {
|
||||||
|
if (typeof pconf[i] !== "object")
|
||||||
|
parseobj.conf.push(`set ${i} ${pconf[i]}`)
|
||||||
else {
|
else {
|
||||||
for (const e of Object.keys(USERCONFIG[i])) {
|
for (const e of Object.keys(pconf[i])) {
|
||||||
if (i === "nmaps") {
|
if (i === "nmaps" ) {
|
||||||
parsedBinds.push(`bind ${e} ${USERCONFIG[i][e]}`)
|
if (pconf[i][e].length > 0) {
|
||||||
} else if (i === "exaliases") {
|
parseobj.binds.push(`bind ${e} "${pconf[i][e]}"`)
|
||||||
// Only really useful if mapping the entire config and not just USERCONFIG.
|
|
||||||
if (e === "alias") {
|
|
||||||
parsedAliases.push(`command ${e} ${USERCONFIG[i][e]}`)
|
|
||||||
} else {
|
} else {
|
||||||
parsedAliases.push(`alias ${e} ${USERCONFIG[i][e]}`)
|
parseobj.binds.push(`unbind ${e}`)
|
||||||
|
}
|
||||||
|
} else if (i === "exmaps" ) {
|
||||||
|
if (pconf[i][e].length > 0) {
|
||||||
|
parseobj.binds.push(`bind --mode=ex ${e} "${pconf[i][e]}"`)
|
||||||
|
} else {
|
||||||
|
parseobj.binds.push(`unbind --mode=ex ${e}`)
|
||||||
|
}
|
||||||
|
} else if (i === "ignoremaps" ) {
|
||||||
|
if (pconf[i][e].length > 0) {
|
||||||
|
parseobj.binds.push(`bind --mode=ignore ${e} "${pconf[i][e]}"`)
|
||||||
|
} else {
|
||||||
|
parseobj.binds.push(`unbind --mode=ignore ${e}`)
|
||||||
|
}
|
||||||
|
} else if (i === "imaps" ) {
|
||||||
|
if (pconf[i][e].length > 0) {
|
||||||
|
parseobj.binds.push(`bind --mode=insert ${e} "${pconf[i][e]}"`)
|
||||||
|
} else {
|
||||||
|
parseobj.binds.push(`unbind --mode=insert ${e}`)
|
||||||
|
}
|
||||||
|
} else if (i === "inputmaps" ) {
|
||||||
|
if (pconf[i][e].length > 0) {
|
||||||
|
parseobj.binds.push(`bind --mode=input ${e} "${pconf[i][e]}"`)
|
||||||
|
} else {
|
||||||
|
parseobj.binds.push(`unbind --mode=input ${e}`)
|
||||||
|
}
|
||||||
|
} else if (i === "hintmaps" ) {
|
||||||
|
if (pconf[i][e].length > 0) {
|
||||||
|
parseobj.binds.push(`bind --mode=hint ${e} "${pconf[i][e]}"`)
|
||||||
|
} else {
|
||||||
|
parseobj.binds.push(`unbind --mode=hint ${e}`)
|
||||||
|
}
|
||||||
|
} else if (i === "subconfigs") {
|
||||||
|
parseobj.subconfigs.push(`js tri.config.set("${i}, {"${e}": ${JSON.stringify(pconf[i][e])}})`)
|
||||||
|
} else if (i === "exaliases") {
|
||||||
|
// Only really useful if mapping the entire config and not just pconf.
|
||||||
|
if (e === "alias") {
|
||||||
|
parseobj.aliases.push(`command ${e} ${pconf[i][e]}`)
|
||||||
|
} else {
|
||||||
|
parseobj.aliases.push(`alias ${e} ${pconf[i][e]}`)
|
||||||
}
|
}
|
||||||
} else if (i === "autocmds") {
|
} else if (i === "autocmds") {
|
||||||
for (const a of Object.keys(USERCONFIG[i][e])) {
|
for (const a of Object.keys(pconf[i][e])) {
|
||||||
parsedAucmds.push(`autocmd ${e} ${a} ${USERCONFIG[i][e][a]}`)
|
parseobj.aucmds.push(`autocmd ${e} ${a} ${pconf[i][e][a]}`)
|
||||||
}
|
}
|
||||||
} else if (i === "autocontain") {
|
} else if (i === "autocontain") {
|
||||||
parsedAucmds.push(`autocontain ${e} ${USERCONFIG[i][e]}`)
|
parseobj.aucmds.push(`autocontain ${e} ${pconf[i][e]}`)
|
||||||
} else if (i === "logging") {
|
} else if (i === "logging") {
|
||||||
// Map the int values in e to a log level
|
// Map the int values in e to a log level
|
||||||
let level
|
let level
|
||||||
if (USERCONFIG[i][e] === 0) level = "never"
|
if (pconf[i][e] === 0) level = "never"
|
||||||
if (USERCONFIG[i][e] === 1) level = "error"
|
if (pconf[i][e] === 1) level = "error"
|
||||||
if (USERCONFIG[i][e] === 2) level = "warning"
|
if (pconf[i][e] === 2) level = "warning"
|
||||||
if (USERCONFIG[i][e] === 3) level = "info"
|
if (pconf[i][e] === 3) level = "info"
|
||||||
if (USERCONFIG[i][e] === 4) level = "debug"
|
if (pconf[i][e] === 4) level = "debug"
|
||||||
parsedLogging.push(`set logging.${e} ${level}`)
|
parseobj.logging.push(`set logging.${e} ${level}`)
|
||||||
} else {
|
} else {
|
||||||
parsedConf.push(`set ${i}.${e} ${USERCONFIG[i][e]}`)
|
parseobj.conf.push(`set ${i}.${e} ${pconf[i][e]}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return parseobj
|
||||||
let genSettings = ``
|
|
||||||
let bindSettings = ``
|
|
||||||
let aliasSettings = ``
|
|
||||||
let aucmdSettings = ``
|
|
||||||
let auconSettings = ``
|
|
||||||
let logSettings = ``
|
|
||||||
|
|
||||||
if (parsedConf.length > 0)
|
|
||||||
genSettings = `"General Settings\n${parsedConf.join("\n")}\n\n`
|
|
||||||
if (parsedBinds.length > 0)
|
|
||||||
bindSettings = `"Binds\n${parsedBinds.join("\n")}\n\n`
|
|
||||||
if (parsedAliases.length > 0)
|
|
||||||
aliasSettings = `"Aliases\n${parsedAliases.join("\n")}\n\n`
|
|
||||||
if (parsedAucmds.length > 0)
|
|
||||||
aucmdSettings = `"Autocmds\n${parsedAucmds.join("\n")}\n\n`
|
|
||||||
if (parsedAucons.length > 0)
|
|
||||||
auconSettings = `"Autocontainers\n${parsedAucons.join("\n")}\n\n`
|
|
||||||
if (parsedLogging.length > 0)
|
|
||||||
logSettings = `"Logging\n" + parsedLogging.join("\n")}\n\n`
|
|
||||||
|
|
||||||
return `${genSettings}${bindSettings}${aliasSettings}${aucmdSettings}${auconSettings}${logSettings}`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Listen for changes to the storage and update the USERCONFIG if appropriate.
|
// Listen for changes to the storage and update the USERCONFIG if appropriate.
|
||||||
|
|
Loading…
Add table
Reference in a new issue