Skip to content

feat: enable color support in marimo notebooks #3651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Upcoming

### Changed

- Enabled color support in marimo notebooks. https://github.com/Textualize/rich/pull/3651

## [13.9.4] - 2024-11-01

Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The following people have contributed to the development of Rich:
<!-- Add your name below, sort alphabetically by surname. Link to GitHub profile / your home page. -->

- [Patrick Arminio](https://github.com/patrick91)
- [banteg](https://github.com/banteg)
- [Gregory Beauregard](https://github.com/GBeauregard/pyffstream)
- [Artur Borecki](https://github.com/pufereq)
- [Pedro Aaron](https://github.com/paaaron)
Expand Down
12 changes: 11 additions & 1 deletion rich/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,16 @@ def _is_jupyter() -> bool: # pragma: no cover
return False # Other type (?)


def _is_marimo() -> bool: # pragma: no cover
"""Check if we're running in a marimo notebook."""
try:
import marimo

return marimo.running_in_notebook() is True
except (ImportError, AttributeError):
return False


COLOR_SYSTEMS = {
"standard": ColorSystem.STANDARD,
"256": ColorSystem.EIGHT_BIT,
Expand Down Expand Up @@ -790,7 +800,7 @@ def _theme_stack(self) -> ThemeStack:

def _detect_color_system(self) -> Optional[ColorSystem]:
"""Detect color system from env vars."""
if self.is_jupyter:
if self.is_jupyter or _is_marimo():
return ColorSystem.TRUECOLOR
if not self.is_terminal or self.is_dumb_terminal:
return None
Expand Down