Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alacritty 0.14.0 - import has been deprecated; use general.import instead #267

Open
killeik opened this issue Oct 30, 2024 · 1 comment
Open
Labels
bug Something isn't working

Comments

@killeik
Copy link

killeik commented Oct 30, 2024

Describe the bug

After alacritty update to 0.14.0 import=[] is deprecated, alacritty-themes need to set [general] and then import=[] in config file

To Reproduce

Steps to reproduce the behavior:

  1. Installation
  • I run it via npx alacritty-themes
  1. Run alacritty-themes
  • I just type "npx alacritty-themes" then click up/down keys, any theme and enter
  1. See error
[WARN] Config warning: import has been deprecated; use general.import instead 
Use 'alacritty migrate' to automatically resolve it 

Expected behavior

alacritty-themes successfully adds to the config file:

import = [
  "/usr/lib/node_modules/alacritty-themes/themes/3024.dark.toml"
]

But it should add:

[general]
import = [
  "/usr/lib/node_modules/alacritty-themes/themes/3024.dark.toml"
]

Operating System:

  • Arch

Add your alacritty.yml content

it's toml btw:

import = [
  "/usr/lib/node_modules/alacritty-themes/themes/Gruvbox-Light.toml"
]

[window]
decorations = "none"
opacity = 0.9
dynamic_padding = true

[env]
TERM = "xterm-256color"

[font]
size = 13

Screenshots

image

@killeik killeik added the bug Something isn't working label Oct 30, 2024
@greninj21
Copy link

open the index.js located in " /usr/lib/node_modules/alacritty-themes/"

and replace these code given below in the functions getCurrentTheme and updateThemeWithFile

const imports = parsedAlacrittyConfig.import || [];

with

const imports = parsedAlacrittyConfig.general?.import || [];

and replace the conditional statement in updateThemeWithFile function with

if (currentThemeIndex === undefined) { 
    parsedAlacrittyConfig.general = parsedAlacrittyConfig.general || {};
    parsedAlacrittyConfig.general.import = [themePath];
} else {
    parsedAlacrittyConfig.general.import[currentThemeIndex] = themePath;
}

So your two functions should be like this (Might as well copy and paste this code lol)

function getCurrentTheme(themesFolder) {
  if (!alacrittyConfigPath()) {
    console.log(
      'No Alacritty configuration file found\nRun: `alacritty-themes -C` to create one'
    );
    exit(1);
  }
  const alacrittyConfig = fs.readFileSync(alacrittyConfigPath(), 'utf8');
  const parsedAlacrittyConfig = TOML.parse(alacrittyConfig);

  const imports = parsedAlacrittyConfig.general?.import || [];

  // We'll consider the first theme import as the current theme
  for (let i = 0; i < imports.length; i++) {
    const relative = path.relative(themesFolder, imports[i]);
    if (relative && !relative.startsWith('..') && !path.isAbsolute(relative)) {
      return path.parse(imports[i]).name;
    }
  }

  return 'default';
}

function updateThemeWithFile(themePath, themesPath, tomlPath, preview = false) {
  const alacrittyConfig = fs.readFileSync(tomlPath, 'utf8');
  const parsedAlacrittyConfig = TOML.parse(alacrittyConfig);

  const imports = parsedAlacrittyConfig.general?.import || [];
  let currentThemeIndex = undefined;

  for (let i = 0; i < imports.length; i++) {
    const relative = path.relative(themesPath, imports[i]);
    if (relative && !relative.startsWith('..') && !path.isAbsolute(relative)) {
      currentThemeIndex = i;
      break;
    }
  }

  if (currentThemeIndex === undefined) {
    parsedAlacrittyConfig.general = parsedAlacrittyConfig.general || {};
    parsedAlacrittyConfig.general.import = [themePath];
  } else {
    parsedAlacrittyConfig.general.import[currentThemeIndex] = themePath;
  }

  const newContent = TOML.stringify(parsedAlacrittyConfig);

  const themeName = path.parse(themePath).name;

  return fsPromises
    .writeFile(tomlPath, newContent, 'utf8')
    .then(() => {
      if (!preview) {
        console.log(`The theme "${themeName}" has been applied successfully!`);
      }
    })
    .catch((err) => {
      if (err) throw err;
    });
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants