<commit_before># -*- coding: utf-8 -*-

DEFAULT_MODE_KEY = None
ATTR_BOLD = 1
ATTR_ITALIC = 2
ATTR_UNDERLINE = 4


class Colorscheme(object):
	def __init__(self, colorscheme):
		'''Initialize a colorscheme.'''
		self.colors = {}
		self.modes_groups = {DEFAULT_MODE_KEY: {}}

		# Create a dict of color tuples with both a cterm and hex value
		for color_name, color in colorscheme['colors'].items():
			try:
				self.colors[color_name] = (color[0], int(color[1], 16))
			except TypeError:
				self.colors[color_name] = (color, cterm_to_hex[color])

		# Create highlighting groups for all modes
		for group_name, group_props in colorscheme['groups'].items():
			group_attr_flag = self._get_attr_flag(group_props.get('attr', []))
			self.modes_groups[DEFAULT_MODE_KEY][group_name] = {
				'fg': self.colors[group_props['fg']],
				'bg': self.colors[group_props['bg']],
				'attr': group_attr_flag,
				}

			# Create mode-specific highlighting for this group
			for mode, translations in colorscheme.get('mode_translations', {}).items():
				if not mode in self.modes_groups:
					self.modes_groups[mode] = {}
				if group_name in translations.get('groups', {}):
					# Override entire group if present in the translations group dict
					self.modes_groups[mode][group_name] = {
						'fg': self.colors[translations['groups'][group_name]['fg']],
						'bg': self.colors[translations['groups'][group_name]['bg']],
						'attr': self._get_attr_flag(translations['groups'][group_name].get('attr', [])),
						}
				else:
					# Fallback to color translations from the translations colors dict
					self.modes_groups[mode][group_name] = {
						'fg': self.colors[translations.get('colors', {}).get(group_props['fg'], group_props['fg'])],
						'bg': self.colors[translations.get('colors', {}).get(group_props['bg'], group_props['bg'])],
						'attr': group_attr_flag,
						}

	def get_group_highlighting(self, group):
		'''Return highlighting information for all modes of a highlighting group.'''
		group_highlighting = {}
		for mode, mode_group in self.modes_groups.items():
			try:
				group_highlighting[mode] = mode_group[group]
			except TypeError:
				for try_group in group:
					if try_group in self.modes_groups[mode]:
						group_highlighting[mode] = mode_group[try_group]
						break
			finally:
				if mode not in group_highlighting:
					raise KeyError('Highlighting groups not found in colorscheme: {0}'.format(group))<commit_msg>Rename colorscheme variable to colorscheme_config<commit_after># -*- coding: utf-8 -*-

DEFAULT_MODE_KEY = None
ATTR_BOLD = 1
ATTR_ITALIC = 2
ATTR_UNDERLINE = 4


class Colorscheme(object):
	def __init__(self, colorscheme_config):
		'''Initialize a colorscheme.'''
		self.colors = {}
		self.modes_groups = {DEFAULT_MODE_KEY: {}}

		# Create a dict of color tuples with both a cterm and hex value
		for color_name, color in colorscheme_config['colors'].items():
			try:
				self.colors[color_name] = (color[0], int(color[1], 16))
			except TypeError:
				self.colors[color_name] = (color, cterm_to_hex[color])

		# Create highlighting groups for all modes
		for group_name, group_props in colorscheme_config['groups'].items():
			group_attr_flag = self._get_attr_flag(group_props.get('attr', []))
			self.modes_groups[DEFAULT_MODE_KEY][group_name] = {
				'fg': self.colors[group_props['fg']],
				'bg': self.colors[group_props['bg']],
				'attr': group_attr_flag,
				}

			# Create mode-specific highlighting for this group
			for mode, translations in colorscheme_config.get('mode_translations', {}).items():
				if not mode in self.modes_groups:
					self.modes_groups[mode] = {}
				if group_name in translations.get('groups', {}):
					# Override entire group if present in the translations group dict
					self.modes_groups[mode][group_name] = {
						'fg': self.colors[translations['groups'][group_name]['fg']],
						'bg': self.colors[translations['groups'][group_name]['bg']],
						'attr': self._get_attr_flag(translations['groups'][group_name].get('attr', [])),
						}
				else:
					# Fallback to color translations from the translations colors dict
					self.modes_groups[mode][group_name] = {
						'fg': self.colors[translations.get('colors', {}).get(group_props['fg'], group_props['fg'])],
						'bg': self.colors[translations.get('colors', {}).get(group_props['bg'], group_props['bg'])],
						'attr': group_attr_flag,
						}

	def get_group_highlighting(self, group):
		'''Return highlighting information for all modes of a highlighting group.'''
		group_highlighting = {}
		for mode, mode_group in self.modes_groups.items():
			try:
				group_highlighting[mode] = mode_group[group]
			except TypeError:
				for try_group in group:
					if try_group in self.modes_groups[mode]:
						group_highlighting[mode] = mode_group[try_group]
						break
			finally:
				if mode not in group_highlighting:
					raise KeyError('Highlighting groups not found in colorscheme: {0}'.format(group))
{'fraction_non_alphanumeric': 0.1396761133603239, 'fraction_numerical': 0.0036437246963562753, 'mean_word_length': 4.42371020856202, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '888884', 'n_tokens_mistral': 1910, 'n_tokens_neox': 1563, 'n_words': 361}