Skip to content
Open
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
13 changes: 11 additions & 2 deletions nbcommands/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from colorama import Fore, Style

from pygments import highlight
from pygments.lexers import PythonLexer
from pygments.lexers import MarkdownLexer, PythonLexer, TextLexer
from pygments.formatters import TerminalTrueColorFormatter


Expand All @@ -12,6 +12,7 @@ def display(cells):

for cell in cells:
prompt = ""

# TODO: show more cell types
if cell["cell_type"] == "code":
execution_count = cell.get("execution_count")
Expand All @@ -22,7 +23,15 @@ def display(cells):
+ "In [{}]: ".format(execution_count)
+ Style.RESET_ALL
)
code = highlight(cell.source, PythonLexer(), TerminalTrueColorFormatter())
lexer = PythonLexer()

elif cell["cell_type"] == "markdown":
lexer = MarkdownLexer()

else:
lexer = TextLexer()

code = highlight(cell.source, lexer, TerminalTrueColorFormatter())
output.append(prompt + code)

return output