mirror of
https://github.com/danbulant/dots-hyprland
synced 2026-05-24 12:22:09 +00:00
ai: code blocks: update colorscheme along with other stuff
This commit is contained in:
parent
cbfb8f6ddb
commit
ac59f23ca4
5 changed files with 41 additions and 32 deletions
|
|
@ -1,8 +1,28 @@
|
||||||
import GLib from 'gi://GLib';
|
const { Gio, GLib } = imports.gi;
|
||||||
|
import GtkSource from "gi://GtkSource?version=3.0";
|
||||||
import App from 'resource:///com/github/Aylur/ags/app.js'
|
import App from 'resource:///com/github/Aylur/ags/app.js'
|
||||||
import * as Utils from 'resource:///com/github/Aylur/ags/utils.js'
|
import * as Utils from 'resource:///com/github/Aylur/ags/utils.js'
|
||||||
import { darkMode } from './modules/.miscutils/system.js';
|
import { darkMode } from './modules/.miscutils/system.js';
|
||||||
|
|
||||||
|
const CUSTOM_SOURCEVIEW_SCHEME_PATH = `${App.configDir}/assets/themes/sourceviewtheme${darkMode.value ? '' : '-light'}.xml`;
|
||||||
|
|
||||||
export const COMPILED_STYLE_DIR = `${GLib.get_user_cache_dir()}/ags/user/generated`
|
export const COMPILED_STYLE_DIR = `${GLib.get_user_cache_dir()}/ags/user/generated`
|
||||||
|
|
||||||
|
function loadSourceViewColorScheme(filePath) {
|
||||||
|
// Read the XML file content
|
||||||
|
const file = Gio.File.new_for_path(filePath);
|
||||||
|
const [success, contents] = file.load_contents(null);
|
||||||
|
|
||||||
|
if (!success) {
|
||||||
|
logError('Failed to load the XML file.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse the XML content and set the Style Scheme
|
||||||
|
const schemeManager = GtkSource.StyleSchemeManager.get_default();
|
||||||
|
schemeManager.append_search_path(file.get_parent().get_path());
|
||||||
|
}
|
||||||
|
|
||||||
globalThis['handleStyles'] = (resetMusic) => {
|
globalThis['handleStyles'] = (resetMusic) => {
|
||||||
// Reset
|
// Reset
|
||||||
Utils.exec(`mkdir -p "${GLib.get_user_state_dir()}/ags/scss"`);
|
Utils.exec(`mkdir -p "${GLib.get_user_state_dir()}/ags/scss"`);
|
||||||
|
|
@ -13,7 +33,8 @@ globalThis['handleStyles'] = (resetMusic) => {
|
||||||
// Generate overrides
|
// Generate overrides
|
||||||
let lightdark = darkMode.value ? "dark" : "light";
|
let lightdark = darkMode.value ? "dark" : "light";
|
||||||
Utils.writeFileSync(
|
Utils.writeFileSync(
|
||||||
`@mixin symbolic-icon {
|
`
|
||||||
|
@mixin symbolic-icon {
|
||||||
-gtk-icon-theme: '${userOptions.icons.symbolicIconTheme[lightdark]}';
|
-gtk-icon-theme: '${userOptions.icons.symbolicIconTheme[lightdark]}';
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
|
|
@ -26,5 +47,7 @@ globalThis['handleStyles'] = (resetMusic) => {
|
||||||
App.applyCss(`${COMPILED_STYLE_DIR}/style.css`);
|
App.applyCss(`${COMPILED_STYLE_DIR}/style.css`);
|
||||||
console.log('[LOG] Styles loaded')
|
console.log('[LOG] Styles loaded')
|
||||||
}
|
}
|
||||||
applyStyle().catch(print);
|
applyStyle().then(() => {
|
||||||
|
loadSourceViewColorScheme(CUSTOM_SOURCEVIEW_SCHEME_PATH);
|
||||||
|
}).catch(print);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -92,6 +92,9 @@ export const ConfigToggle = ({
|
||||||
...rest,
|
...rest,
|
||||||
});
|
});
|
||||||
const wholeThing = Box({
|
const wholeThing = Box({
|
||||||
|
attribute: {
|
||||||
|
'enabled': enabled,
|
||||||
|
},
|
||||||
className: 'configtoggle-box spacing-h-5',
|
className: 'configtoggle-box spacing-h-5',
|
||||||
children: [
|
children: [
|
||||||
interactionWrapper,
|
interactionWrapper,
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ const ColorSchemeSettings = () => Widget.Box({
|
||||||
darkMode.value = !!newValue;
|
darkMode.value = !!newValue;
|
||||||
},
|
},
|
||||||
extraSetup: (self) => self.hook(darkMode, (self) => {
|
extraSetup: (self) => self.hook(darkMode, (self) => {
|
||||||
self.enabled.value = darkMode.value;
|
self.attribute.enabled.value = darkMode.value;
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
ConfigToggle({
|
ConfigToggle({
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ import App from 'resource:///com/github/Aylur/ags/app.js';
|
||||||
import * as Utils from 'resource:///com/github/Aylur/ags/utils.js';
|
import * as Utils from 'resource:///com/github/Aylur/ags/utils.js';
|
||||||
const { execAsync, exec } = Utils;
|
const { execAsync, exec } = Utils;
|
||||||
import Todo from "../../services/todo.js";
|
import Todo from "../../services/todo.js";
|
||||||
import { darkMode } from '../.miscutils/system.js';
|
|
||||||
|
|
||||||
export function hasUnterminatedBackslash(inputString) {
|
export function hasUnterminatedBackslash(inputString) {
|
||||||
// Use a regular expression to match a trailing odd number of backslashes
|
// Use a regular expression to match a trailing odd number of backslashes
|
||||||
|
|
@ -35,10 +34,10 @@ export function launchCustomCommand(command) {
|
||||||
execAsync([`bash`, `-c`, `${App.configDir}/scripts/color_generation/switchcolor.sh "${args[1]}"`, `&`]).catch(print);
|
execAsync([`bash`, `-c`, `${App.configDir}/scripts/color_generation/switchcolor.sh "${args[1]}"`, `&`]).catch(print);
|
||||||
}
|
}
|
||||||
else if (args[0] == '>light') { // Light mode
|
else if (args[0] == '>light') { // Light mode
|
||||||
darkMode.value = false;
|
darkMode.setValue(false).catch(print);
|
||||||
}
|
}
|
||||||
else if (args[0] == '>dark') { // Dark mode
|
else if (args[0] == '>dark') { // Dark mode
|
||||||
darkMode.value = true;
|
darkMode.setValue(true).catch(print);
|
||||||
}
|
}
|
||||||
else if (args[0] == '>badapple') { // Black and white
|
else if (args[0] == '>badapple') { // Black and white
|
||||||
execAsync([`bash`, `-c`, `mkdir -p ${GLib.get_user_state_dir()}/ags/user && sed -i "3s/.*/monochrome/" ${GLib.get_user_state_dir()}/ags/user/colormode.txt`])
|
execAsync([`bash`, `-c`, `mkdir -p ${GLib.get_user_state_dir()}/ags/user && sed -i "3s/.*/monochrome/" ${GLib.get_user_state_dir()}/ags/user/colormode.txt`])
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
const { Gdk, Gio, GLib, Gtk } = imports.gi;
|
const { GLib, Gtk } = imports.gi;
|
||||||
import GtkSource from "gi://GtkSource?version=3.0";
|
import GtkSource from "gi://GtkSource?version=3.0";
|
||||||
import App from 'resource:///com/github/Aylur/ags/app.js';
|
import App from 'resource:///com/github/Aylur/ags/app.js';
|
||||||
import Widget from 'resource:///com/github/Aylur/ags/widget.js';
|
import Widget from 'resource:///com/github/Aylur/ags/widget.js';
|
||||||
|
|
@ -10,30 +10,8 @@ import md2pango from '../../.miscutils/md2pango.js';
|
||||||
import { darkMode } from "../../.miscutils/system.js";
|
import { darkMode } from "../../.miscutils/system.js";
|
||||||
|
|
||||||
const LATEX_DIR = `${GLib.get_user_cache_dir()}/ags/media/latex`;
|
const LATEX_DIR = `${GLib.get_user_cache_dir()}/ags/media/latex`;
|
||||||
const CUSTOM_SOURCEVIEW_SCHEME_PATH = `${App.configDir}/assets/themes/sourceviewtheme${darkMode.value ? '' : '-light'}.xml`;
|
|
||||||
const CUSTOM_SCHEME_ID = `custom${darkMode.value ? '' : '-light'}`;
|
|
||||||
const USERNAME = GLib.get_user_name();
|
const USERNAME = GLib.get_user_name();
|
||||||
|
|
||||||
/////////////////////// Custom source view colorscheme /////////////////////////
|
|
||||||
|
|
||||||
function loadCustomColorScheme(filePath) {
|
|
||||||
// Read the XML file content
|
|
||||||
const file = Gio.File.new_for_path(filePath);
|
|
||||||
const [success, contents] = file.load_contents(null);
|
|
||||||
|
|
||||||
if (!success) {
|
|
||||||
logError('Failed to load the XML file.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse the XML content and set the Style Scheme
|
|
||||||
const schemeManager = GtkSource.StyleSchemeManager.get_default();
|
|
||||||
schemeManager.append_search_path(file.get_parent().get_path());
|
|
||||||
}
|
|
||||||
loadCustomColorScheme(CUSTOM_SOURCEVIEW_SCHEME_PATH);
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
function substituteLang(str) {
|
function substituteLang(str) {
|
||||||
const subs = [
|
const subs = [
|
||||||
{ from: 'javascript', to: 'js' },
|
{ from: 'javascript', to: 'js' },
|
||||||
|
|
@ -62,7 +40,7 @@ const HighlightedCode = (content, lang) => {
|
||||||
buffer.set_language(displayLang);
|
buffer.set_language(displayLang);
|
||||||
}
|
}
|
||||||
const schemeManager = GtkSource.StyleSchemeManager.get_default();
|
const schemeManager = GtkSource.StyleSchemeManager.get_default();
|
||||||
buffer.set_style_scheme(schemeManager.get_scheme(CUSTOM_SCHEME_ID));
|
buffer.set_style_scheme(schemeManager.get_scheme(`custom${darkMode.value ? '' : '-light'}`));
|
||||||
buffer.set_text(content, -1);
|
buffer.set_text(content, -1);
|
||||||
return sourceView;
|
return sourceView;
|
||||||
}
|
}
|
||||||
|
|
@ -204,7 +182,13 @@ const CodeBlock = (content = '', lang = 'txt') => {
|
||||||
child: sourceView,
|
child: sourceView,
|
||||||
})],
|
})],
|
||||||
})
|
})
|
||||||
]
|
],
|
||||||
|
setup: (self) => self.hook(darkMode, (self) => {
|
||||||
|
const schemeManager = GtkSource.StyleSchemeManager.get_default();
|
||||||
|
Utils.timeout(1000, () => { // Wait for the theme to be loaded
|
||||||
|
sourceView.buffer.set_style_scheme(schemeManager.get_scheme(`custom${darkMode.value ? '' : '-light'}`));
|
||||||
|
});
|
||||||
|
}, "changed"),
|
||||||
})
|
})
|
||||||
|
|
||||||
// const schemeIds = styleManager.get_scheme_ids();
|
// const schemeIds = styleManager.get_scheme_ids();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue