mirror of
https://github.com/python/cpython.git
synced 2025-08-23 02:04:56 +00:00
bpo-37903: IDLE: Shell sidebar with prompts (GH-22682)
The first followup will change shell indents to spaces. More are expected. Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
This commit is contained in:
parent
103d5e420d
commit
15d3861856
14 changed files with 888 additions and 132 deletions
|
@ -60,7 +60,6 @@ class EditorWindow:
|
|||
from idlelib.sidebar import LineNumbers
|
||||
from idlelib.format import FormatParagraph, FormatRegion, Indents, Rstrip
|
||||
from idlelib.parenmatch import ParenMatch
|
||||
from idlelib.squeezer import Squeezer
|
||||
from idlelib.zoomheight import ZoomHeight
|
||||
|
||||
filesystemencoding = sys.getfilesystemencoding() # for file names
|
||||
|
@ -68,6 +67,7 @@ class EditorWindow:
|
|||
|
||||
allow_code_context = True
|
||||
allow_line_numbers = True
|
||||
user_input_insert_tags = None
|
||||
|
||||
def __init__(self, flist=None, filename=None, key=None, root=None):
|
||||
# Delay import: runscript imports pyshell imports EditorWindow.
|
||||
|
@ -784,9 +784,7 @@ class EditorWindow:
|
|||
self.color = self.ColorDelegator()
|
||||
# can add more colorizers here...
|
||||
if self.color:
|
||||
self.per.removefilter(self.undo)
|
||||
self.per.insertfilter(self.color)
|
||||
self.per.insertfilter(self.undo)
|
||||
self.per.insertfilterafter(filter=self.color, after=self.undo)
|
||||
|
||||
def _rmcolorizer(self):
|
||||
if not self.color:
|
||||
|
@ -1303,8 +1301,6 @@ class EditorWindow:
|
|||
# Debug prompt is multilined....
|
||||
ncharsdeleted = 0
|
||||
while 1:
|
||||
if chars == self.prompt_last_line: # '' unless PyShell
|
||||
break
|
||||
chars = chars[:-1]
|
||||
ncharsdeleted = ncharsdeleted + 1
|
||||
have = len(chars.expandtabs(tabwidth))
|
||||
|
@ -1313,7 +1309,8 @@ class EditorWindow:
|
|||
text.undo_block_start()
|
||||
text.delete("insert-%dc" % ncharsdeleted, "insert")
|
||||
if have < want:
|
||||
text.insert("insert", ' ' * (want - have))
|
||||
text.insert("insert", ' ' * (want - have),
|
||||
self.user_input_insert_tags)
|
||||
text.undo_block_stop()
|
||||
return "break"
|
||||
|
||||
|
@ -1346,7 +1343,7 @@ class EditorWindow:
|
|||
effective = len(prefix.expandtabs(self.tabwidth))
|
||||
n = self.indentwidth
|
||||
pad = ' ' * (n - effective % n)
|
||||
text.insert("insert", pad)
|
||||
text.insert("insert", pad, self.user_input_insert_tags)
|
||||
text.see("insert")
|
||||
return "break"
|
||||
finally:
|
||||
|
@ -1377,13 +1374,14 @@ class EditorWindow:
|
|||
if i == n:
|
||||
# The cursor is in or at leading indentation in a continuation
|
||||
# line; just inject an empty line at the start.
|
||||
text.insert("insert linestart", '\n')
|
||||
text.insert("insert linestart", '\n',
|
||||
self.user_input_insert_tags)
|
||||
return "break"
|
||||
indent = line[:i]
|
||||
|
||||
# Strip whitespace before insert point unless it's in the prompt.
|
||||
i = 0
|
||||
while line and line[-1] in " \t" and line != self.prompt_last_line:
|
||||
while line and line[-1] in " \t":
|
||||
line = line[:-1]
|
||||
i += 1
|
||||
if i:
|
||||
|
@ -1394,7 +1392,7 @@ class EditorWindow:
|
|||
text.delete("insert")
|
||||
|
||||
# Insert new line.
|
||||
text.insert("insert", '\n')
|
||||
text.insert("insert", '\n', self.user_input_insert_tags)
|
||||
|
||||
# Adjust indentation for continuations and block open/close.
|
||||
# First need to find the last statement.
|
||||
|
@ -1430,7 +1428,7 @@ class EditorWindow:
|
|||
elif c == pyparse.C_STRING_NEXT_LINES:
|
||||
# Inside a string which started before this line;
|
||||
# just mimic the current indent.
|
||||
text.insert("insert", indent)
|
||||
text.insert("insert", indent, self.user_input_insert_tags)
|
||||
elif c == pyparse.C_BRACKET:
|
||||
# Line up with the first (if any) element of the
|
||||
# last open bracket structure; else indent one
|
||||
|
@ -1444,7 +1442,8 @@ class EditorWindow:
|
|||
# beyond leftmost =; else to beyond first chunk of
|
||||
# non-whitespace on initial line.
|
||||
if y.get_num_lines_in_stmt() > 1:
|
||||
text.insert("insert", indent)
|
||||
text.insert("insert", indent,
|
||||
self.user_input_insert_tags)
|
||||
else:
|
||||
self.reindent_to(y.compute_backslash_indent())
|
||||
else:
|
||||
|
@ -1455,7 +1454,7 @@ class EditorWindow:
|
|||
# indentation of initial line of closest preceding
|
||||
# interesting statement.
|
||||
indent = y.get_base_indent_string()
|
||||
text.insert("insert", indent)
|
||||
text.insert("insert", indent, self.user_input_insert_tags)
|
||||
if y.is_block_opener():
|
||||
self.smart_indent_event(event)
|
||||
elif indent and y.is_block_closer():
|
||||
|
@ -1502,7 +1501,8 @@ class EditorWindow:
|
|||
if text.compare("insert linestart", "!=", "insert"):
|
||||
text.delete("insert linestart", "insert")
|
||||
if column:
|
||||
text.insert("insert", self._make_blanks(column))
|
||||
text.insert("insert", self._make_blanks(column),
|
||||
self.user_input_insert_tags)
|
||||
text.undo_block_stop()
|
||||
|
||||
# Guess indentwidth from text content.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue