Skip to content

Commit

Permalink
Migrate old themer-tmux package into internal templates
Browse files Browse the repository at this point in the history
  • Loading branch information
Tamzin Selvi committed Jan 2, 2025
1 parent bb86533 commit 383d483
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cli/src/template/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -62,6 +63,7 @@ const BUILT_IN_TEMPLATE_IDENTIFIERS = [
'sublime-text',
'terminal',
'terminator',
'tmux',
'vim',
'vim-lightline',
'visual-studio',
Expand Down Expand Up @@ -134,6 +136,8 @@ export function resolveTemplate(
return terminal;
case 'terminator':
return terminator;
case 'tmux':
return tmux;
case 'vim':
return vim;
case 'vim-lightline':
Expand Down
89 changes: 89 additions & 0 deletions cli/src/template/tmux.ts
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 383d483

Please sign in to comment.