You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using ThinkPy in Jupyter notebooks with color output mode (--style color), the ANSI color codes appear as raw escape sequences in copied text, making it difficult to share or document output.
Current Behavior
When copying output from a ThinkPy cell with color formatting:
[94m[1mPROGRAM[0m: Test float operations
[94m[1mTASK[0m: Executing FloatMath
Expected Behavior
Clean, formatted text without ANSI escape sequences:
PROGRAM: Test float operations
TASK: Executing FloatMath
Observe ANSI escape sequences in copied text
�[94m�[1mPROGRAM�[0m: Test float operations
�[94m�[1mTASK�[0m: Executing FloatMath
�[93m�[1mSTEP�[0m: Executing Basic arithmetic
�[91m�[1mVARIABLE�[0m: Assigned 10.5 to a
�[91m�[1mVARIABLE�[0m: Assigned -0.1 to b
�[91m�[1mVARIABLE�[0m: Assigned -105.0 to result
�[92m�[1mOUTPUT�[0m: -105
Proposed Solutions
Primary Solution: HTML-based Rendering
Convert ANSI color sequences to HTML/CSS for Jupyter display:
Create a new output formatter that:
Intercepts the colored output
Converts ANSI sequences to HTML/CSS classes
Returns rich HTML output for Jupyter
defformat_output_html(text):
# Convert ANSI to HTML classesansi_to_html= {
'\033[94m': '<span class="thinkpy-task">',
'\033[93m': '<span class="thinkpy-step">',
'\033[0m': '</span>'# ... other mappings
}
# Replace ANSI sequences with HTMLforansi, htmlinansi_to_html.items():
text=text.replace(ansi, html)
returnf'<div class="thinkpy-output">{text}</div>'
Alternative Solutions
Dual Output Mode
Keep ANSI colors for terminal use
Add --format html option for Jupyter
Let users choose based on context
Rich Library Integration
Utilize the rich library's HTML export
Provides consistent formatting across platforms
Built-in ANSI-to-HTML conversion
Copy-Paste Enhancement
Add custom clipboard handler
Strip ANSI sequences on copy
Preserve visual formatting in notebook
ANSI Preservation Option
For users who need ANSI colors (e.g., for terminal tools):
defpreserve_ansi_output(text):
fromIPython.displayimportHTML# Encode ANSI sequences for displayhtml_safe=text.replace('\033', '\\033')
returnHTML(f'<pre>{html_safe}</pre>')
Problem Description
When using ThinkPy in Jupyter notebooks with color output mode (
--style color
), the ANSI color codes appear as raw escape sequences in copied text, making it difficult to share or document output.Current Behavior
When copying output from a ThinkPy cell with color formatting:
Expected Behavior
Clean, formatted text without ANSI escape sequences:
Reproduction Steps
The output
Observe ANSI escape sequences in copied text
�[94m�[1mPROGRAM�[0m: Test float operations
�[94m�[1mTASK�[0m: Executing FloatMath
�[93m�[1mSTEP�[0m: Executing Basic arithmetic
�[91m�[1mVARIABLE�[0m: Assigned 10.5 to a
�[91m�[1mVARIABLE�[0m: Assigned -0.1 to b
�[91m�[1mVARIABLE�[0m: Assigned -105.0 to result
�[92m�[1mOUTPUT�[0m: -105
Proposed Solutions
Primary Solution: HTML-based Rendering
Convert ANSI color sequences to HTML/CSS for Jupyter display:
Alternative Solutions
Dual Output Mode
--format html
option for JupyterRich Library Integration
rich
library's HTML exportCopy-Paste Enhancement
ANSI Preservation Option
For users who need ANSI colors (e.g., for terminal tools):
Implementation Impact
Additional Notes
/label ~"Master" ~bug ~needs-design
/cc @project-maintainers
The text was updated successfully, but these errors were encountered: