Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
7adb9ad
initial working shell sidebar
taleinat Aug 5, 2019
26bbaec
fix recall and handling of prompt and input lines
taleinat Aug 23, 2019
9076da5
update only as needed during editing, accounting for line wrapping
taleinat Aug 23, 2019
cad2cd1
properly insert delegators into their proper place in the percolator
taleinat Aug 24, 2019
4040e26
move non-syntax tag highlighting out of ColorDelegator
taleinat Aug 24, 2019
9b31031
replace shell sidebar prompt and input line recognition method
taleinat Aug 24, 2019
37a0db3
minor code cleanup
taleinat Aug 24, 2019
c766822
remove unnecessary .replace() delegator method
taleinat Aug 24, 2019
50bd082
fix inverted condition in deciding whether to update sidebar (oops!)
taleinat Aug 24, 2019
6f186f0
fix "stdin" tag removed when undo-ing a deletion
taleinat Aug 24, 2019
f7f3de9
fix sidebar update on new prompt
taleinat Aug 24, 2019
e929ea7
add a NEWS entry
taleinat Aug 24, 2019
d04bfa3
fix recall handling with multiple successive statements
taleinat Aug 24, 2019
81f4852
remove a dead line
taleinat Aug 24, 2019
46be85e
remove commented out initial attempt
taleinat Aug 24, 2019
1fc4bcb
update shell sidebar font upon font config changes
taleinat Aug 25, 2019
6f1c975
update sidebar text colors upon highlight config changes
taleinat Sep 17, 2020
083fede
use the prompt ("console") foreground color for the shell sidebar text
taleinat Sep 17, 2020
4ad72a1
show continuation prompts ("...") for multi-line history recall
taleinat Sep 17, 2020
009e08d
show continuation prompts ("...") after multi-line replace in the shell
taleinat Sep 17, 2020
e524cce
show continuation prompts ("...") after multi-line undo/redo in the s…
taleinat Sep 17, 2020
3ea2986
don't show continuation prompts ("...") for print() outputs
taleinat Sep 17, 2020
7f9182f
allow deleting ">>> " at the beginning of a line in shell windows
taleinat Sep 17, 2020
10aaf1d
update shell sidebar on shell output squeeze/unsqueeze
taleinat Sep 17, 2020
7c91901
remove failing editor window test that is no longer relevant
taleinat Sep 17, 2020
50ca9c6
add several tests for the shell sidebar
taleinat Sep 18, 2020
23c218f
reduce shell sidebar test run time by reusing the PyShell
taleinat Sep 18, 2020
6cef0a9
revert removal of the "hit" tag from Colorizer.tag_defs
taleinat Oct 11, 2020
a018135
hide unnecessary extra "root" Tk window in tests
taleinat Oct 11, 2020
525fe44
fix test method names
taleinat Oct 11, 2020
7b8913d
fix test comments according to pep-8 style
taleinat Oct 11, 2020
8c8d0c0
rename sidebar test class according to convention
taleinat Oct 11, 2020
7ecc843
re-word doc-strings for BaseSideBar and EndLineDelegator
taleinat Oct 12, 2020
bedb1cb
re-word doc-strings for get_lineno and get_end_linenumber
taleinat Oct 12, 2020
eee0453
optimize tests and make them more robust
taleinat Oct 12, 2020
7afcb57
handle mouse buttons except for button 1 (left-click)
taleinat Oct 12, 2020
8a7dd60
add tests for text font and color configs
taleinat Oct 12, 2020
6efb968
remove show/hide_sidebar from the shell sidebar
taleinat Oct 12, 2020
cc37924
add more test cases
taleinat Oct 12, 2020
97576da
update coverage percentage
taleinat Oct 12, 2020
2aa4e1a
re-word squeeze_current_text() doc-string
taleinat Oct 12, 2020
71f343e
update coverage percentage
taleinat Oct 13, 2020
45e66a5
Merge branch 'master' into idle-shell-sidebar
taleinat Oct 13, 2020
dbe931c
fix wrong colors at ends of input lines/blocks
taleinat Oct 14, 2020
779adc4
fix some sidebar tests affected by losing window focus
taleinat Oct 14, 2020
8f81915
fix highlighting and sidebar prompts after syntax errors
taleinat Oct 15, 2020
ddc0026
better long-term disabling of line numbers tests
taleinat Oct 15, 2020
d1e0d32
update unittest coverage percentage
taleinat Oct 15, 2020
0516db9
run sidebar tests with PyShell without a sub-process
taleinat Oct 22, 2020
afa6669
avoid creating text widgets for whitespace shell prompts
taleinat Oct 22, 2020
9d06f26
simplify some test code
taleinat Oct 22, 2020
73146fb
remove unnecessary parentheses
taleinat Oct 22, 2020
19b16a4
fix first prompt when shown text starts with the end of a wrapped line
taleinat Oct 22, 2020
ecab884
fix failing tests on Azure Devops
taleinat Nov 1, 2020
7b2d9dc
Merge remote-tracking branch 'upstream/master' into pr_22682
terryjreedy Jan 22, 2021
d6e35cc
Merge remote-tracking branch 'upstream/master' into pr_22682
terryjreedy Apr 25, 2021
f6c9a7c
revert indentation change
taleinat Apr 25, 2021
990cef4
revert InteractiveInterpreter.runsource return values
taleinat Apr 25, 2021
e86353b
fix removal of final newline and surrounding whitespace
taleinat Apr 25, 2021
a1891a4
simplify fixed newline+whitespace removal using \Z
taleinat Apr 25, 2021
3e52c5d
revert unneeded changes to ResetColorizer
taleinat Apr 26, 2021
cc709ab
wrap some overly long lines of code
taleinat Apr 26, 2021
093544a
fix tests failing on Azure Pipelines
taleinat Apr 27, 2021
474c11a
rename and refactor Tk mainloop function decorator
taleinat Apr 28, 2021
fde793a
simplify code by making use_subprocess default to False
taleinat Apr 28, 2021
916e0d3
rename "*_command" -> "*_statement"
taleinat Apr 28, 2021
8ada0a7
improve test with squeezer
taleinat Apr 28, 2021
c1871f2
fix missed renaming of update_colors() back to ResetColorizer()
taleinat Apr 28, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
replace shell sidebar prompt and input line recognition method
Prompts are now marked in the text by adding the "console" tag to
the newline character ('\n') before the beginning of the line.  This
works around issues with the prompt itself usually no longer being
written in the text widget.

With another small fix to the PyShell.recall() method, input lines
can now be recognized consistently by checking for the "stdin" tag.

This is much better than attempting to separately track the prompt
and input lines, since those are difficult to keep up to date after
undo/redo actions and squeezing/unsqueezing of previous output.
  • Loading branch information
taleinat committed Sep 17, 2020
commit 9b31031896964f5853d0f7d63ba83ac7bffc23c7
37 changes: 20 additions & 17 deletions Lib/idlelib/pyshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

from idlelib.colorizer import ColorDelegator
from idlelib.config import idleConf
from idlelib.delegator import Delegator
from idlelib import debugger
from idlelib import debugger_r
from idlelib.editor import EditorWindow, fixwordbreaks
Expand Down Expand Up @@ -367,6 +368,14 @@ def delete(self, index1, index2=None):
UndoDelegator.delete(self, index1, index2)


class UserInputTaggingDelegator(Delegator):
"""Delegator used to tag user input with "stdin"."""
def insert(self, index, chars, tags=None):
if tags is None:
tags = "stdin"
self.delegate.insert(index, chars, tags)


class MyRPCClient(rpc.RPCClient):

def handle_EOF(self):
Expand Down Expand Up @@ -912,12 +921,15 @@ def __init__(self, flist=None):
#
self.pollinterval = 50 # millisec

self.input_lines = set()
self.prompt_lines = set()

self.shell_sidebar = self.ShellSidebar(self)
self.shell_sidebar.show_sidebar()

# Insert UserInputTaggingDelegator at the top of the percolator,
# but make calls to text.insert() skip it. This causes only insert
# events generated in Tcl/Tk to go through this delegator.
self.text.insert = self.per.top.insert
self.per.insertfilter(UserInputTaggingDelegator())

def get_tag_colors(self):
tag_colors = super().get_tag_colors()

Expand Down Expand Up @@ -1169,7 +1181,7 @@ def enter_callback(self, event):
if prev and self.text.compare("insert", "<", prev[1]):
for line in reversed(range(self.getlineno(prev[0]),
self.getlineno(prev[1]))):
if line in self.prompt_lines:
if "console" in self.text.tag_names(f"{line}.0-1c"):
break
if self.text.compare(f"{line}.0", ">", prev[0]):
prev = (f"{line}.0", prev[1])
Expand All @@ -1179,7 +1191,7 @@ def enter_callback(self, event):
if next and self.text.compare("insert lineend", ">=", next[0]):
for line in range(self.getlineno(next[0]),
self.getlineno(next[1])):
if line + 1 in self.prompt_lines:
if "console" in self.text.tag_names(f"{line+1}.0-1c"):
break
if self.text.compare(f"{line}.end", "<", next[1]):
next = (next[0], f"{line}.end")
Expand Down Expand Up @@ -1236,17 +1248,15 @@ def recall(self, s, event):
self.newline_and_indent_event(event)
prefix = self.text.get("insert linestart", "insert")
first_line = self.getlineno("insert")
self.text.insert("insert", lines[0].strip())
self.text.insert("insert", lines[0].strip(), "stdin")
if len(lines) > 1:
orig_base_indent = re.search(r'^([ \t]*)', lines[0]).group(0)
new_base_indent = re.search(r'^([ \t]*)', prefix).group(0)
for line in lines[1:]:
if line.startswith(orig_base_indent):
# replace orig base indentation with new indentation
line = new_base_indent + line[len(orig_base_indent):]
self.text.insert('insert', '\n'+line.rstrip())
self.input_lines.update(
range(first_line, self.getlineno("insert") + 1))
self.text.insert('insert', '\n'+line.rstrip(), "stdin")
self.shell_sidebar.update_sidebar()
finally:
self.text.see("insert")
Expand All @@ -1268,8 +1278,6 @@ def runit(self):
# If the input is a complete statement, the sidebar updates will be
# handled elsewhere.
if input_is_incomplete:
self.input_lines.update(range(self.getlineno("iomark"),
self.getlineno("end-1c") + 1))
self.shell_sidebar.update_sidebar()

def open_stack_viewer(self, event=None):
Expand Down Expand Up @@ -1297,17 +1305,12 @@ def restart_shell(self, event=None):
def showprompt(self):
self.resetoutput()

prompt_lineno = self.getlineno("iomark")
prompt = self.prompt
if self.sys_ps1 and prompt.endswith(self.sys_ps1):
prompt = prompt[:-len(self.sys_ps1)]
self.text.tag_add("console", "iomark-1c")
self.console.write(prompt)

n_prompt_lines = prompt.count('\n') + 1
self.prompt_lines.update(
range(prompt_lineno, prompt_lineno + n_prompt_lines))
self.shell_sidebar.update_sidebar()

self.text.mark_set("insert", "end-1c")
self.set_line_and_column()
self.io.reset_undo()
Expand Down
8 changes: 5 additions & 3 deletions Lib/idlelib/sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ def change_callback(self):

def update_sidebar(self):
text = self.text
text_tagnames = text.tag_names
canvas = self.canvas

canvas.delete(tk.ALL)
Expand All @@ -488,10 +489,11 @@ def update_sidebar(self):
if lineinfo is None:
break
y = lineinfo[1]
lineno = self.editwin.getlineno(index)
is_prompt = "console" in text_tagnames(f"{index} linestart -1c")
is_input = "stdin" in text_tagnames(f"{index} lineend -1c")
prompt = (
'>>>' if lineno in self.editwin.prompt_lines else
'...' if lineno in self.editwin.input_lines else
'>>>' if is_prompt else
'...' if is_input else
' '
)
canvas.create_text(2, y, anchor=tk.NW, text=prompt,
Expand Down