or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

command-line.mdcustom-components.mdfilter-system.mdformatter-management.mdhigh-level-api.mdindex.mdlexer-management.mdstyle-management.md

style-management.mddocs/

0

# Style Management

1

2

Functions for working with color schemes and visual styles that define how different token types are rendered in formatted output.

3

4

## Capabilities

5

6

### Style Discovery

7

8

Get a style class by name.

9

10

```python { .api }

11

def get_style_by_name(name: str):

12

"""

13

Get style class by name.

14

15

Parameters:

16

- name: Style name (e.g., 'default', 'github', 'monokai', 'vim')

17

18

Returns:

19

Style class that can be used with formatters

20

21

Raises:

22

ClassNotFound: If no style with that name is found

23

"""

24

```

25

26

Usage example:

27

28

```python

29

from pygments.styles import get_style_by_name

30

from pygments.formatters import HtmlFormatter

31

32

# Get specific styles

33

default_style = get_style_by_name('default')

34

github_style = get_style_by_name('github')

35

monokai_style = get_style_by_name('monokai')

36

37

# Use with formatter

38

formatter = HtmlFormatter(style=github_style)

39

# Or by name

40

formatter = HtmlFormatter(style='github')

41

```

42

43

### Style Enumeration

44

45

List all available styles.

46

47

```python { .api }

48

def get_all_styles() -> Iterator[str]:

49

"""

50

Return generator of all available style names.

51

52

Yields:

53

Style name strings for both built-in and plugin styles

54

"""

55

```

56

57

Usage example:

58

59

```python

60

from pygments.styles import get_all_styles

61

62

# List all available styles

63

print("Available styles:")

64

for style_name in get_all_styles():

65

print(f" {style_name}")

66

67

# Find dark themes

68

dark_styles = [name for name in get_all_styles()

69

if 'dark' in name.lower() or name in ['monokai', 'vim', 'native']]

70

```

71

72

## Built-in Styles

73

74

Pygments includes many built-in styles:

75

76

### Light Themes

77

- `default` - Default Pygments style

78

- `emacs` - Emacs editor style

79

- `friendly` - Friendly light style

80

- `friendly_grayscale` - Grayscale friendly style

81

- `colorful` - Colorful light style

82

- `autumn` - Autumn colors

83

- `murphy` - Murphy style

84

- `manni` - Manni style

85

- `material` - Material design inspired

86

- `perldoc` - Perl documentation style

87

- `pastie` - Pastie web service style

88

- `borland` - Borland IDE style

89

- `trac` - Trac style

90

- `igor` - Igor Pro style

91

- `vs` - Visual Studio style

92

- `xcode` - Xcode style

93

94

### Dark Themes

95

- `monokai` - Popular dark theme

96

- `vim` - Vim editor dark theme

97

- `native` - Native terminal style

98

- `fruity` - Fruity dark colors

99

- `github-dark` - GitHub dark theme

100

- `dracula` - Dracula theme

101

- `gruvbox-dark` - Gruvbox dark variant

102

- `nord` - Nord color palette

103

- `onedark` - One Dark theme

104

- `zenburn` - Zenburn style

105

106

### Specialized Themes

107

- `bw` - Black and white (no colors)

108

- `rrt` - Radically Reduced Theme

109

- `solarized-dark` / `solarized-light` - Solarized color scheme

110

- `paraiso-dark` / `paraiso-light` - Paraiso themes

111

- `rainbow_dash` - Colorful rainbow theme

112

113

## Style Usage

114

115

```python

116

from pygments import highlight

117

from pygments.lexers import PythonLexer

118

from pygments.formatters import HtmlFormatter

119

from pygments.styles import get_style_by_name

120

121

code = '''

122

def factorial(n):

123

if n <= 1:

124

return 1

125

return n * factorial(n - 1)

126

'''

127

128

lexer = PythonLexer()

129

130

# Different styles produce different visual output

131

styles_to_try = ['default', 'github', 'monokai', 'vim', 'colorful']

132

133

for style_name in styles_to_try:

134

formatter = HtmlFormatter(style=style_name, cssclass=f'highlight-{style_name}')

135

result = highlight(code, lexer, formatter)

136

print(f"=== {style_name.upper()} STYLE ===")

137

print(result[:200] + "...")

138

```

139

140

## Style Properties

141

142

Each style defines colors and formatting for token types:

143

144

```python

145

from pygments.styles import get_style_by_name

146

from pygments.token import Keyword, String, Comment

147

148

style = get_style_by_name('monokai')

149

150

# Access style definitions (internal API)

151

print(f"Keyword color: {style.style_for_token(Keyword)}")

152

print(f"String color: {style.style_for_token(String)}")

153

print(f"Comment color: {style.style_for_token(Comment)}")

154

```

155

156

## Custom Styles

157

158

You can create custom styles by subclassing the Style class:

159

160

```python

161

from pygments.style import Style

162

from pygments.token import *

163

164

class MyCustomStyle(Style):

165

name = 'mycustom'

166

167

styles = {

168

Comment: 'italic #75715e',

169

Keyword: 'bold #66d9ef',

170

Name: '#f8f8f2',

171

Name.Attribute: '#a6e22e',

172

Name.Class: 'bold #a6e22e',

173

Name.Function: '#a6e22e',

174

Number: '#ae81ff',

175

Operator: '#f92672',

176

String: '#e6db74',

177

Generic.Deleted: '#f92672',

178

Generic.Inserted: '#a6e22e',

179

}

180

181

# Use custom style

182

from pygments.formatters import HtmlFormatter

183

formatter = HtmlFormatter(style=MyCustomStyle)

184

```

185

186

## Style Format

187

188

Style definitions use this format:

189

- Colors: hex colors (`#ff0000`), ANSI colors (`ansiblue`), or color names

190

- Modifiers: `bold`, `italic`, `underline`, `nobold`, `noitalic`, `noinherit`

191

- Background: `bg:#ffffff` for background colors

192

193

Examples:

194

- `'bold #ff0000'` - Bold red text

195

- `'italic #008000'` - Italic green text

196

- `'bg:#ffff00 #000000'` - Black text on yellow background

197

- `'underline #0000ff'` - Underlined blue text

198

- `'noinherit'` - Don't inherit parent styles

199

200

## Error Handling

201

202

- **ClassNotFound**: No style found with the specified name

203

- **ImportError**: Issues loading custom style modules