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

Migrate themer-tmux package into internal templates #162

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;