diff --git a/README.md b/README.md deleted file mode 100644 index e1b787f..0000000 --- a/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# pygments_nightfox_style - -Pygments Nightfox Style -======================= - -A style for Pygments (and IPython) based on Nightfox palette by EdenEast. - -`Original repository for Nightfox palette `_ - diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..c064ad3 --- /dev/null +++ b/README.rst @@ -0,0 +1,74 @@ +# pygments_nightfox_style + +Pygments Nightfox Style +======================= + +A style for Pygments (and IPython) based on Nightfox palette by EdenEast. + +`Original repository for Nightfox palette `_ + + +This style has IPython specific configuration, when using this code in your +IPython configuration: + +.. code:: python + + from IPython.terminal.prompts import Prompts, RichPromptDisplayHook + from pygments.token import Token + from prompt_toolkit.enums import EditingMode + from platform import python_version + import os + import socket + import subprocess + + class NightfoxPrompts(Prompts): + def vi_mode(self): + if (getattr(self.shell.pt_app, 'editing_mode', None) == EditingMode.VI + and self.shell.prompt_includes_vi_mode): + mode = str(self.shell.pt_app.app.vi_state.input_mode) + if "INSERT" in mode: + return 'I' + if "NAV" in mode: + return 'N' + if "REPLACE_SINGLE" in mode: + return 'r' + if "REPLACE" in mode: + return 'R' + return 'E' # Emacs mode + + def in_prompt_tokens(self): + git_branch = "" + try: + git_branch = subprocess.check_output( + ["git", "branch", "--show-current"], stderr=subprocess.DEVNULL + ) + if git_branch: + git_branch = git_branch.decode("utf-8").replace("\n", "") + except subprocess.CalledProcessError: + pass + + git_branch = str(git_branch) + + venv = (os.environ.get("VIRTUAL_ENV") or "").split("/")[-1] + + return [ + (Token.IPython.Prompt.Login, os.getlogin()), + (Token.IPython.Prompt.Login.Sep, ''), + (Token.IPython.Prompt.Host, socket.gethostname()), + (Token.IPython.Prompt.Host.Sep, ''), + (Token.IPython.Prompt.Venv, venv), + (Token.IPython.Prompt.Venv.Sep, ''), + (Token.IPython.Prompt.Version, ' ' + python_version()), + (Token.IPython.Prompt.Version.Sep, ''), + (Token, '\n'), + (Token.IPython.Prompt.Cwd, os.getcwd()), + (Token.IPython.Prompt.Cwd.Sep, ''), + (Token.IPython.Prompt.Vcs, str(' ') + git_branch if git_branch else ''), + (Token.IPython.Prompt.Vcs.Sep, ''), + (Token, '\n'), + (Token.IPython.Prompt.Mode, self.vi_mode()), + (Token.IPython.Prompt.Mode.Sep, ' '), + ] + + def out_prompt_tokens(self): + return []