-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.ptpython.py
118 lines (88 loc) · 3.52 KB
/
.ptpython.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
"""
My Configuration for ptpython - an improved Python REPL.
This file lives at - ~/.ptpython/config.py
"""
from __future__ import unicode_literals
from prompt_toolkit.keys import Keys
from pygments.token import Token
__all__ = (
'configure',
)
def configure(repl):
"""
Configuration method. This is called during the start-up of ptpython.
:param repl: `PythonRepl` instance.
"""
# Show function signature (bool).
repl.show_signature = True
# Show docstring (bool).
repl.show_docstring = True
# Show completions.
repl.show_completions_menu = True
repl.show_completions_toolbar = False
# Show line numbers (when the input contains multiple lines.)
repl.show_line_numbers = True
# Show status bar.
repl.show_status_bar = True
# When the sidebar is visible, also show the help text.
repl.show_sidebar_help = True
# Complete while typing. (Don't require tab before the
# completion menu is shown.)
repl.complete_while_typing = True
# Vi mode.
repl.vi_mode = False
# Paste mode. (When True, don't insert whitespace after new line.)
repl.paste_mode = False
# History Search.
# When True, going back in history will filter the history on the records
# starting with the current input. (Like readline.)
# Note: When enable, please disable the `complete_while_typing` option.
# otherwise, when there is a completion available, the arrows will
# browse through the available completions instead of the history.
repl.enable_history_search = False
# Enable open-in-editor. Pressing C-X C-E in emacs mode or 'v' in
# Vi navigation mode will open the input in the current editor.
repl.enable_open_in_editor = True
# Enable system prompt. Pressing meta-! will display the system prompt.
# Also enables Control-Z suspend.
repl.enable_system_bindings = True
# Ask for confirmation on exit.
repl.confirm_exit = False
# Enable input validation. (Don't try to execute when the input contains
# syntax errors.)
repl.enable_input_validation = True
# Fish style auto suggestion
repl.enable_auto_suggest = True
# Use this colorscheme for the code.
repl.use_code_colorscheme('monokai')
# Install custom colorscheme named 'my-colorscheme' and use it.
# repl.install_ui_colorscheme('my-colorscheme', _custom_ui_colorscheme)
# repl.use_ui_colorscheme('my-colorscheme')
# Add custom key binding for PDB.
@repl.add_key_binding(Keys.ControlB)
def _(event):
' Pressing Control-B will insert "pdb.set_trace()" '
event.cli.current_buffer.insert_text('\nimport pdb; pdb.set_trace()\n')
# Custom key binding for some simple autocorrection while typing.
corrections = {
'impotr': 'import',
'pritn': 'print',
}
@repl.add_key_binding(' ')
def _(event):
' When a space is pressed. Check & correct word before cursor. '
b = event.cli.current_buffer
w = b.document.get_word_before_cursor()
if w is not None:
if w in corrections:
b.delete_before_cursor(count=len(w))
b.insert_text(corrections[w])
b.insert_text(' ')
# Custom colorscheme for the UI. See `ptpython/layout.py` and
# `ptpython/style.py` for all possible tokens.
_custom_ui_colorscheme = {
# Blue prompt.
Token.Layout.Prompt: 'bg:#eeeeff #000000 bold',
# Make the status toolbar red.
Token.Toolbar.Status: 'bg:#ff0000 #000000',
}