mirror of
https://github.com/TheR1D/shell_gpt.git
synced 2026-07-03 14:10:18 +02:00
Make markdown vertical_overflow configurable (#779)
This commit is contained in:
@@ -391,9 +391,32 @@ SHOW_FUNCTIONS_OUTPUT=false
|
||||
OPENAI_USE_FUNCTIONS=true
|
||||
# Enforce LiteLLM usage (for local LLMs).
|
||||
USE_LITELLM=false
|
||||
# Control how markdown live rendering handles overflow when output exceeds terminal height.
|
||||
# Possible values: ellipsis, visible, crop
|
||||
MARKDOWN_LIVE_VERTICAL_OVERFLOW=ellipsis
|
||||
```
|
||||
Possible options for `DEFAULT_COLOR`: black, red, green, yellow, blue, magenta, cyan, white, bright_black, bright_red, bright_green, bright_yellow, bright_blue, bright_magenta, bright_cyan, bright_white.
|
||||
Possible options for `CODE_THEME`: https://pygments.org/styles/
|
||||
Possible options for `MARKDOWN_LIVE_VERTICAL_OVERFLOW`: `ellipsis`, `visible`, `crop`.
|
||||
|
||||
### Configuration Examples
|
||||
|
||||
**Default behavior (ellipsis):**
|
||||
```text
|
||||
MARKDOWN_LIVE_VERTICAL_OVERFLOW=ellipsis
|
||||
```
|
||||
When the markdown output exceeds the terminal height, only `...` is shown. This is the default and preserves backward compatibility.
|
||||
|
||||
**Visible mode (recommended for REPL sessions):**
|
||||
```text
|
||||
MARKDOWN_LIVE_VERTICAL_OVERFLOW=visible
|
||||
```
|
||||
All generated markdown content is visible in real-time. This is especially useful for long-running REPL interactions or agent workflows where you want to observe the model's reasoning process, tool calls, and intermediate outputs.
|
||||
|
||||
```shell
|
||||
sgpt --repl
|
||||
```
|
||||
With `visible` mode, you can continuously observe generated markdown output, tool execution details, and progress updates instead of staring at `...` for several minutes.
|
||||
|
||||
### Full list of arguments
|
||||
```text
|
||||
|
||||
@@ -35,6 +35,7 @@ DEFAULT_CONFIG = {
|
||||
"PRETTIFY_MARKDOWN": os.getenv("PRETTIFY_MARKDOWN", "true"),
|
||||
"USE_LITELLM": os.getenv("USE_LITELLM", "false"),
|
||||
"SHELL_INTERACTION": os.getenv("SHELL_INTERACTION ", "true"),
|
||||
"MARKDOWN_LIVE_VERTICAL_OVERFLOW": os.getenv("MARKDOWN_LIVE_VERTICAL_OVERFLOW", "ellipsis"),
|
||||
"OS_NAME": os.getenv("OS_NAME", "auto"),
|
||||
"SHELL_NAME": os.getenv("SHELL_NAME", "auto"),
|
||||
# New features might add their own config variables here.
|
||||
|
||||
@@ -46,8 +46,9 @@ class Handler:
|
||||
|
||||
@property
|
||||
def printer(self) -> Printer:
|
||||
vertical_overflow = cfg.get("MARKDOWN_LIVE_VERTICAL_OVERFLOW")
|
||||
return (
|
||||
MarkdownPrinter(self.code_theme)
|
||||
MarkdownPrinter(self.code_theme, vertical_overflow)
|
||||
if self.markdown
|
||||
else TextPrinter(self.color)
|
||||
)
|
||||
|
||||
+41
-9
@@ -1,10 +1,12 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Generator
|
||||
from typing import Generator, Literal
|
||||
|
||||
from rich.console import Console
|
||||
from rich.live import Live
|
||||
from rich.markdown import Markdown
|
||||
from typer import secho
|
||||
import time
|
||||
|
||||
|
||||
|
||||
class Printer(ABC):
|
||||
@@ -28,18 +30,48 @@ class Printer(ABC):
|
||||
|
||||
|
||||
class MarkdownPrinter(Printer):
|
||||
def __init__(self, theme: str) -> None:
|
||||
def __init__(
|
||||
self,
|
||||
theme: str,
|
||||
vertical_overflow: Literal["ellipsis", "visible", "crop"] = "ellipsis",
|
||||
) -> None:
|
||||
self.console = Console()
|
||||
self.theme = theme
|
||||
self.vertical_overflow = vertical_overflow
|
||||
|
||||
def live_print(self, chunks: Generator[str, None, None]) -> str:
|
||||
full_completion = ""
|
||||
with Live(console=self.console) as live:
|
||||
for chunk in chunks:
|
||||
full_completion += chunk
|
||||
markdown = Markdown(markup=full_completion, code_theme=self.theme)
|
||||
live.update(markdown, refresh=True)
|
||||
return full_completion
|
||||
full_completion = ""
|
||||
|
||||
with Live(
|
||||
console=self.console,
|
||||
vertical_overflow=self.vertical_overflow,
|
||||
auto_refresh=False,
|
||||
) as live:
|
||||
last_refresh = time.monotonic()
|
||||
for chunk in chunks:
|
||||
full_completion += chunk
|
||||
if time.monotonic() - last_refresh > 0.5:
|
||||
live.update(
|
||||
Markdown(
|
||||
markup=full_completion,
|
||||
code_theme=self.theme,
|
||||
),
|
||||
refresh=True,
|
||||
)
|
||||
last_refresh = time.monotonic()
|
||||
|
||||
# Avoid excessive terminal flickering caused by frequent refreshes.
|
||||
# Ensure the complete output is always rendered when streaming finishes.
|
||||
live.update(
|
||||
Markdown(
|
||||
markup=full_completion,
|
||||
code_theme=self.theme,
|
||||
),
|
||||
refresh=True,
|
||||
)
|
||||
|
||||
return full_completion
|
||||
|
||||
|
||||
def static_print(self, text: str) -> str:
|
||||
markdown = Markdown(markup=text, code_theme=self.theme)
|
||||
|
||||
Reference in New Issue
Block a user