mirror of
https://github.com/Swordfish90/cool-retro-term.git
synced 2025-02-22 04:49:02 +00:00
Profile-bound custom commands now execute
Rather than starting ksession right away, PreprocessedTerminal now waits for ApplicationSettings to finish loading custom command settings from storage. If a custom command is specified, PreprocessedTerminal will tokenize it and pass it onto ksession as a shell program similar to the -e option. If both a -e command and a custom command is specified, the -e version overrides the custom command.
This commit is contained in:
parent
674097f672
commit
cc57fbdcd5
@ -97,6 +97,8 @@ QtObject{
|
|||||||
|
|
||||||
signal terminalFontChanged(string fontSource, int pixelSize, int lineSpacing, real screenScaling, real fontWidth)
|
signal terminalFontChanged(string fontSource, int pixelSize, int lineSpacing, real screenScaling, real fontWidth)
|
||||||
|
|
||||||
|
signal initializedSettings()
|
||||||
|
|
||||||
property Loader fontManager: Loader{
|
property Loader fontManager: Loader{
|
||||||
states: [
|
states: [
|
||||||
State { when: rasterization == no_rasterization
|
State { when: rasterization == no_rasterization
|
||||||
@ -463,6 +465,8 @@ QtObject{
|
|||||||
fullscreen = true;
|
fullscreen = true;
|
||||||
showMenubar = false;
|
showMenubar = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initializedSettings();
|
||||||
}
|
}
|
||||||
Component.onDestruction: {
|
Component.onDestruction: {
|
||||||
storeSettings();
|
storeSettings();
|
||||||
|
@ -129,13 +129,17 @@ Item{
|
|||||||
|
|
||||||
kterminal.lineSpacing = lineSpacing;
|
kterminal.lineSpacing = lineSpacing;
|
||||||
}
|
}
|
||||||
Component.onCompleted: {
|
function startSession() {
|
||||||
appSettings.terminalFontChanged.connect(handleFontChange);
|
appSettings.initializedSettings.disconnect(startSession);
|
||||||
|
|
||||||
// Retrieve the variable set in main.cpp if arguments are passed.
|
// Retrieve the variable set in main.cpp if arguments are passed.
|
||||||
if (defaultCmd) {
|
if (defaultCmd) {
|
||||||
ksession.setShellProgram(defaultCmd);
|
ksession.setShellProgram(defaultCmd);
|
||||||
ksession.setArgs(defaultCmdArgs);
|
ksession.setArgs(defaultCmdArgs);
|
||||||
|
} else if (appSettings.useCustomCommand) {
|
||||||
|
var args = Utils.tokenizeCommandLine(appSettings.customCommand);
|
||||||
|
ksession.setShellProgram(args[0]);
|
||||||
|
ksession.setArgs(args.slice(1));
|
||||||
} else if (!defaultCmd && Qt.platform.os === "osx") {
|
} else if (!defaultCmd && Qt.platform.os === "osx") {
|
||||||
// OSX Requires the following default parameters for auto login.
|
// OSX Requires the following default parameters for auto login.
|
||||||
ksession.setArgs(["-i", "-l"]);
|
ksession.setArgs(["-i", "-l"]);
|
||||||
@ -147,6 +151,10 @@ Item{
|
|||||||
ksession.startShellProgram();
|
ksession.startShellProgram();
|
||||||
forceActiveFocus();
|
forceActiveFocus();
|
||||||
}
|
}
|
||||||
|
Component.onCompleted: {
|
||||||
|
appSettings.terminalFontChanged.connect(handleFontChange);
|
||||||
|
appSettings.initializedSettings.connect(startSession);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Component {
|
Component {
|
||||||
id: linuxContextMenu
|
id: linuxContextMenu
|
||||||
|
@ -21,3 +21,74 @@ function strToColor(s){
|
|||||||
var b = parseInt(s.substring(5,7), 16) / 256;
|
var b = parseInt(s.substring(5,7), 16) / 256;
|
||||||
return Qt.rgba(r, g, b, 1.0);
|
return Qt.rgba(r, g, b, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Tokenizes a command into program and arguments, taking into account quoted
|
||||||
|
* strings and backslashes.
|
||||||
|
* Based on GLib's tokenizer, used by Gnome Terminal
|
||||||
|
*/
|
||||||
|
function tokenizeCommandLine(s){
|
||||||
|
var args = [];
|
||||||
|
var currentToken = "";
|
||||||
|
var quoteChar = "";
|
||||||
|
var escaped = false;
|
||||||
|
var nextToken = function() {
|
||||||
|
args.push(currentToken);
|
||||||
|
currentToken = "";
|
||||||
|
}
|
||||||
|
var appendToCurrentToken = function(c) {
|
||||||
|
currentToken += c;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < s.length; i++) {
|
||||||
|
|
||||||
|
// char followed by backslash, append literally
|
||||||
|
if (escaped) {
|
||||||
|
escaped = false;
|
||||||
|
appendToCurrentToken(s[i]);
|
||||||
|
|
||||||
|
// char inside quotes, either close or append
|
||||||
|
} else if (quoteChar) {
|
||||||
|
escaped = s[i] === '\\';
|
||||||
|
if (quoteChar === s[i]) {
|
||||||
|
quoteChar = "";
|
||||||
|
nextToken();
|
||||||
|
} else if (!escaped) {
|
||||||
|
appendToCurrentToken(s[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// regular char
|
||||||
|
} else {
|
||||||
|
escaped = s[i] === '\\';
|
||||||
|
switch (s[i]) {
|
||||||
|
case '\\':
|
||||||
|
// begin escape
|
||||||
|
break;
|
||||||
|
case '\n':
|
||||||
|
// newlines always delimits
|
||||||
|
nextToken();
|
||||||
|
break;
|
||||||
|
case ' ':
|
||||||
|
case '\t':
|
||||||
|
// delimit on new whitespace
|
||||||
|
if (currentToken) {
|
||||||
|
nextToken();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case '\'':
|
||||||
|
case '"':
|
||||||
|
// begin quoted section
|
||||||
|
quoteChar = s[i];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
appendToCurrentToken(s[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ignore last token if broken quotes/backslash
|
||||||
|
if (currentToken && !escaped && !quoteChar) {
|
||||||
|
nextToken();
|
||||||
|
}
|
||||||
|
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user