Julkaistu lähde
Lataa lähde ZIP
CH-J Tools
Selaile hakemistoja ja tiedostoja tietyn sovelluksen julkaisua varten.
CH-J / Server Manager
1704 tiedostot
0.1.2-beta
Lisätty: · Rakennettu:
1
// Terminal look. The CH-J default stays fixed; a saved appearance only overrides what the user chose.2
(function (root) {3
const DEFAULT_FONT = "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace";4
const DEFAULTS = Object.freeze({ fontFamily: DEFAULT_FONT, fontSize: 13, fontWeight: "normal", lineHeight: 1, letterSpacing: 0, cursorStyle: "block", foreground: "#d8e7f5", background: "#050b12", cursor: "#43d6a0", selection: "#264c6d" });5
const ANSI_NAMES = Object.freeze(["black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "brightBlack", "brightRed", "brightGreen", "brightYellow", "brightBlue", "brightMagenta", "brightCyan", "brightWhite"]);6
// What xterm.js uses when a theme sets no ANSI colors; the CH-J default profile keeps exactly this.7
const ANSI_DEFAULTS = Object.freeze(["#2e3436", "#cc0000", "#4e9a06", "#c4a000", "#3465a4", "#75507b", "#06989a", "#d3d7cf", "#555753", "#ef2929", "#8ae234", "#fce94f", "#729fcf", "#ad7fa8", "#34e2e2", "#eeeeec"]);8
// Fonts come from the user's computer; nothing is bundled and a missing one falls back to the default.9
const FONTS = Object.freeze(["JetBrains Mono", "Cascadia Mono", "Fira Code", "Hack", "Iosevka Term", "IBM Plex Mono", "Source Code Pro", "Menlo", "Consolas", "Courier New", "Victor Mono", "Monaspace Radon", "Monaspace Xenon", "Terminus", "Times New Roman"]);10
// Terminal columns assume equal character widths, so these can break tables and programs like htop.11
const PROPORTIONAL = Object.freeze(["Times New Roman", "Georgia", "Arial", "Helvetica", "Verdana", "Comic Sans MS", "Brush Script MT"]);12
const palette = (colors) => Object.fromEntries(ANSI_NAMES.map((name, index) => [name, colors[index]]));13
const colors = (foreground, background, cursor, selection, ansi) => ({ foreground, background, cursor, selection, ansi: palette(ansi) });14
const PROFILES = Object.freeze([15
{ id: "chj", key: "terminal.appearance.profile.default", appearance: {} },16
{ id: "retro-green", key: "terminal.appearance.profile.retroGreen", appearance: colors("#33ff33", "#001100", "#33ff33", "#0a4a0a", ["#001100", "#1f9f1f", "#33ff33", "#66ff66", "#2fbf2f", "#1f9f1f", "#66ff99", "#99ff99", "#0f5f0f", "#33cc33", "#66ff66", "#99ff99", "#66ff66", "#33cc33", "#99ffbb", "#ccffcc"]) },17
{ id: "retro-amber", key: "terminal.appearance.profile.retroAmber", appearance: colors("#ffb000", "#1a0f00", "#ffb000", "#5a3a00", ["#1a0f00", "#b36b00", "#ffb000", "#ffc533", "#cc8c00", "#b36b00", "#ffd066", "#ffe0a0", "#6b4400", "#cc8c00", "#ffc533", "#ffd966", "#ffc533", "#cc8c00", "#ffe08a", "#fff0cc"]) },18
{ id: "solarized-dark", name: "Solarized Dark", appearance: colors("#839496", "#002b36", "#93a1a1", "#073642", ["#073642", "#dc322f", "#859900", "#b58900", "#268bd2", "#d33682", "#2aa198", "#eee8d5", "#002b36", "#cb4b16", "#586e75", "#657b83", "#839496", "#6c71c4", "#93a1a1", "#fdf6e3"]) },19
{ id: "dracula", name: "Dracula", appearance: colors("#f8f8f2", "#282a36", "#f8f8f2", "#44475a", ["#21222c", "#ff5555", "#50fa7b", "#f1fa8c", "#bd93f9", "#ff79c6", "#8be9fd", "#f8f8f2", "#6272a4", "#ff6e6e", "#69ff94", "#ffffa5", "#d6acff", "#ff92df", "#a4ffff", "#ffffff"]) },20
{ id: "nord", name: "Nord", appearance: colors("#d8dee9", "#2e3440", "#d8dee9", "#434c5e", ["#3b4252", "#bf616a", "#a3be8c", "#ebcb8b", "#81a1c1", "#b48ead", "#88c0d0", "#e5e9f0", "#4c566a", "#bf616a", "#a3be8c", "#ebcb8b", "#81a1c1", "#b48ead", "#8fbcbb", "#eceff4"]) },21
{ id: "gruvbox-dark", name: "Gruvbox Dark", appearance: colors("#ebdbb2", "#282828", "#ebdbb2", "#504945", ["#282828", "#cc241d", "#98971a", "#d79921", "#458588", "#b16286", "#689d6a", "#a89984", "#928374", "#fb4934", "#b8bb26", "#fabd2f", "#83a598", "#d3869b", "#8ec07c", "#ebdbb2"]) },22
{ id: "light", key: "terminal.appearance.profile.light", appearance: colors("#24292e", "#ffffff", "#044289", "#c8e1ff", ["#24292e", "#d73a49", "#22863a", "#b08800", "#0366d6", "#6f42c1", "#1b7c83", "#6a737d", "#586069", "#cb2431", "#28a745", "#dbab09", "#2188ff", "#8a63d2", "#3192aa", "#d1d5da"]) },23
{ id: "high-contrast", key: "terminal.appearance.profile.highContrast", appearance: colors("#ffffff", "#000000", "#ffff00", "#0000c0", ["#000000", "#ff4d4d", "#00ff00", "#ffff00", "#5c9dff", "#ff66ff", "#00ffff", "#ffffff", "#808080", "#ff8080", "#66ff66", "#ffff66", "#99c2ff", "#ff99ff", "#66ffff", "#ffffff"]) }24
]);25
const fontStack = (name) => (name ? `"${String(name).replace(/["\\]/g, "")}", ${DEFAULT_FONT}` : DEFAULT_FONT);26
function terminalOptions(appearance) {27
const a = appearance || {};28
const theme = { background: a.background || DEFAULTS.background, foreground: a.foreground || DEFAULTS.foreground, cursor: a.cursor || DEFAULTS.cursor, selectionBackground: a.selection || DEFAULTS.selection };29
for (const name of ANSI_NAMES) if (a.ansi?.[name]) theme[name] = a.ansi[name];30
return {31
fontFamily: fontStack(a.fontFamily), fontSize: a.fontSize || DEFAULTS.fontSize, fontWeight: a.fontWeight || DEFAULTS.fontWeight,32
lineHeight: a.lineHeight || DEFAULTS.lineHeight, letterSpacing: a.letterSpacing || DEFAULTS.letterSpacing, cursorStyle: a.cursorStyle || DEFAULTS.cursorStyle, theme33
};34
}35
// A shared profile is plain JSON; Core validates its values again when it is saved.36
function exportProfile(name, appearance) {37
return JSON.stringify({ schema: "chj-terminal-profile/1", name, appearance }, null, 2);38
}39
function parseProfile(text) {40
const data = JSON.parse(text);41
const appearance = data?.appearance;42
if (data?.schema !== "chj-terminal-profile/1" || typeof data.name !== "string" || !data.name.trim() || typeof appearance !== "object" || appearance === null || Array.isArray(appearance)) throw new Error("profile");43
return { name: data.name.trim().slice(0, 40), appearance };44
}45
root.CHJ_TERMINAL_APPEARANCE = Object.freeze({ DEFAULTS, FONTS, PROPORTIONAL, ANSI_NAMES, ANSI_DEFAULTS, PROFILES, terminalOptions, exportProfile, parseProfile, isProportional: (name) => PROPORTIONAL.includes(name) });46
})(globalThis);SHA-256
3f9dcc10a1100557e85f1a7f07c7b8a4f50909a0e8075382ab132b3844b84bbaCH-J Proprietary Software License 1.14 · Lähde ilmoitetaan CH-J Proprietary Software License 1.14-koodilla. Sen saatavuus ei muuta lisenssiehtoja eikä myönnä lisäoikeuksia.
Arkisto SHA-256
ac8fe790f4ba60fc098f8c985fc2656cfcc6cdc21fb34b30e308a2b54e62258f