Only save color/history
This commit is contained in:
parent
468de2a4a4
commit
60c3c45868
@ -306,9 +306,13 @@ const save: Command = {
|
|||||||
desc: "Saves the current color and command history to local storage.",
|
desc: "Saves the current color and command history to local storage.",
|
||||||
subcommands: {
|
subcommands: {
|
||||||
clear: { name: "clear", desc: "Clear the saved data." },
|
clear: { name: "clear", desc: "Clear the saved data." },
|
||||||
confirm: { name: "confirm", desc: "You explicitly confirm, you allow saving to the local storage." }
|
confirm: { name: "confirm", desc: "You explicitly confirm, you allow saving to the local storage." },
|
||||||
},
|
},
|
||||||
execute: (_flags, args, _raw, cmdIf) => {
|
flags: {
|
||||||
|
color: { short: "c", long: "color", desc: "Only save the color." },
|
||||||
|
history: { short: "h", long: "history", desc: "Only save the history." },
|
||||||
|
},
|
||||||
|
execute: (flags, args, _raw, cmdIf) => {
|
||||||
const defaultRet = [
|
const defaultRet = [
|
||||||
"You can save the current color and command history to local storage.",
|
"You can save the current color and command history to local storage.",
|
||||||
"To do so, use %{save confirm}.",
|
"To do so, use %{save confirm}.",
|
||||||
@ -322,20 +326,28 @@ const save: Command = {
|
|||||||
window.localStorage.clear();
|
window.localStorage.clear();
|
||||||
return ["Colors and history removed from storage."];
|
return ["Colors and history removed from storage."];
|
||||||
} else if (args[0] === "confirm") {
|
} else if (args[0] === "confirm") {
|
||||||
|
const saveColor = save.flags && checkFlagInclude(flags, save.flags.color);
|
||||||
|
const saveHistory = save.flags && checkFlagInclude(flags, save.flags.history);
|
||||||
|
const saveAll = !saveColor && !saveHistory;
|
||||||
|
|
||||||
const result = [];
|
const result = [];
|
||||||
|
|
||||||
const currentColors = getColors();
|
if (saveColor || saveAll) {
|
||||||
const color = new Color(currentColors[0]);
|
const currentColors = getColors();
|
||||||
if(color.contrast(new Color("#000")) < 1.1 || color.alpha() < 0.1) result.push("Skipping saving the color because it's too dark.");
|
const color = new Color(currentColors[0]);
|
||||||
else {
|
if(color.contrast(new Color("#000")) < 1.1 || color.alpha() < 0.1) result.push("Skipping saving the color because it's too dark.");
|
||||||
window.localStorage.setItem("color", currentColors[0]);
|
else {
|
||||||
result.push("Color saved to local storage.");
|
window.localStorage.setItem("color", currentColors[0]);
|
||||||
|
result.push("Color saved to local storage.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const history = cmdIf.callbacks?.getCmdHistory ? cmdIf.callbacks.getCmdHistory() : [];
|
if (saveHistory || saveAll) {
|
||||||
window.localStorage.setItem("history", JSON.stringify(history));
|
const history = cmdIf.callbacks?.getCmdHistory ? cmdIf.callbacks.getCmdHistory() : [];
|
||||||
|
window.localStorage.setItem("history", JSON.stringify(history));
|
||||||
|
result.push("History saved to storage.");
|
||||||
|
}
|
||||||
|
|
||||||
result.push("History saved to storage.");
|
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
return printSyntax(save);
|
return printSyntax(save);
|
||||||
|
Loading…
Reference in New Issue
Block a user