winwal icon indicating copy to clipboard operation
winwal copied to clipboard

Add WezTerm support for automatic color scheme updates

Open Copilot opened this issue 10 months ago • 3 comments

This PR adds comprehensive WezTerm support to winwal, allowing automatic color scheme updates for the cross-platform WezTerm terminal emulator.

Changes Made

🎨 Template

  • Added templates/wezterm.lua with proper Lua color scheme structure
  • Includes all standard pywal color variables ({foreground}, {background}, {color0-15})
  • Supports WezTerm-specific properties like cursor colors and selection colors

🔧 Functionality

  • Created common/WezTermFunctions.ps1 with Update-WalWezTerm function
  • Cross-platform config detection for both Windows and Unix-like systems
  • Automatic discovery of WezTerm configs in standard locations:
    • Windows: %APPDATA%\wezterm\wezterm.lua, %USERPROFILE%\.config\wezterm\wezterm.lua, %USERPROFILE%\.wezterm.lua
    • Unix: $HOME/.config/wezterm/wezterm.lua, $HOME/.wezterm.lua

🔗 Integration

  • Integrated WezTerm updates into the main Update-WalThemeInternal.ps1 workflow
  • WezTerm configs are now automatically updated alongside Windows Terminal
  • Added function export to winwal.psm1 module

🛡️ Safety Features

  • Automatic backup of existing configs before modification (.bak files)
  • Graceful handling of missing or invalid config files
  • Smart merging that preserves existing configuration while injecting wal colors
  • Error handling with automatic restoration from backups if updates fail

📚 Documentation

  • Updated README.md to mention WezTerm support
  • Added usage notes about automatic config detection

Usage

WezTerm support works automatically with existing winwal commands:

# Updates all supported terminals including WezTerm
Update-WalTheme

# Works with different backends too
Update-WalTheme -Backend haishoku

# Updates theme from a specific image
Update-WalTheme -Image .\path\to\image.jpg

The implementation intelligently detects existing WezTerm configurations and merges the wal color scheme while preserving other settings like fonts, keybindings, and custom configurations.

Fixes #23.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot avatar Jun 19 '25 18:06 Copilot

@copilot I think we need to look into:

  1. What does the wezterm theme look like.
  2. Add a template for the wezterm theme in the templates directory to have a wal-wezterm template
  3. After running Update-WalTheme, check for if a wezterm config directory exists
  4. Copy the wal-wezterm result to the config directory
  5. Update wezterm's theme in the config to use wal-wezterm or leave it alone if it already does so it since it'll detect the changes to the theme file

scaryrawr avatar Jun 19 '25 19:06 scaryrawr

@copilot I think we need to look into:

  1. What does the wezterm theme look like. ...

I've implemented the WezTerm support following your suggested approach:

  1. Researched WezTerm theme format - WezTerm uses TOML color scheme files in a colors/ subdirectory
  2. Created wal-wezterm.toml template - Follows WezTerm's color scheme structure with all pywal variables
  3. After Update-WalTheme, check for WezTerm config directory - Cross-platform detection for Windows and Unix paths
  4. Copy wal-wezterm result to config directory - Places the generated theme as colors/wal.toml
  5. Update wezterm config to use wal theme - Sets config.color_scheme = "wal" or leaves existing reference alone

The implementation now follows the same pattern as Windows Terminal: generating a separate theme file and referencing it by name, rather than injecting the color scheme inline. This is much cleaner and matches WezTerm's expected workflow.

Commit: 055c8f5

Copilot avatar Jun 19 '25 19:06 Copilot

@scaryrawr Unfortunately I hit an unexpected error while processing your comment. I've automatically reported this to GitHub.

You can ask me to try again later by mentioning me in a new comment.

If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: 5fb8098e-94f7-493b-8057-b81ec7ae6deb

Sorry for the inconvenience!

Copilot avatar Jun 19 '25 19:06 Copilot