Advertisement
FranzVuttke

ptpython config file

May 23rd, 2024
674
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.96 KB | Source Code | 1 0
  1. """
  2. Configuration example for ``ptpython``.
  3.  
  4. Copy this file to $XDG_CONFIG_HOME/ptpython/config.py
  5. On Linux, this is: ~/.config/ptpython/config.py
  6. On macOS, this is: ~/Library/Application Support/ptpython/config.py
  7. """
  8. from prompt_toolkit.filters import ViInsertMode
  9. from prompt_toolkit.key_binding.key_processor import KeyPress
  10. from prompt_toolkit.keys import Keys
  11. from prompt_toolkit.styles import Style
  12.  
  13. from ptpython.layout import CompletionVisualisation
  14.  
  15. __all__ = ["configure"]
  16.  
  17.  
  18. def configure(repl):
  19.     """
  20.    Configuration method. This is called during the start-up of ptpython.
  21.  
  22.    :param repl: `PythonRepl` instance.
  23.    """
  24.     # Show function signature (bool).
  25.     repl.show_signature = True
  26.  
  27.     # Show docstring (bool).
  28.     repl.show_docstring = False
  29.  
  30.     # Show the "[Meta+Enter] Execute" message when pressing [Enter] only
  31.     # inserts a newline instead of executing the code.
  32.     repl.show_meta_enter_message = True
  33.  
  34.     # Show completions. (NONE, POP_UP, MULTI_COLUMN or TOOLBAR)
  35.     repl.completion_visualisation = CompletionVisualisation.POP_UP
  36.  
  37.     # When CompletionVisualisation.POP_UP has been chosen, use this
  38.     # scroll_offset in the completion menu.
  39.     repl.completion_menu_scroll_offset = 0
  40.  
  41.     # Show line numbers (when the input contains multiple lines.)
  42.     repl.show_line_numbers = False
  43.  
  44.     # Show status bar.
  45.     repl.show_status_bar = True
  46.  
  47.     # When the sidebar is visible, also show the help text.
  48.     repl.show_sidebar_help = True
  49.  
  50.     # Swap light/dark colors on or off
  51.     repl.swap_light_and_dark = True
  52.  
  53.     # Highlight matching parentheses.
  54.     repl.highlight_matching_parenthesis = True
  55.  
  56.     # Line wrapping. (Instead of horizontal scrolling.)
  57.     repl.wrap_lines = True
  58.  
  59.     # Mouse support.
  60.     repl.enable_mouse_support = False # OuNiS 01.2024 - wyłącza przełączanie spodniego statusbaru ale włącza popup menu!
  61.  
  62.     # Complete while typing. (Don't require tab before the
  63.     # completion menu is shown.)
  64.     repl.complete_while_typing = True
  65.  
  66.     # Fuzzy and dictionary completion.
  67.     repl.enable_fuzzy_completion = False
  68.     repl.enable_dictionary_completion = False
  69.  
  70.     # Vi mode.
  71.     repl.vi_mode = False
  72.  
  73.     # Enable the modal cursor (when using Vi mode). Other options are 'Block', 'Underline',  'Beam',  'Blink under', 'Blink block', and 'Blink beam'
  74.     repl.cursor_shape_config = "Modal (vi)"
  75.  
  76.     # Paste mode. (When True, don't insert whitespace after new line.)
  77.     repl.paste_mode = False
  78.  
  79.     # Use the classic prompt. (Display '>>>' instead of 'In [1]'.)
  80.     repl.prompt_style = "ipython"  # 'classic' or 'ipython'
  81.  
  82.     # Don't insert a blank line after the output.
  83.     repl.insert_blank_line_after_output = False
  84.  
  85.     # History Search.
  86.     # When True, going back in history will filter the history on the records
  87.     # starting with the current input. (Like readline.)
  88.     # Note: When enable, please disable the `complete_while_typing` option.
  89.     #       otherwise, when there is a completion available, the arrows will
  90.     #       browse through the available completions instead of the history.
  91.     repl.enable_history_search = True
  92.  
  93.     # Enable auto suggestions. (Pressing right arrow will complete the input,
  94.     # based on the history.)
  95.     repl.enable_auto_suggest = False
  96.  
  97.     # Enable open-in-editor. Pressing C-x C-e in emacs mode or 'v' in
  98.     # Vi navigation mode will open the input in the current editor.
  99.     repl.enable_open_in_editor = True
  100.  
  101.     # Enable system prompt. Pressing meta-! will display the system prompt.
  102.     # Also enables Control-Z suspend.
  103.     repl.enable_system_bindings = True
  104.  
  105.     # Ask for confirmation on exit.
  106.     repl.confirm_exit = False # OuNiS 01.2024
  107.  
  108.     # Enable input validation. (Don't try to execute when the input contains
  109.     # syntax errors.)
  110.     repl.enable_input_validation = True
  111.  
  112.     # Use this colorscheme for the code.
  113.     # Ptpython uses Pygments for code styling, so you can choose from Pygments'
  114.     # color schemes. See:
  115.     # https://pygments.org/docs/styles/
  116.     # https://pygments.org/demo/
  117.     repl.use_code_colorscheme("default")
  118.     # A colorscheme that looks good on dark backgrounds is 'native':
  119.     # repl.use_code_colorscheme("native")
  120.  
  121.     # Set color depth (keep in mind that not all terminals support true color).
  122.  
  123.     # repl.color_depth = "DEPTH_1_BIT"  # Monochrome.
  124.     # repl.color_depth = "DEPTH_4_BIT"  # ANSI colors only.
  125.     repl.color_depth = "DEPTH_8_BIT"  # The default, 256 colors.
  126.     # repl.color_depth = "DEPTH_24_BIT"  # True color.
  127.  
  128.     # Min/max brightness
  129.     repl.min_brightness = 0.0  # Increase for dark terminal backgrounds.
  130.     repl.max_brightness = 1.0  # Decrease for light terminal backgrounds.
  131.  
  132.     # Syntax.
  133.     repl.enable_syntax_highlighting = True
  134.  
  135.     # Get into Vi navigation mode at startup
  136.     repl.vi_start_in_navigation_mode = False
  137.  
  138.     # Preserve last used Vi input mode between main loop iterations
  139.     repl.vi_keep_last_used_mode = False
  140.  
  141.     # Install custom colorscheme named 'my-colorscheme' and use it.
  142.     """
  143.    repl.install_ui_colorscheme("my-colorscheme", Style.from_dict(_custom_ui_colorscheme))
  144.    repl.use_ui_colorscheme("my-colorscheme")
  145.    """
  146.  
  147.     # Add custom key binding for PDB.
  148.     """
  149.    @repl.add_key_binding("c-b")
  150.    def _(event):
  151.        " Pressing Control-B will insert "pdb.set_trace()" "
  152.        event.cli.current_buffer.insert_text("\nimport pdb; pdb.set_trace()\n")
  153.    """
  154.  
  155.     # Typing ControlE twice should also execute the current command.
  156.     # (Alternative for Meta-Enter.)
  157.     """
  158.    @repl.add_key_binding("c-e", "c-e")
  159.    def _(event):
  160.        event.current_buffer.validate_and_handle()
  161.    """
  162.  
  163.     # Typing 'jj' in Vi Insert mode, should send escape. (Go back to navigation
  164.     # mode.)
  165.     """
  166.    @repl.add_key_binding("j", "j", filter=ViInsertMode())
  167.    def _(event):
  168.        " Map 'jj' to Escape. "
  169.        event.cli.key_processor.feed(KeyPress(Keys("escape")))
  170.    """
  171.  
  172.     # Custom key binding for some simple autocorrection while typing.
  173.  
  174.     corrections = {
  175.         "impotr": "import",
  176.         "pritn": "print",
  177.     }
  178.  
  179.     @repl.add_key_binding(" ")
  180.     def _(event):
  181.         " When a space is pressed. Check & correct word before cursor. "
  182.         b = event.cli.current_buffer
  183.         w = b.document.get_word_before_cursor()
  184.  
  185.         if w is not None:
  186.             if w in corrections:
  187.                 b.delete_before_cursor(count=len(w))
  188.                 b.insert_text(corrections[w])
  189.  
  190.         b.insert_text(" ")
  191.  
  192.  
  193.     # Add a custom title to the status bar. This is useful when ptpython is
  194.     # embedded in other applications.
  195.     """
  196.    repl.title = "My custom prompt."
  197.    """
  198.  
  199.  
  200. # Custom colorscheme for the UI. See `ptpython/layout.py` and
  201. # `ptpython/style.py` for all possible tokens.
  202. _custom_ui_colorscheme = {
  203.     # Blue prompt.
  204.     "prompt": "bg:#eeeeff #000000 bold",
  205.     # Make the status toolbar red.
  206.     "status-toolbar": "bg:#ff0000 #000000",
  207. }
  208.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement