diff options
author | Profpatsch <mail@profpatsch.de> | 2024-12-13T20·18+0100 |
---|---|---|
committer | Profpatsch <mail@profpatsch.de> | 2024-12-13T20·28+0000 |
commit | c283116c2e3393e59d533026091208cd39bc9176 (patch) | |
tree | 0f71dd6e64c944a6229444a67b4a5d4b74faffd1 /users/Profpatsch | |
parent | 1ec787a4170169558e4ed9c190f91724929ec5ce (diff) |
feat(users/Profpatsch/alacritty): add dbus theme change r/9005
For trying out a bunch of themes in quick succession. Also note down a few of the cooler themes. Change-Id: I0da80cc0945dba03d3592f28f4c34df4b5969e82 Reviewed-on: https://cl.tvl.fyi/c/depot/+/12893 Tested-by: BuildkiteCI Reviewed-by: Profpatsch <mail@profpatsch.de>
Diffstat (limited to 'users/Profpatsch')
-rw-r--r-- | users/Profpatsch/alacritty-change-color-scheme/alacritty-change-color-scheme.js | 52 | ||||
-rw-r--r-- | users/Profpatsch/alacritty-change-color-scheme/cool-themes | 8 |
2 files changed, 56 insertions, 4 deletions
diff --git a/users/Profpatsch/alacritty-change-color-scheme/alacritty-change-color-scheme.js b/users/Profpatsch/alacritty-change-color-scheme/alacritty-change-color-scheme.js index ab12a25b13ff..3fa274ff3908 100644 --- a/users/Profpatsch/alacritty-change-color-scheme/alacritty-change-color-scheme.js +++ b/users/Profpatsch/alacritty-change-color-scheme/alacritty-change-color-scheme.js @@ -20,7 +20,7 @@ const { setTimeout } = require('node:timers/promises'); const { promisify } = require('util'); const { pseudoRandomBytes } = require('crypto'); const { execFile } = require('node:child_process'); -const { readdir } = require('fs/promises'); +const { readdir, realpath, access } = require('fs/promises'); // NB: this code is like 80% copilot generated, and seriously missing error handling. // It might break at any time, but for now it seems to work lol. @@ -33,8 +33,8 @@ let darkThemeName = process.argv[3] ?? 'alacritty_0_12'; let lightThemeName = process.argv[4] ?? 'dayfox'; assert(themeDir, 'Theme directory is required'); -const darkTheme = getThemePathSync(darkThemeName); -const lightTheme = getThemePathSync(lightThemeName); +let darkTheme = getThemePathSync(darkThemeName); +let lightTheme = getThemePathSync(lightThemeName); console.log(`Dark theme: ${darkTheme}`); console.log(`Light theme: ${lightTheme}`); @@ -291,8 +291,10 @@ if (!process.env.XDG_CONFIG_HOME) { process.env.XDG_CONFIG_HOME = process.env.HOME + '/.config'; } -/** +/** get the path of the theme config file synchronously + * * @param {string} theme + * @returns {string} * */ function getThemePathSync(theme) { const path = `${themeDir}/${theme}.toml`; @@ -301,6 +303,22 @@ function getThemePathSync(theme) { return absolutePath; } +/** get the path of the theme config file + * + * @param {string} theme + * @returns {Promise<string | null>} null if the theme file does not exist + * */ +async function getThemePath(theme) { + const path = `${themeDir}/${theme}.toml`; + try { + const absolutePath = await realpath(path); + await access(absolutePath); + return absolutePath; + } catch (err) { + return null; + } +} + /** write new color scheme * * @param {'prefer-dark' | 'prefer-light'} cs @@ -407,6 +425,10 @@ async function exportColorSchemeDbusInterface() { name: 'de.profpatsch.alacritty.ColorScheme', methods: { SetColorScheme: ['s', ''], + // first argument: 'dark' | 'light' + // second argument: the theme name (one of the themes in the theme directory) + // will only be applied during the run-time of this program, and reset on restart + SetColorSchemeTheme: ['ss', ''], }, }; @@ -416,6 +438,28 @@ async function exportColorSchemeDbusInterface() { console.log(`SetColorScheme called with ${cs}`); writeAlacrittyColorConfigIfDifferent(cs); }, + SetColorSchemeTheme: async function ( + /** @type {string} */ cs, + /** @type {string} */ theme, + ) { + console.log(`SetColorSchemeTheme called with ${cs} and theme ${theme}`); + if (cs !== 'dark' && cs !== 'light') { + console.warn(`Invalid color scheme ${cs}`); + return; + } + const themePath = await getThemePath(theme); + if (themePath === null) { + return; + } + if (cs === 'dark') { + darkTheme = themePath; + } + if (cs === 'light') { + lightTheme = themePath; + } + console.log(`Setting color scheme ${cs} with theme ${themePath}`); + writeAlacrittyColorConfig(cs === 'dark' ? 'prefer-dark' : 'prefer-light'); + }, }; try { diff --git a/users/Profpatsch/alacritty-change-color-scheme/cool-themes b/users/Profpatsch/alacritty-change-color-scheme/cool-themes new file mode 100644 index 000000000000..ea8bfd46d7ec --- /dev/null +++ b/users/Profpatsch/alacritty-change-color-scheme/cool-themes @@ -0,0 +1,8 @@ +ayu_mirage +catppuccin +gruvbox_dark +inferno +monokai_pro + + +night_owlish_light |