<commit_before>"""
IPython configuration with custom prompt using gruvbox colors.
- https://github.com/reillysiemens/ipython-style-gruvbox

Thanks to @petobens for their excellent dotfiles.
- https://github.com/petobens/dotfiles
"""
from typing import List, Optional, Tuple

import IPython.terminal.prompts as prompts
from prompt_toolkit.application import get_app
from prompt_toolkit.key_binding.vi_state import InputMode
from pygments.token import _TokenType, Token

from gruvbox import Color, GruvboxStyle

config = get_config()  # type: ignore # noqa: E0602


class Prompt(prompts.Prompts):
    """Custom IPython prompt."""

    _before: str = "❰"
    _after: str = "❱ ⬢ "
    _continuation: str = "… "

    def in_prompt_tokens(self) -> List[Tuple[_TokenType, str]]:
        """Return in prompt."""
        if get_app().vi_state.input_mode == InputMode.INSERT:
            prompt_token = prompts.Token.InsertPrompt
            num_token = prompts.Token.InsertPromptNum
        else:
            prompt_token = prompts.Token.NavPrompt
            num_token = prompts.Token.NavPromptNum

        return [
            (prompt_token, self._before),
            (num_token, str(self.shell.execution_count)),
            (prompt_token, self._after),
        ]

    def continuation_prompt_tokens(
        self, width: Optional[int] = None
    ) -> List[Tuple[_TokenType, str]]:
        """Return continuation prompt."""
        if width is None:
            width = self._width()

        if get_app().vi_state.input_mode == InputMode.INSERT:
            token = prompts.Token.InsertPrompt
        else:
            token = prompts.Token.NavPrompt

        return [(token, " " * (width - 2) + self._continuation)]

    def out_prompt_tokens(self) -> List[Tuple[_TokenType, str]]:
        """Return out prompt."""
        return []


config.TerminalIPythonApp.display_banner = False
config.TerminalInteractiveShell.confirm_exit = False
config.TerminalInteractiveShell.editing_mode = "vi"
config.TerminalInteractiveShell.true_color = True
config.TerminalInteractiveShell.prompts_class = Prompt
config.TerminalInteractiveShell.highlighting_style = GruvboxStyle
config.TerminalInteractiveShell.highlighting_style_overrides = {
    Token.InsertPrompt: Color.neutral_blue,
    Token.NavPrompt: Color.neutral_purple,
    Token.InsertPromptNum: f"{Color.neutral_purple} bold",
    Token.NavPromptNum: f"{Color.neutral_blue} bold",
}
<commit_msg>Suppress annoying virtualenv warnings<commit_after>"""
IPython configuration with custom prompt using gruvbox colors.
- https://github.com/reillysiemens/ipython-style-gruvbox

Thanks to @petobens for their excellent dotfiles.
- https://github.com/petobens/dotfiles
"""
import warnings
from typing import List, Optional, Tuple

import IPython.terminal.prompts as prompts
from prompt_toolkit.application import get_app
from prompt_toolkit.key_binding.vi_state import InputMode
from pygments.token import _TokenType, Token

from gruvbox import Color, GruvboxStyle

config = get_config()  # type: ignore # noqa: E0602


class Prompt(prompts.Prompts):
    """Custom IPython prompt."""

    _before: str = "❰"
    _after: str = "❱ ⬢ "
    _continuation: str = "… "

    def in_prompt_tokens(self) -> List[Tuple[_TokenType, str]]:
        """Return in prompt."""
        if get_app().vi_state.input_mode == InputMode.INSERT:
            prompt_token = prompts.Token.InsertPrompt
            num_token = prompts.Token.InsertPromptNum
        else:
            prompt_token = prompts.Token.NavPrompt
            num_token = prompts.Token.NavPromptNum

        return [
            (prompt_token, self._before),
            (num_token, str(self.shell.execution_count)),
            (prompt_token, self._after),
        ]

    def continuation_prompt_tokens(
        self, width: Optional[int] = None
    ) -> List[Tuple[_TokenType, str]]:
        """Return continuation prompt."""
        if width is None:
            width = self._width()

        if get_app().vi_state.input_mode == InputMode.INSERT:
            token = prompts.Token.InsertPrompt
        else:
            token = prompts.Token.NavPrompt

        return [(token, " " * (width - 2) + self._continuation)]

    def out_prompt_tokens(self) -> List[Tuple[_TokenType, str]]:
        """Return out prompt."""
        return []


config.TerminalIPythonApp.display_banner = False
config.TerminalInteractiveShell.confirm_exit = False
config.TerminalInteractiveShell.editing_mode = "vi"
config.TerminalInteractiveShell.true_color = True
config.TerminalInteractiveShell.prompts_class = Prompt
config.TerminalInteractiveShell.highlighting_style = GruvboxStyle
config.TerminalInteractiveShell.highlighting_style_overrides = {
    Token.InsertPrompt: Color.neutral_blue,
    Token.NavPrompt: Color.neutral_purple,
    Token.InsertPromptNum: f"{Color.neutral_purple} bold",
    Token.NavPromptNum: f"{Color.neutral_blue} bold",
}

# Suppress annoying virtualenv warnings.
warnings.filterwarnings(
    "ignore",
    message=(
        "Attempting to work in a virtualenv. If you encounter problems, "
        "please install IPython inside the virtualenv."
    ),
)

{'fraction_non_alphanumeric': 0.10202098717450447, 'fraction_numerical': 0.00194325689856199, 'mean_word_length': 3.3324915824915826, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1548737', 'n_tokens_mistral': 1603, 'n_tokens_neox': 1529, 'n_words': 336}