2013-10-19 14:32:00 +08:00
|
|
|
controllers = angular.module("controllers", []);
|
2013-08-17 02:32:58 +08:00
|
|
|
|
2023-02-08 07:34:10 +08:00
|
|
|
controllers.controller("main", function ($scope, $location) {
|
2015-06-14 15:04:29 +08:00
|
|
|
// substr(1) strips a leading slash
|
|
|
|
$scope.currentTab = $location.path().substr(1) || "colors";
|
2023-02-08 07:34:10 +08:00
|
|
|
$scope.changeView = function (view) {
|
2013-08-17 02:32:58 +08:00
|
|
|
$location.path(view);
|
|
|
|
$scope.currentTab = view;
|
2023-02-08 07:34:10 +08:00
|
|
|
};
|
|
|
|
});
|
2013-08-17 02:32:58 +08:00
|
|
|
|
2023-02-08 07:34:10 +08:00
|
|
|
controllers.controller("colorsController", function ($scope, $http) {
|
|
|
|
$scope.changeSelectedColorScheme = function (newScheme) {
|
2014-02-24 17:56:02 +08:00
|
|
|
$scope.selectedColorScheme = angular.copy(newScheme);
|
2013-10-13 02:25:37 +08:00
|
|
|
if ($scope.selectedColorScheme.preferred_background) {
|
|
|
|
$scope.terminalBackgroundColor = $scope.selectedColorScheme.preferred_background;
|
|
|
|
}
|
2014-02-24 17:56:02 +08:00
|
|
|
$scope.selectedColorSetting = false;
|
2023-02-08 07:34:10 +08:00
|
|
|
$scope.customizationActive = false;
|
|
|
|
$scope.csEditingType = false;
|
2013-10-13 02:25:37 +08:00
|
|
|
$scope.colorArraysArray = $scope.getColorArraysArray();
|
|
|
|
//TODO: Save button should be shown only when colors are changed
|
|
|
|
$scope.showSaveButton = true;
|
2017-01-16 06:51:10 +08:00
|
|
|
|
2014-02-24 17:56:02 +08:00
|
|
|
$scope.noteThemeChanged();
|
2023-02-08 07:34:10 +08:00
|
|
|
};
|
2013-10-13 02:25:37 +08:00
|
|
|
|
2023-02-08 07:34:10 +08:00
|
|
|
$scope.changeTerminalBackgroundColor = function (color) {
|
2013-10-13 02:25:37 +08:00
|
|
|
$scope.terminalBackgroundColor = color;
|
2023-02-08 07:34:10 +08:00
|
|
|
};
|
2013-10-13 02:25:37 +08:00
|
|
|
|
2014-02-24 17:56:02 +08:00
|
|
|
$scope.text_color_for_color = text_color_for_color;
|
2017-01-16 06:51:10 +08:00
|
|
|
|
2014-02-24 17:56:02 +08:00
|
|
|
$scope.border_color_for_color = border_color_for_color;
|
2013-12-07 15:42:43 +08:00
|
|
|
|
2020-07-07 07:24:44 +08:00
|
|
|
$scope.interpret_color = interpret_color;
|
|
|
|
|
2023-02-08 07:34:10 +08:00
|
|
|
$scope.getColorArraysArray = function () {
|
2013-10-13 01:48:52 +08:00
|
|
|
var result = null;
|
2023-02-08 07:34:10 +08:00
|
|
|
if ($scope.selectedColorScheme.colors && $scope.selectedColorScheme.colors.length > 0)
|
2013-10-13 01:48:52 +08:00
|
|
|
result = get_colors_as_nested_array($scope.selectedColorScheme.colors, 32);
|
2023-02-08 07:34:10 +08:00
|
|
|
else result = get_colors_as_nested_array(term_256_colors, 32);
|
2013-10-13 01:48:52 +08:00
|
|
|
return result;
|
2023-02-08 07:34:10 +08:00
|
|
|
};
|
2017-01-16 06:51:10 +08:00
|
|
|
|
2023-02-08 07:34:10 +08:00
|
|
|
$scope.beginCustomizationWithSetting = function (setting) {
|
|
|
|
if (!$scope.customizationActive) {
|
|
|
|
$scope.customizationActive = true;
|
|
|
|
$scope.selectedColorSetting = setting;
|
|
|
|
$scope.csEditingType = setting;
|
|
|
|
$scope.csUserVisibleTitle = user_visible_title_for_setting_name(setting);
|
|
|
|
}
|
|
|
|
};
|
2017-01-16 06:51:10 +08:00
|
|
|
|
2023-02-08 07:34:10 +08:00
|
|
|
$scope.selectColorSetting = function (name) {
|
|
|
|
$scope.selectedColorSetting = name;
|
|
|
|
$scope.csEditingType = $scope.customizationActive ? name : "";
|
|
|
|
$scope.csUserVisibleTitle = user_visible_title_for_setting_name(name);
|
|
|
|
$scope.beginCustomizationWithSetting(name);
|
|
|
|
};
|
2017-01-16 06:51:10 +08:00
|
|
|
|
2023-02-08 07:34:10 +08:00
|
|
|
$scope.toggleCustomizationActive = function () {
|
|
|
|
if (!$scope.customizationActive) {
|
|
|
|
$scope.beginCustomizationWithSetting($scope.selectedColorSetting || "command");
|
|
|
|
} else {
|
|
|
|
$scope.customizationActive = false;
|
|
|
|
$scope.selectedColorSetting = "";
|
|
|
|
$scope.csEditingType = "";
|
|
|
|
}
|
|
|
|
};
|
2013-10-13 01:48:52 +08:00
|
|
|
|
2023-02-08 07:34:10 +08:00
|
|
|
$scope.changeSelectedTextColor = function (color) {
|
2013-10-13 01:48:52 +08:00
|
|
|
$scope.selectedColorScheme[$scope.selectedColorSetting] = color;
|
2021-12-14 04:28:16 +08:00
|
|
|
$scope.selectedColorScheme["colordata-" + $scope.selectedColorSetting].color = color;
|
2014-02-24 17:56:02 +08:00
|
|
|
$scope.noteThemeChanged();
|
2023-02-08 07:34:10 +08:00
|
|
|
};
|
2013-10-02 21:40:40 +08:00
|
|
|
|
2023-02-08 07:34:10 +08:00
|
|
|
$scope.sampleTerminalBackgroundColors = [
|
|
|
|
"white",
|
|
|
|
"#" + solarized.base3,
|
|
|
|
"#300",
|
|
|
|
"#003",
|
|
|
|
"#" + solarized.base03,
|
|
|
|
"#232323",
|
|
|
|
"#" + nord.nord0,
|
|
|
|
"black",
|
|
|
|
];
|
2013-10-13 01:48:52 +08:00
|
|
|
|
2013-10-02 21:40:40 +08:00
|
|
|
/* Array of FishColorSchemes */
|
2021-07-10 01:45:03 +08:00
|
|
|
$scope.colorSchemes = [];
|
|
|
|
|
2023-02-08 07:34:10 +08:00
|
|
|
isValidColor = function (col) {
|
2021-12-14 03:21:34 +08:00
|
|
|
if (col == "normal") return true;
|
2021-07-10 02:30:54 +08:00
|
|
|
var s = new Option().style;
|
|
|
|
s.color = col;
|
|
|
|
return !!s.color;
|
2023-02-08 07:34:10 +08:00
|
|
|
};
|
2021-07-10 02:30:54 +08:00
|
|
|
|
2023-02-08 07:34:10 +08:00
|
|
|
$scope.getThemes = function () {
|
|
|
|
$http.get("colors/").then(function (arg) {
|
2021-07-10 01:45:03 +08:00
|
|
|
for (var scheme of arg.data) {
|
2023-02-08 07:34:10 +08:00
|
|
|
var currentScheme = { name: "Current", colors: [], preferred_background: "black" };
|
2021-07-10 01:45:03 +08:00
|
|
|
currentScheme["name"] = scheme["theme"];
|
2021-09-03 23:37:54 +08:00
|
|
|
if (scheme["name"]) currentScheme["name"] = scheme["name"];
|
2021-07-10 01:45:03 +08:00
|
|
|
var data = scheme["colors"];
|
2021-07-10 02:30:54 +08:00
|
|
|
if (scheme["preferred_background"]) {
|
|
|
|
if (isValidColor(scheme["preferred_background"])) {
|
|
|
|
currentScheme["preferred_background"] = scheme["preferred_background"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (scheme["url"]) currentScheme["url"] = scheme["url"];
|
|
|
|
|
2021-07-10 01:45:03 +08:00
|
|
|
for (var i in data) {
|
2023-02-08 07:34:10 +08:00
|
|
|
currentScheme[data[i].name] = interpret_color(data[i].color).replace(/#/, "");
|
2021-12-14 04:42:26 +08:00
|
|
|
// HACK: For some reason the colors array is cleared later
|
|
|
|
// So we cheesily encode the actual objects as colordata-, so we can send them.
|
|
|
|
// TODO: We should switch to keeping the objects, and also displaying them
|
|
|
|
// with underlines and such.
|
|
|
|
currentScheme["colordata-" + data[i].name] = data[i];
|
2021-07-10 01:45:03 +08:00
|
|
|
}
|
|
|
|
$scope.colorSchemes.push(currentScheme);
|
2013-10-20 16:58:40 +08:00
|
|
|
}
|
2021-07-10 01:45:03 +08:00
|
|
|
$scope.changeSelectedColorScheme($scope.colorSchemes[0]);
|
2023-02-08 07:34:10 +08:00
|
|
|
});
|
|
|
|
};
|
2013-10-13 16:20:21 +08:00
|
|
|
|
2023-02-08 07:34:10 +08:00
|
|
|
$scope.saveThemeButtonTitle = "Set Theme";
|
2017-01-16 06:51:10 +08:00
|
|
|
|
2023-02-08 07:34:10 +08:00
|
|
|
$scope.noteThemeChanged = function () {
|
|
|
|
$scope.saveThemeButtonTitle = "Set Theme";
|
|
|
|
};
|
2014-02-24 17:56:02 +08:00
|
|
|
|
2023-02-08 07:34:10 +08:00
|
|
|
$scope.setTheme = function () {
|
|
|
|
var settingNames = [
|
|
|
|
"normal",
|
|
|
|
"command",
|
|
|
|
"quote",
|
|
|
|
"redirection",
|
|
|
|
"end",
|
|
|
|
"error",
|
|
|
|
"param",
|
|
|
|
"comment",
|
|
|
|
"match",
|
|
|
|
"selection",
|
|
|
|
"search_match",
|
|
|
|
"history_current",
|
|
|
|
"operator",
|
|
|
|
"escape",
|
|
|
|
"cwd",
|
|
|
|
"cwd_root",
|
|
|
|
"valid_path",
|
|
|
|
"autosuggestion",
|
|
|
|
"user",
|
|
|
|
"host",
|
|
|
|
"cancel",
|
|
|
|
// Cheesy hardcoded variable names ahoy!
|
|
|
|
// These are all the pager vars,
|
|
|
|
// we should really just save all these in a dictionary.
|
|
|
|
"fish_pager_color_background",
|
|
|
|
"fish_pager_color_prefix",
|
|
|
|
"fish_pager_color_progress",
|
|
|
|
"fish_pager_color_completion",
|
|
|
|
"fish_pager_color_description",
|
|
|
|
"fish_pager_color_selected_background",
|
|
|
|
"fish_pager_color_selected_prefix",
|
|
|
|
"fish_pager_color_selected_completion",
|
|
|
|
"fish_pager_color_selected_description",
|
|
|
|
// TODO: Setting these to empty currently makes them weird. Figure out why!
|
|
|
|
/*
|
2021-12-14 03:21:34 +08:00
|
|
|
"fish_pager_color_secondary_background",
|
|
|
|
"fish_pager_color_secondary_prefix",
|
|
|
|
"fish_pager_color_secondary_completion",
|
|
|
|
"fish_pager_color_secondary_description",
|
|
|
|
*/
|
2023-02-08 07:34:10 +08:00
|
|
|
];
|
2014-02-24 17:56:02 +08:00
|
|
|
var remaining = settingNames.length;
|
2021-12-13 04:32:32 +08:00
|
|
|
var postdata = {
|
2023-02-08 07:34:10 +08:00
|
|
|
theme: $scope.selectedColorScheme["name"],
|
|
|
|
colors: [],
|
|
|
|
};
|
2021-12-13 04:32:32 +08:00
|
|
|
for (var name of settingNames) {
|
2018-12-05 16:52:36 +08:00
|
|
|
var selected;
|
2021-12-14 04:28:16 +08:00
|
|
|
var realname = "colordata-" + name;
|
2018-11-29 21:49:12 +08:00
|
|
|
// Skip colors undefined in the current theme
|
2018-12-05 16:52:36 +08:00
|
|
|
// js is dumb - the empty string is false,
|
|
|
|
// but we want that to mean unsetting a var.
|
2023-02-08 07:34:10 +08:00
|
|
|
if (
|
|
|
|
!$scope.selectedColorScheme[realname] &&
|
|
|
|
$scope.selectedColorScheme[realname] !== ""
|
|
|
|
) {
|
2021-12-15 05:54:28 +08:00
|
|
|
continue;
|
2018-12-05 16:52:36 +08:00
|
|
|
} else {
|
2021-12-14 04:28:16 +08:00
|
|
|
selected = $scope.selectedColorScheme[realname];
|
2018-11-29 21:49:12 +08:00
|
|
|
}
|
2021-07-10 00:24:41 +08:00
|
|
|
postdata.colors.push({
|
2023-02-08 07:34:10 +08:00
|
|
|
what: name,
|
|
|
|
color: selected,
|
2021-07-10 00:24:41 +08:00
|
|
|
});
|
2013-10-13 02:25:37 +08:00
|
|
|
}
|
2023-02-08 07:34:10 +08:00
|
|
|
$http
|
|
|
|
.post("set_color/", postdata, { headers: { "Content-Type": "application/json" } })
|
|
|
|
.then(function (arg) {
|
|
|
|
if (arg.status == 200) {
|
|
|
|
$scope.saveThemeButtonTitle = "Theme Set!";
|
|
|
|
}
|
2018-09-09 15:26:38 +08:00
|
|
|
});
|
|
|
|
};
|
2013-10-12 20:17:43 +08:00
|
|
|
|
2023-02-08 07:34:10 +08:00
|
|
|
$scope.getThemes();
|
2013-10-13 21:06:46 +08:00
|
|
|
});
|