Skip to content

Commit 214e4ca

Browse files
rybarczykjthomasballinger
authored andcommitted
reconfigure and rename formatforfile
- New name: get_session_formatted_for_file - No longer takes parameters as it can refer directly to all_logical_lines - send_session_to_external_editor now call this method instead of doing a very similar process - Now "# OUT:" refers to output and "### " refers to current line
1 parent e1733c5 commit 214e4ca

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

bpython/curtsiesfrontend/repl.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from pygments.formatters import TerminalFormatter
2121

2222
from wcwidth import wcswidth
23-
from math import ceil
2423

2524
import blessings
2625

@@ -1009,18 +1008,10 @@ def send_current_block_to_external_editor(self, filename=None):
10091008

10101009
def send_session_to_external_editor(self, filename=None):
10111010
"""
1012-
Sends entire bpython session to external editor to be edited. Usually bound to F7.
1013-
1014-
Loops through self.all_logical_lines so that lines aren't wrapped in the editor.
1015-
1011+
Sends entire bpython session to external editor to be edited. Usually bound to F7.
10161012
"""
10171013
for_editor = EDIT_SESSION_HEADER
1018-
for_editor += "\n".join(
1019-
line[0] if line[1] == INPUT
1020-
else "### " + line[0]
1021-
for line in self.all_logical_lines
1022-
)
1023-
for_editor += "\n" + "### " + self.current_line
1014+
for_editor += self.get_session_formatted_for_file()
10241015

10251016
text = self.send_to_external_editor(for_editor)
10261017
if text == for_editor:
@@ -1035,7 +1026,7 @@ def send_session_to_external_editor(self, filename=None):
10351026
current_line = lines[-1][4:]
10361027
else:
10371028
current_line = ""
1038-
from_editor = [line for line in lines if line[:3] != "###"]
1029+
from_editor = [line for line in lines if line[:6] != "# OUT:"]
10391030
if all(not line.strip() for line in from_editor):
10401031
self.status_bar.message(
10411032
_("Session not reevaluated because saved file was blank")
@@ -1938,7 +1929,7 @@ def initialize_interp(self):
19381929

19391930
def getstdout(self):
19401931
"""
1941-
Returns a string of the current bpython session, formatted and wrapped.
1932+
Returns a string of the current bpython session, wrapped, WITH prompts.
19421933
"""
19431934
lines = self.lines_for_display + [self.current_line_formatted]
19441935
s = (

bpython/repl.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -821,18 +821,18 @@ def line_is_empty(line):
821821
indentation = 0
822822
return indentation
823823

824-
def formatforfile(self, session_ouput):
824+
def get_session_formatted_for_file(self):
825825
"""Format the stdout buffer to something suitable for writing to disk,
826826
i.e. without >>> and ... at input lines and with "# OUT: " prepended to
827-
output lines."""
827+
output lines and "### " prepended to current line"""
828828

829829
def process():
830830
for line, lineType in self.all_logical_lines:
831831
if lineType == LineTypeTranslator.INPUT:
832832
yield line
833833
elif line.rstrip():
834-
yield "# OUT: %s" % (line,)
835-
834+
yield "# OUT: %s" % line
835+
yield "###: %s" % self.current_line
836836
return "\n".join(process())
837837

838838
def write2file(self):
@@ -872,7 +872,7 @@ def write2file(self):
872872
self.interact.notify(_("Save cancelled."))
873873
return
874874

875-
stdout_text = self.formatforfile(self.getstdout())
875+
stdout_text = self.get_session_formatted_for_file()
876876

877877
try:
878878
with open(fn, mode) as f:
@@ -889,7 +889,7 @@ def copy2clipboard(self):
889889
self.interact.notify(_("No clipboard available."))
890890
return
891891

892-
content = self.formatforfile(self.getstdout())
892+
content = self.get_session_formatted_for_file()
893893
try:
894894
self.clipboard.copy(content)
895895
except CopyFailed:

0 commit comments

Comments
 (0)