customizable font family

This commit is contained in:
Felix Roos 2023-02-22 20:28:22 +01:00
parent 8f6c1531fa
commit ff99dbcd22
11 changed files with 25 additions and 15 deletions

View File

@ -101,6 +101,7 @@ export default function CodeMirror({
theme, theme,
keybindings, keybindings,
fontSize = 18, fontSize = 18,
fontFamily = 'monospace',
options, options,
editorDidMount, editorDidMount,
}) { }) {
@ -135,7 +136,7 @@ export default function CodeMirror({
return staticExtensions; return staticExtensions;
}, [keybindings]); }, [keybindings]);
return ( return (
<div style={{ fontSize }} className="w-full"> <div style={{ fontSize, fontFamily }} className="w-full">
<_CodeMirror <_CodeMirror
value={value} value={value}
theme={theme || strudelTheme} theme={theme || strudelTheme}

View File

@ -12,7 +12,6 @@ export const settings = {
gutterBackground: 'transparent', gutterBackground: 'transparent',
gutterForeground: '#0f380f', gutterForeground: '#0f380f',
light: true, light: true,
fontFamily: 'PressStart, monospace',
}; };
export default createTheme({ export default createTheme({
theme: 'light', theme: 'light',

View File

@ -7,10 +7,9 @@ export const settings = {
selection: '#ffffff20', selection: '#ffffff20',
selectionMatch: '#036dd626', selectionMatch: '#036dd626',
lineHighlight: '#ffffff10', lineHighlight: '#ffffff10',
lineBackground: '#00000050',
gutterBackground: 'transparent', gutterBackground: 'transparent',
gutterForeground: '#8a919966', gutterForeground: '#8a919966',
fontFamily: 'BigBlueTerminal, monospace',
//fontFamily: 'x3270, monospace',
}; };
export default createTheme({ export default createTheme({
theme: 'dark', theme: 'dark',

View File

@ -12,7 +12,6 @@ export const settings = {
gutterBackground: 'transparent', gutterBackground: 'transparent',
// gutterForeground: '#8a919966', // gutterForeground: '#8a919966',
gutterForeground: '#8a919966', gutterForeground: '#8a919966',
fontFamily: 'BigBlueTerminal, monospace',
}; };
export default createTheme({ export default createTheme({

View File

@ -9,8 +9,6 @@ export const settings = {
lineHighlight: '#ffffff10', lineHighlight: '#ffffff10',
gutterBackground: 'transparent', gutterBackground: 'transparent',
gutterForeground: '#8a919966', gutterForeground: '#8a919966',
//fontFamily: 'BigBlueTerminal, monospace',
fontFamily: 'x3270, monospace',
}; };
export default createTheme({ export default createTheme({
theme: 'dark', theme: 'dark',

View File

@ -11,7 +11,6 @@ export const settings = {
gutterBackground: 'transparent', gutterBackground: 'transparent',
gutterForeground: 'black', gutterForeground: 'black',
light: true, light: true,
fontFamily: 'BigBlueTerminal, monospace',
}; };
export default createTheme({ export default createTheme({
theme: 'light', theme: 'light',

View File

@ -279,18 +279,31 @@ function FormItem({ label, children }) {
} }
const themeOptions = Object.fromEntries(Object.keys(themes).map((k) => [k, k])); const themeOptions = Object.fromEntries(Object.keys(themes).map((k) => [k, k]));
const fontFamilyOptions = {
monospace: 'monospace',
BigBlueTerminal: 'BigBlueTerminal',
x3270: 'x3270',
PressStart: 'PressStart2P',
};
function SettingsTab() { function SettingsTab() {
const { state, update, reset } = useStore(); const { state, update, reset } = useStore();
const { theme, keybindings, fontSize } = state; const { theme, keybindings, fontSize, fontFamily } = state;
return ( return (
<div className="text-foreground p-4 space-y-4"> <div className="text-foreground p-4 space-y-4">
<FormItem label="Theme">
<SelectInput
options={themeOptions}
value={theme}
onChange={(theme) => update((current) => ({ ...current, theme }))}
/>
</FormItem>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4"> <div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<FormItem label="Theme"> <FormItem label="Font Family">
<SelectInput <SelectInput
options={themeOptions} options={fontFamilyOptions}
value={theme} value={fontFamily}
onChange={(theme) => update((current) => ({ ...current, theme }))} onChange={(fontFamily) => update((current) => ({ ...current, fontFamily }))}
/> />
</FormItem> </FormItem>
<FormItem label="Font Size"> <FormItem label="Font Size">

View File

@ -17,6 +17,7 @@
#code .cm-scroller { #code .cm-scroller {
padding-bottom: 50vh; padding-bottom: 50vh;
font-family: inherit;
} }
#code .cm-line > * { #code .cm-line > * {
background: var(--lineBackground); background: var(--lineBackground);

View File

@ -121,7 +121,7 @@ export function Repl({ embedded = false }) {
const { theme, themeSettings } = useTheme(); const { theme, themeSettings } = useTheme();
const { const {
state: { keybindings, fontSize }, state: { keybindings, fontSize, fontFamily },
} = useStore(); } = useStore();
const { code, setCode, scheduler, evaluate, activateCode, isDirty, activeCode, pattern, started, stop, error } = const { code, setCode, scheduler, evaluate, activateCode, isDirty, activeCode, pattern, started, stop, error } =
@ -283,6 +283,7 @@ export function Repl({ embedded = false }) {
value={code} value={code}
keybindings={keybindings} keybindings={keybindings}
fontSize={fontSize} fontSize={fontSize}
fontFamily={fontFamily}
onChange={handleChangeCode} onChange={handleChangeCode}
onViewChanged={setView} onViewChanged={setView}
onSelectionChange={handleSelectionChange} onSelectionChange={handleSelectionChange}

View File

@ -410,7 +410,6 @@ export const settings = {
gutterBackground: '#1e1e1e', gutterBackground: '#1e1e1e',
gutterForeground: '#838383', gutterForeground: '#838383',
gutterActiveForeground: '#fff', gutterActiveForeground: '#fff',
fontFamily: 'Menlo, Monaco, Consolas, "Andale Mono", "Ubuntu Mono", "Courier New", monospace',
}, },
xcodeLight: { xcodeLight: {
light: true, light: true,

View File

@ -2,6 +2,7 @@ export const storeKey = 'strudel-settings';
const defaults = { const defaults = {
keybindings: 'codemirror', keybindings: 'codemirror',
theme: 'strudelTheme', theme: 'strudelTheme',
fontFamily: 'monospace',
fontSize: 18, fontSize: 18,
}; };