@setoelkahfi / svara / commits / 45010c9

an attempt at getting fonts but failing

mellbacon committed Dec 17, 2022 at 00:32 UTC 45010c9ea0ba2c55f524d086470556a0241831e4
8 files changed +139 -14
src-tauri/Cargo.lock
+77
@@ -42,6 +42,7 @@ checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6"
42 name = "app"
43 version = "0.1.0"
44 dependencies = [
45 + "font-loader",
46 "notify",
47 "serde",
48 "serde_json",
@@ -263,6 +264,15 @@ version = "1.0.0"
264 source = "registry+https://github.com/rust-lang/crates.io-index"
265 checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
266
267 +[[package]]
268 +name = "cmake"
269 +version = "0.1.49"
270 +source = "registry+https://github.com/rust-lang/crates.io-index"
271 +checksum = "db34956e100b30725f2eb215f90d4871051239535632f84fea3bc92722c66b7c"
272 +dependencies = [
273 + "cc",
274 +]
275 +
276 [[package]]
277 name = "cocoa"
278 version = "0.24.1"
@@ -357,6 +367,18 @@ dependencies = [
367 "libc",
368 ]
369
370 +[[package]]
371 +name = "core-text"
372 +version = "19.2.0"
373 +source = "registry+https://github.com/rust-lang/crates.io-index"
374 +checksum = "99d74ada66e07c1cefa18f8abfba765b486f250de2e4a999e5727fc0dd4b4a25"
375 +dependencies = [
376 + "core-foundation",
377 + "core-graphics",
378 + "foreign-types",
379 + "libc",
380 +]
381 +
382 [[package]]
383 name = "cpufeatures"
384 version = "0.2.5"
@@ -579,6 +601,16 @@ dependencies = [
601 "cfg-if 1.0.0",
602 ]
603
604 +[[package]]
605 +name = "expat-sys"
606 +version = "2.1.6"
607 +source = "registry+https://github.com/rust-lang/crates.io-index"
608 +checksum = "658f19728920138342f68408b7cf7644d90d4784353d8ebc32e7e8663dbe45fa"
609 +dependencies = [
610 + "cmake",
611 + "pkg-config",
612 +]
613 +
614 [[package]]
615 name = "fastrand"
616 version = "1.8.0"
@@ -626,6 +658,19 @@ version = "1.0.7"
658 source = "registry+https://github.com/rust-lang/crates.io-index"
659 checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
660
661 +[[package]]
662 +name = "font-loader"
663 +version = "0.11.0"
664 +source = "registry+https://github.com/rust-lang/crates.io-index"
665 +checksum = "c49d6b4c11dca1a1dd931a34a9f397e2da91abe3de4110505f3530a80e560b52"
666 +dependencies = [
667 + "core-foundation",
668 + "core-text",
669 + "libc",
670 + "servo-fontconfig",
671 + "winapi 0.3.9",
672 +]
673 +
674 [[package]]
675 name = "foreign-types"
676 version = "0.3.2"
@@ -650,6 +695,17 @@ dependencies = [
695 "percent-encoding",
696 ]
697
698 +[[package]]
699 +name = "freetype-sys"
700 +version = "0.13.1"
701 +source = "registry+https://github.com/rust-lang/crates.io-index"
702 +checksum = "a37d4011c0cc628dfa766fcc195454f4b068d7afdc2adfd28861191d866e731a"
703 +dependencies = [
704 + "cmake",
705 + "libc",
706 + "pkg-config",
707 +]
708 +
709 [[package]]
710 name = "fsevent"
711 version = "0.4.0"
@@ -2508,6 +2564,27 @@ dependencies = [
2564 "syn",
2565 ]
2566
2567 +[[package]]
2568 +name = "servo-fontconfig"
2569 +version = "0.5.1"
2570 +source = "registry+https://github.com/rust-lang/crates.io-index"
2571 +checksum = "c7e3e22fe5fd73d04ebf0daa049d3efe3eae55369ce38ab16d07ddd9ac5c217c"
2572 +dependencies = [
2573 + "libc",
2574 + "servo-fontconfig-sys",
2575 +]
2576 +
2577 +[[package]]
2578 +name = "servo-fontconfig-sys"
2579 +version = "5.1.0"
2580 +source = "registry+https://github.com/rust-lang/crates.io-index"
2581 +checksum = "e36b879db9892dfa40f95da1c38a835d41634b825fbd8c4c418093d53c24b388"
2582 +dependencies = [
2583 + "expat-sys",
2584 + "freetype-sys",
2585 + "pkg-config",
2586 +]
2587 +
2588 [[package]]
2589 name = "servo_arc"
2590 version = "0.1.1"
src-tauri/Cargo.toml
+1
@@ -18,6 +18,7 @@ serde_json = "1.0"
18 serde = { version = "1.0", features = ["derive"] }
19 tauri = { version = "1.1", features = ["api-all"] }
20 notify = "4.0.0"
21 +font-loader = "0.11.0"
22
23 [dev-dependencies]
24 windows = "0.32.0"
src-tauri/src/main.rs
+7 -1
@@ -5,6 +5,7 @@
5
6 use std::env;
7 use std::process::Command;
8 +use font_loader::system_fonts;
9 #[tauri::command]
10 fn open_in_explorer(path: &str) {
11 // FOR OTHER OS REFER - https://doc.rust-lang.org/std/env/consts/constant.OS.html
@@ -42,9 +43,14 @@ fn open_terminal(path: &str) {
43 }
44 }
45
46 +#[tauri::command]
47 +fn get_installed_fonts() -> Vec<String> {
48 + system_fonts::query_all()
49 +}
50 +
51 fn main() {
52 tauri::Builder::default()
47 - .invoke_handler(tauri::generate_handler![open_in_explorer, open_terminal])
53 + .invoke_handler(tauri::generate_handler![open_in_explorer, open_terminal, get_installed_fonts])
54 .run(tauri::generate_context!())
55 .expect("error while running tauri application");
56 }
src/App.svelte
+5 -2
@@ -7,10 +7,11 @@
7 import SidebarView from "./components/Sidebar/SidebarView.svelte";
8 import { showsidebarview, tool } from "./components/Sidebar/Sidebar";
9 import settings from "./config/nucleus-settings.json";
10 - import { executeWindowShortcut } from "./config/config";
10 + import { executeWindowShortcut, getInstalledFonts } from "./config/config";
11 import { Action, addNotification, NotifType } from "./components/Notifications/Notifications";
12 import { onMount } from "svelte";
13 import { shell } from "@tauri-apps/api";
14 + import { invoke } from "@tauri-apps/api/tauri";
15
16 const shortcuts = Object.entries(settings.shortcuts);
17 let keys = {};
@@ -26,7 +27,9 @@
27 return "";
28 }
29
29 - onMount(() => {
30 + onMount(async () => {
31 + let fonts: [] = await invoke("get_installed_fonts");
32 + getInstalledFonts(fonts);
33 addNotification(NotifType.Message, "Nucleus editor is in a work in progress state. Expect missing features and bugs", [new Action("GitHub link", () => {shell.open("https://github.com/mellobacon/Nucleus")}), new Action("Report issue/feature", () => {shell.open("https://github.com/mellobacon/Nucleus/issues/new/choose")})]);
34 })
35 </script>
src/components/Editor/CodeMirrorEditor.svelte
+8 -1
@@ -30,6 +30,7 @@
30 let editorView: EditorView;
31 export let content = "";
32 export let lang = new Compartment();
33 + export let theme = new Compartment();
34 let file_info;
35 let _ = null;
36
@@ -65,9 +66,15 @@
66 await tick();
67 file_linefeed.set(file_info.linefeed);
68 file_language.set(file_info.language);
69 + updateTheme();
70 editorView.focus();
71 getLineInfo();
72 }
73 + export function updateTheme() {
74 + editorView.dispatch({
75 + effects: theme.reconfigure(default_theme)
76 + })
77 + }
78 function getLineInfo() {
79 let linenumber = editorView.state.doc.lineAt(editorView.state.selection.main.head).number;
80 let colnumber = editorView.state.selection.ranges[0].head - editorView.state.doc.lineAt(editorView.state.selection.main.head).from
@@ -96,7 +103,7 @@
103 onMount(() => {
104 editorView = new EditorView({
105 state: EditorState.create({
99 - extensions: [basicSetup, default_theme, keymap.of([indentWithTab]), lang.of([])],
106 + extensions: [basicSetup, theme.of([default_theme]), keymap.of([indentWithTab]), lang.of([])],
107 doc: content
108 }),
109 parent: editorElement,
src/components/Editor/scripts/DefaultTheme.ts
+8 -9
@@ -2,6 +2,7 @@ import { EditorView } from "@codemirror/view";
2 import type { Extension } from "@codemirror/state";
3 import { HighlightStyle, syntaxHighlighting } from "@codemirror/language";
4 import { tags as t } from "@lezer/highlight";
5 +import { font } from "../../../config/config";
6
7 const bg = "#1c1c1c",
8 cl = "#282a2e",
@@ -14,11 +15,10 @@ const bg = "#1c1c1c",
15 aqua = "#8abeb7",
16 blue = "#81a2be",
17 purple = "#b294bb";
17 -
18 const defaultTheme = EditorView.theme(
19 {
20 "*": {
21 - fontFamily: '"Ubuntu Mono", monospace'
21 + fontFamily: `"${font}", monospace`
22 },
23
24 "&": {
@@ -107,13 +107,13 @@ const defaultTheme = EditorView.theme(
107
108 const defaultHighlightStyle = HighlightStyle.define([
109 {
110 - tag: t.keyword,
111 - color: purple
110 + tag: [t.keyword, t.typeName],
111 + color: "#7db7f3" // blue
112 },
113
114 {
115 - tag: [t.name, t.deleted, t.character, t.propertyName, t.macroName],
116 - color: red
115 + tag: [t.deleted, t.character, t.propertyName, t.macroName],
116 + color: "#cc8c66" // orange
117 },
118
119 {
@@ -133,7 +133,6 @@ const defaultHighlightStyle = HighlightStyle.define([
133
134 {
135 tag: [
136 - t.typeName,
136 t.className,
137 t.number,
138 t.changed,
@@ -142,7 +141,7 @@ const defaultHighlightStyle = HighlightStyle.define([
141 t.self,
142 t.namespace
143 ],
145 - color: orange
144 + color: purple
145 },
146
147 {
@@ -197,7 +196,7 @@ const defaultHighlightStyle = HighlightStyle.define([
196
197 {
198 tag: [t.processingInstruction, t.string, t.inserted],
200 - color: green
199 + color: "#df8cc9" // pink
200 },
201
202 {
src/components/Tabs/scripts/Tab.ts
+5
@@ -30,6 +30,11 @@ class Tab {
30 updateView(id) {
31 this.content.$set({ hidden: !(this.id === id) });
32 }
33 + refreshView(tab) {
34 + if (tab.isfile) {
35 + tab.content.updateTheme();
36 + }
37 + }
38 }
39
40 export async function addFileTab(path = "") {
src/config/config.ts
+28 -1
@@ -1,5 +1,11 @@
1 +import { writable } from "svelte/store";
2 import { openFile, openFolder, saveOpenFile, saveOpenFileAs } from "../components/Header/header_menus/FileMenu";
2 -import { addFileTab } from "../components/Tabs/scripts/Tab";
3 +import { addFileTab, tablist } from "../components/Tabs/scripts/Tab";
4 +
5 +export const systemfonts = writable([]);
6 +export const editorfont = writable("");
7 +export const windowtheme = writable("");
8 +export let font = "";
9
10 export function getShortcut({ primaryKey, secondaryKey, modifier }) {
11 if (modifier) {
@@ -52,4 +58,25 @@ export async function executeWindowShortcut(shortcut) {
58 export function getTime() {
59 let time = new Intl.DateTimeFormat('en-US', {dateStyle: "short", timeStyle: "long"}).format();
60 return time;
61 +}
62 +
63 +export function getInstalledFonts(fonts: []) {
64 + let fontlist = [];
65 + let id = 0;
66 + for (const f of fonts) {
67 + let font = {id: id, name: f};
68 + fontlist = [...fontlist, font];
69 + id++;
70 + }
71 + systemfonts.set(fontlist);
72 +}
73 +export function setFont(efont) {
74 + editorfont.set(efont);
75 + editorfont.subscribe(f => (font = f));
76 + for (const tab of tablist) {
77 + if (tab.active && tab.isfile) {
78 + tab.refreshView(tab);
79 + }
80 + }
81 +
82 }
\ No newline at end of file