Skip to content

Commit

Permalink
Cleaner code examples (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin authored Oct 14, 2023
1 parent 1295811 commit 651ab81
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ repos:

- repo: local
hooks:
- id: lint
name: Lint
entry: make lint
- id: format
name: Format Python
entry: make format
types: [python]
language: system
pass_filenames: false
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ install:
.PHONY: format
format:
black $(sources)
ruff --fix $(sources)
ruff --fix-only $(sources)

.PHONY: lint
lint:
Expand Down
18 changes: 15 additions & 3 deletions samuelcolvin_aicli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,25 @@
from prompt_toolkit import PromptSession
from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
from prompt_toolkit.history import FileHistory
from rich.console import Console
from rich.console import Console, ConsoleOptions, RenderResult
from rich.live import Live
from rich.markdown import Markdown
from rich.markdown import CodeBlock, Markdown
from rich.status import Status
from rich.syntax import Syntax
from rich.text import Text

__version__ = '0.4.1'
__version__ = '0.5.0'


class SimpleCodeBlock(CodeBlock):
def __rich_console__(self, console: Console, options: ConsoleOptions) -> RenderResult:
code = str(self.text).rstrip()
yield Text(self.lexer_name, style='dim')
yield Syntax(code, self.lexer_name, theme=self.theme, background_color='default', word_wrap=True)
yield Text(f'/{self.lexer_name}', style='dim')


Markdown.elements['fence'] = SimpleCodeBlock


def cli() -> int:
Expand Down

0 comments on commit 651ab81

Please sign in to comment.