Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/account/terminal-settings.tsx
6037 views
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { Button } from "antd";
7
import { useIntl } from "react-intl";
8
9
import { Panel } from "@cocalc/frontend/antd-bootstrap";
10
import { useTypedRedux } from "@cocalc/frontend/app-framework";
11
import {
12
Icon,
13
LabeledRow,
14
Loading,
15
SelectorInput,
16
} from "@cocalc/frontend/components";
17
import {
18
example,
19
theme_desc,
20
} from "@cocalc/frontend/frame-editors/terminal-editor/theme-data";
21
import { labels } from "@cocalc/frontend/i18n";
22
import { set_account_table } from "./util";
23
24
declare global {
25
interface Window {
26
Terminal: any;
27
}
28
}
29
30
export function TerminalSettings() {
31
const intl = useIntl();
32
33
const terminal = useTypedRedux("account", "terminal");
34
const color_scheme = terminal?.get("color_scheme") || "default";
35
36
if (terminal == null) {
37
return <Loading />;
38
}
39
40
const label = intl.formatMessage({
41
id: "account.terminal-settings.label-row.label",
42
defaultMessage: "Terminal color scheme",
43
});
44
45
return (
46
<Panel
47
size="small"
48
header={
49
<>
50
<Icon name="terminal" /> Terminal Settings
51
</>
52
}
53
>
54
<LabeledRow label={label}>
55
<Button
56
disabled={color_scheme === "default"}
57
style={{ float: "right" }}
58
onClick={() => {
59
set_account_table({ terminal: { color_scheme: "default" } });
60
}}
61
>
62
{intl.formatMessage(labels.reset)}
63
</Button>
64
<SelectorInput
65
style={{ width: "250px" }}
66
selected={color_scheme}
67
options={theme_desc}
68
on_change={(color_scheme) =>
69
set_account_table({ terminal: { color_scheme } })
70
}
71
showSearch={true}
72
/>
73
</LabeledRow>
74
<TerminalPreview color_scheme={color_scheme} />
75
</Panel>
76
);
77
}
78
79
function TerminalPreview({ color_scheme }: { color_scheme: string }) {
80
const html = example(color_scheme || "default");
81
return (
82
<div
83
style={{
84
marginTop: "10px",
85
border: "1px solid #ccc",
86
borderRadius: "4px",
87
overflow: "hidden",
88
}}
89
dangerouslySetInnerHTML={{ __html: html }}
90
/>
91
);
92
}
93
94