From 383d483c7c4c7098612e9e9d7f249e0d66ca2b79 Mon Sep 17 00:00:00 2001 From: Tamzin Selvi Date: Thu, 2 Jan 2025 14:27:47 -0800 Subject: [PATCH] Migrate old `themer-tmux` package into internal templates --- cli/src/template/all.ts | 4 ++ cli/src/template/tmux.ts | 89 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 cli/src/template/tmux.ts diff --git a/cli/src/template/all.ts b/cli/src/template/all.ts index 17536b41..17698cc4 100644 --- a/cli/src/template/all.ts +++ b/cli/src/template/all.ts @@ -21,6 +21,7 @@ import slack from './slack.js'; import sublimeText from './sublime-text.js'; import terminal from './terminal.js'; import terminator from './terminator.js'; +import tmux from './tmux.js'; import vimLightline from './vim-lightline.js'; import vim from './vim.js'; import visualStudio from './visual-studio.js'; @@ -62,6 +63,7 @@ const BUILT_IN_TEMPLATE_IDENTIFIERS = [ 'sublime-text', 'terminal', 'terminator', + 'tmux', 'vim', 'vim-lightline', 'visual-studio', @@ -134,6 +136,8 @@ export function resolveTemplate( return terminal; case 'terminator': return terminator; + case 'tmux': + return tmux; case 'vim': return vim; case 'vim-lightline': diff --git a/cli/src/template/tmux.ts b/cli/src/template/tmux.ts new file mode 100644 index 00000000..b0b3ac42 --- /dev/null +++ b/cli/src/template/tmux.ts @@ -0,0 +1,89 @@ +import type { Template } from './index.js'; +import { colorSetToVariants, FullVariant } from '../color-set/index.js'; +import { source } from 'common-tags'; + +type Layout = 'block' | 'default' | 'double'; + +const renderLayout = ( + layoutName: Layout, + colorSet: FullVariant, + index: number, +) => { + const layouts = { + block: (colors: FullVariant, i: number) => source` + # Powerline Themer Block - Tmux Theme + set -g status-interval 1 + set -g status-fg "${colors.shade3}" + set -g status-bg "${colors.shade1}" + set -g status-left "#[fg=${colors.shade0},bg=${ + colors[`accent${i * 2}` as keyof FullVariant] + },bold] #S #[fg=${colors[`accent${i * 2}` as keyof FullVariant]},bg=${ + colors.shade4 + },nobold]" + set -g status-right "#[fg=${colors.shade2},bg=${colors.shade1}]#[fg=${ + colors.shade4 + },bg=${colors.shade2}] %H:%M:%S" + `, + default: (colors: FullVariant, i: number) => source` + # Powerline Default - Tmux Theme + set -g status-interval 1 + set -g status-fg "${colors.shade3}" + set -g status-bg "${colors.shade1}" + set -g status-left "#[fg=${colors.shade0},bg=${ + colors[`accent${i * 2}` as keyof FullVariant] + },bold] #S #[fg=${colors[`accent${i * 2}` as keyof FullVariant]},bg=${ + colors.shade4 + },nobold]" + set -g status-right "#[fg=${colors.shade2},bg=${colors.shade1}]#[fg=${ + colors.shade4 + },bg=${colors.shade2}] %H:%M:%S" + `, + double: (colors: FullVariant, i: number) => source` + # Powerline Double - Tmux Theme + set -g status-interval 1 + set -g status-fg "${colors.shade3}" + set -g status-bg "${colors.shade1}" + set -g status-left "#[fg=${colors.shade0},bg=${ + colors[`accent${i * 2}` as keyof FullVariant] + },bold] #S #[fg=${colors[`accent${i * 2}` as keyof FullVariant]},bg=${ + colors.shade4 + },nobold]" + set -g status-right "#[fg=${colors.shade2},bg=${colors.shade1}]#[fg=${ + colors.shade4 + },bg=${colors.shade2}] %H:%M:%S" + `, + }; + + return layouts[layoutName](colorSet, index); +}; + +const template: Template = { + name: 'tmux', + render: async function* (colorSet) { + const variants = colorSetToVariants(colorSet); + for (const variant of variants) { + const { colors, name } = variant; + for (const layoutName of ['block', 'default', 'double'] as Layout[]) { + for (let i = 0; i < Math.floor(Object.keys(colors).length / 4); i++) { + yield { + path: `themer-tmux.${name}.${layoutName}.v${i}.tmuxtheme`, + content: renderLayout(layoutName, colors, i), + }; + } + } + } + }, + renderInstructions: (paths) => source` + Generated tmux themes: + + ${paths.map((path) => ` - ${path}`).join('\n')} + + Copy or symlink these files to your tmux configuration directory, and include them in your \`.tmux.conf\` like so: + + \`\`\` + source-file path/to/theme-file + \`\`\` + `, +}; + +export default template;