mirror of
https://github.com/Eugeny/tabby.git
synced 2025-06-08 21:40:03 +00:00
51 lines
1.7 KiB
TypeScript
51 lines
1.7 KiB
TypeScript
import { Injectable } from '@angular/core'
|
|
import { TerminalColorSchemeProvider, ITerminalColorScheme } from 'terminus-terminal'
|
|
|
|
const schemeContents = require.context('../schemes/', true, /.*/)
|
|
|
|
@Injectable()
|
|
export class ColorSchemes extends TerminalColorSchemeProvider {
|
|
async getSchemes (): Promise<ITerminalColorScheme[]> {
|
|
const schemes: ITerminalColorScheme[] = []
|
|
|
|
schemeContents.keys().forEach(schemeFile => {
|
|
const lines = (schemeContents(schemeFile).default as string).split('\n')
|
|
|
|
// process #define variables
|
|
const variables: any = {}
|
|
lines
|
|
.filter(x => x.startsWith('#define'))
|
|
.map(x => x.split(' ').map(v => v.trim()))
|
|
.forEach(([ignore, variableName, variableValue]) => {
|
|
variables[variableName] = variableValue
|
|
})
|
|
|
|
const values: any = {}
|
|
lines
|
|
.filter(x => x.startsWith('*.'))
|
|
.map(x => x.substring(2))
|
|
.map(x => x.split(':').map(v => v.trim()))
|
|
.forEach(([key, value]) => {
|
|
values[key] = variables[value] ? variables[value] : value
|
|
})
|
|
|
|
const colors: string[] = []
|
|
let colorIndex = 0
|
|
while (values[`color${colorIndex}`]) {
|
|
colors.push(values[`color${colorIndex}`])
|
|
colorIndex++
|
|
}
|
|
|
|
schemes.push({
|
|
name: schemeFile.split('/')[1].trim(),
|
|
foreground: values.foreground,
|
|
background: values.background,
|
|
cursor: values.cursorColor,
|
|
colors,
|
|
})
|
|
})
|
|
|
|
return schemes
|
|
}
|
|
}
|