PsySH’s theme system allows you to customize colors, prompts, and output formatting to match your preferences and terminal environment.
Built-in Themes
PsySH includes three built-in themes:
The default theme with clean, minimal prompts and full color support. Prompts:
Main: >
Buffer (multi-line): .
Replay: -
Return value: =
Output: Standard spacing with full syntax highlightingSame colors as modern, but with more compact output formatting. Prompts: Same as modernOutput: Condensed spacing, less whitespace between elementsTraditional REPL appearance with classic >>> prompts. Prompts:
Main: >>>
Buffer: ...
Replay: -->
Return value: =>
Output: Compact formatting like Python’s REPL
Custom Themes
Create custom themes by passing an array of configuration options:
return [
'theme' => [
// Prompts
'prompt' => '>> ' ,
'bufferPrompt' => '.. ' ,
'replayPrompt' => '-> ' ,
'returnValue' => '=> ' ,
// Output formatting
'compact' => true ,
// Color fallback (when 'gray' is unavailable)
'grayFallback' => 'blue' ,
// Custom styles (see Color Customization below)
'styles' => [
'error' => [ 'white' , 'red' , [ 'bold' ]],
'warning' => [ 'black' , 'yellow' ],
],
],
];
Theme Options
Use compact output formatting 'theme' => [ 'compact' => true ],
Main input prompt string 'theme' => [ 'prompt' => '>>> ' ],
Prompt for multi-line input continuation 'theme' => [ 'bufferPrompt' => '... ' ],
Prompt when replaying history 'theme' => [ 'replayPrompt' => '--> ' ],
Marker displayed before return values 'theme' => [ 'returnValue' => '=> ' ],
Fallback color when ‘gray’ is not available in the terminal 'theme' => [ 'grayFallback' => 'cyan' ],
styles
array
default: "(see Color Customization)"
Custom color styles for syntax highlighting and output 'theme' => [
'styles' => [
'error' => [ 'white' , 'red' , [ 'bold' ]],
],
],
Color Customization
Customize colors by defining styles in your theme. Each style is an array with three elements:
[ foreground , background , options ]
Any element can be null or omitted:
'styles' => [
'error' => [ 'white' , 'red' , [ 'bold' ]], // Full specification
'warning' => [ 'black' , 'yellow' ], // No options
'strong' => [ null , null , [ 'bold' ]], // Only options
'info' => [ 'cyan' ], // Only foreground
],
Available Styles
You can customize any of these styles:
General Output Styles
Info/Warning/Error
Text Emphasis
'styles' => [
'info' => [ 'white' , 'blue' , [ 'bold' ]],
'warning' => [ 'black' , 'yellow' ],
'error' => [ 'white' , 'red' , [ 'bold' ]],
'whisper' => [ 'gray' ],
],
PHP Keyword Styles
'styles' => [
'public' => [ null , null , [ 'bold' ]],
'protected' => [ 'yellow' ],
'private' => [ 'red' ],
'global' => [ 'cyan' , null , [ 'bold' ]],
'const' => [ 'cyan' ],
'class' => [ 'blue' , null , [ 'underscore' ]],
'function' => [ null ],
'virtual' => [ 'magenta' ],
'default' => [ null ],
],
Type and Value Styles
'styles' => [
'number' => [ 'magenta' ],
'integer' => [ 'magenta' ],
'float' => [ 'yellow' ],
'string' => [ 'green' ],
'bool' => [ 'cyan' ],
'keyword' => [ 'yellow' ],
'comment' => [ 'blue' ],
'code_comment' => [ 'gray' ],
'object' => [ 'blue' ],
'resource' => [ 'yellow' ],
'inline_html' => [ 'cyan' ],
],
Available Colors
Foreground and background colors:
black
red
green
yellow
blue
magenta
cyan
white
gray (may fall back to grayFallback on some terminals)
null (default/transparent)
Available Options
Text formatting options:
bold
underscore
blink
reverse
conceal
Example Custom Themes
Dark Theme
return [
'theme' => [
'prompt' => '⚡ ' ,
'bufferPrompt' => ' ' ,
'returnValue' => '↪ ' ,
'styles' => [
'error' => [ 'red' , null , [ 'bold' ]],
'warning' => [ 'yellow' , null , [ 'bold' ]],
'info' => [ 'cyan' ],
'string' => [ 'green' ],
'number' => [ 'magenta' ],
'bool' => [ 'yellow' ],
'class' => [ 'cyan' , null , [ 'bold' ]],
'function' => [ 'yellow' ],
'comment' => [ 'gray' ],
],
],
];
Minimal Theme
return [
'theme' => [
'compact' => true ,
'prompt' => '→ ' ,
'bufferPrompt' => ' ' ,
'returnValue' => ' ' ,
'styles' => [
// Use mostly default terminal colors
'error' => [ 'red' ],
'warning' => [ 'yellow' ],
'string' => [ 'green' ],
'number' => [ 'blue' ],
],
],
];
High Contrast Theme
return [
'theme' => [
'styles' => [
'error' => [ 'white' , 'red' , [ 'bold' ]],
'warning' => [ 'black' , 'yellow' , [ 'bold' ]],
'info' => [ 'white' , 'blue' , [ 'bold' ]],
'string' => [ 'green' , null , [ 'bold' ]],
'number' => [ 'magenta' , null , [ 'bold' ]],
'bool' => [ 'cyan' , null , [ 'bold' ]],
'class' => [ 'white' , null , [ 'bold' , 'underscore' ]],
'public' => [ 'green' , null , [ 'bold' ]],
'protected' => [ 'yellow' , null , [ 'bold' ]],
'private' => [ 'red' , null , [ 'bold' ]],
],
],
];
Setting Themes via Command Line
You can switch to the compact theme using the --compact flag:
For other themes or custom configurations, use a config file.
Programmatic Theme Configuration
You can also create and configure themes programmatically:
use Psy\Output\ Theme ;
// Create a theme instance
$theme = new Theme ( 'modern' );
$theme -> setCompact ( true );
$theme -> setPrompt ( '>> ' );
// Apply to config
$config -> setTheme ( $theme );
// Or create from array
$config -> setTheme ([
'compact' => true ,
'prompt' => '>> ' ,
]);
Color Mode Control
Control when colors are used:
return [
'colorMode' => 'auto' , // Auto-detect (default)
'colorMode' => 'forced' , // Always use colors
'colorMode' => 'disabled' , // Never use colors
];
Or via command line:
psysh --color # Force colors
psysh --no-color # Disable colors
Tips
Test Your Theme : Colors may appear different depending on your terminal emulator’s color scheme. Test your custom theme in your actual terminal environment.
Use Unicode Carefully : Unicode characters in prompts (like ⚡ or →) require useUnicode => true (the default) and a terminal with Unicode support.
Gray Color : The gray color isn’t available on all terminals. Use the grayFallback option to specify an alternative color when gray is unavailable.