<commit_before>import path from 'path'
import fs from 'fs'
import hexterm from 'hexterm'
import { loadYml, isHexColor } from './util'
import { crack } from './crack'
import {
  Palette,
  SyntaxRule,
  StatusStyle,
  TerminalStyle,
  Mustaches,
  StatusBrand
} from './common'

export function loadPalette (filepath: string): Palette {
  const { content } = loadYml(filepath)

  const palette = {
    filepath,
    name: path.basename(filepath, '.yml'),
    colors: {}
  } as Palette

  Object.keys(content).forEach(name => {
    const hexcolor = content[name].trim()
    if (!isHexColor(hexcolor)) crack('Wrong color', { filepath, name })
    palette.colors[name] = {
      hex: hexcolor.startsWith('#') ? hexcolor : '#' + hexcolor,
      xterm: hexterm(hexcolor)
    }
  })
  return palette
}

export function loadSyntax (filepath: string): SyntaxRule[] {
  const { content } = loadYml(filepath)
  return Object.keys(content)
    .map(name => ({
      filepath,
      name,
      rule: content[name].trim()
    }))
    .filter(rule => rule.rule)
}

const statusParts = {
  airline: [
    'normal1',
    'normal2',
    'normal3',
    'insert1',
    'insert2',
    'insert3',
    'replace1',
    'replace2',
    'replace3',
    'visual1',
    'visual2',
    'visual3',
    'inactive1',
    'inactive2',
    'inactive3'
  ],
  lightline: [
    'normal1',
    'normal2',
    'normal3',
    'insert1',
    'insert2',
    'insert3',
    'replace1',
    'replace2',
    'replace3',
    'visual1',
    'visual2',
    'visual3',
    'inactive1',
    'inactive2',
    'inactive3'
  ]
} // , ctrlp

export function loadStatus (filepath: string, brand: StatusBrand): StatusStyle {
  const { content } = loadYml(filepath)

  const statusStyle = {
    name: path.basename(filepath, '.yml'),
    filepath: filepath,
    syntax: {}
  } as StatusStyle

  Object.keys(content).forEach(name => {
    const txt = content[name].trim()
    statusStyle.syntax[name] = txt.split(/\s+/)
  })

  statusParts[brand].forEach(part => {
    const block = statusStyle.syntax[part]
    if (!block) crack('Missing block in status', { filepath, block: part })
    if (!block[0]) crack('Missing foreground in status block', { filepath, block: part })
    if (!block[1]) crack('Missing background in status block', { filepath, block: part })
  })
  return statusStyle
}

export function loadTerminal (folderPath: string): TerminalStyle {
  const filepath = path.resolve(folderPath, 'addons', 'nvim-term.yml')
  const { content } = loadYml(filepath)

  const terminalStyle = {
    filepath: filepath,
    styles: {}
  } as TerminalStyle

  Object.keys(content).forEach(prop => {
    const colorname = content[prop].trim()
    if (!colorname) return
    terminalStyle.styles[prop] = colorname
  })

  return terminalStyle
}

export function loadMustaches (): Mustaches {
  const folder = path.resolve(__dirname, '../templates/mustaches')<commit_msg>Fix: Airline fields in Lightline validator<commit_after>import path from 'path'
import fs from 'fs'
import hexterm from 'hexterm'
import { loadYml, isHexColor } from './util'
import { crack } from './crack'
import {
  Palette,
  SyntaxRule,
  StatusStyle,
  TerminalStyle,
  Mustaches,
  StatusBrand
} from './common'

export function loadPalette (filepath: string): Palette {
  const { content } = loadYml(filepath)

  const palette = {
    filepath,
    name: path.basename(filepath, '.yml'),
    colors: {}
  } as Palette

  Object.keys(content).forEach(name => {
    const hexcolor = content[name].trim()
    if (!isHexColor(hexcolor)) crack('Wrong color', { filepath, name })
    palette.colors[name] = {
      hex: hexcolor.startsWith('#') ? hexcolor : '#' + hexcolor,
      xterm: hexterm(hexcolor)
    }
  })
  return palette
}

export function loadSyntax (filepath: string): SyntaxRule[] {
  const { content } = loadYml(filepath)
  return Object.keys(content)
    .map(name => ({
      filepath,
      name,
      rule: content[name].trim()
    }))
    .filter(rule => rule.rule)
}

const statusParts = {
  airline: [
    'normal1',
    'normal2',
    'normal3',
    'insert1',
    'insert2',
    'insert3',
    'replace1',
    'replace2',
    'replace3',
    'visual1',
    'visual2',
    'visual3',
    'inactive1',
    'inactive2',
    'inactive3'
  ],
  lightline: [
    'normal1',
    'normal2',
    'normal3',
    'normal4',
    'normal5',
    'normalError',
    'normalWarning',
    'inactive1',
    'inactive2',
    'inactive3',
    'inactive4',
    'inactive5',
    'insert1',
    'insert2',
    'insert3',
    'insert4',
    'insert5',
    'replace1',
    'replace2',
    'replace3',
    'replace4',
    'replace5',
    'visual1',
    'visual2',
    'visual3',
    'visual4',
    'visual5',
    'tablineLeft',
    'tablineSelected',
    'tablineMiddle',
    'tablineRight'
  ]
} // , ctrlp

export function loadStatus (filepath: string, brand: StatusBrand): StatusStyle {
  const { content } = loadYml(filepath)

  const statusStyle = {
    name: path.basename(filepath, '.yml'),
    filepath: filepath,
    syntax: {}
  } as StatusStyle

  Object.keys(content).forEach(name => {
    const txt = content[name].trim()
    statusStyle.syntax[name] = txt.split(/\s+/)
  })

  statusParts[brand].forEach(part => {
    const block = statusStyle.syntax[part]
    if (!block) crack('Missing block in status', { filepath, block: part })
    if (!block[0]) {
      crack('Missing foreground in status block', { filepath, block: part })
    }
    if (!block[1]) {
      crack('Missing background in status block', { filepath, block: part })
    }
  })
  return statusStyle
}

export function loadTerminal (folderPath: string): TerminalStyle {
  const filepath = path.resolve(folderPath, 'addons', 'nvim-term.yml')
  const { content } = loadYml(filepath)

  const terminalStyle = {
    filepath: filepath,
    styles: {}
  } as TerminalStyle

  Object.keys(content).forEach(prop => {
    const colorname = content[prop].trim()
    if (!colorname) return
    terminalStyle.styles[prop] = colorname
  })

  return terminalStyle
}

export function loadMustaches (): Mustaches {
  const folder = path.resolve(__dirname, '../templates/mustaches')
{'fraction_non_alphanumeric': 0.14849074975657253, 'fraction_numerical': 0.012009087958455048, 'mean_word_length': 3.186820652173913, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5150762', 'n_tokens_mistral': 2087, 'n_tokens_neox': 2037, 'n_words': 464}