File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change 3
3
4
4
from __future__ import print_function
5
5
6
+ import sys
6
7
import locale
7
8
import os .path
8
9
import subprocess
@@ -71,11 +72,20 @@ def get_editor():
71
72
"Please consider setting your %s variable" % get_platform_editor_var ())
72
73
73
74
74
- def edit (filename = None , contents = None ):
75
+ def get_tty_filename ():
76
+ if sys .platform == 'win32' :
77
+ return 'CON:'
78
+ return '/dev/tty'
79
+
80
+
81
+ def edit (filename = None , contents = None , use_tty = None ):
75
82
editor = get_editor ()
76
83
args = get_editor_args (os .path .basename (os .path .realpath (editor )))
77
84
args = [editor ] + args .split (' ' )
78
85
86
+ if use_tty is None :
87
+ use_tty = sys .stdin .isatty () and not sys .stdout .isatty ()
88
+
79
89
if filename is None :
80
90
tmp = tempfile .NamedTemporaryFile ()
81
91
filename = tmp .name
@@ -86,7 +96,11 @@ def edit(filename=None, contents=None):
86
96
87
97
args += [filename ]
88
98
89
- proc = subprocess .Popen (args , close_fds = True )
99
+ stdout = None
100
+ if use_tty :
101
+ stdout = open (get_tty_filename (), 'wb' )
102
+
103
+ proc = subprocess .Popen (args , close_fds = True , stdout = stdout )
90
104
proc .communicate ()
91
105
92
106
with open (filename , mode = 'rb' ) as f :
Original file line number Diff line number Diff line change
1
+ import sys
2
+ import editor
3
+
4
+ cont = editor .edit (contents = 'ABC!' ,
5
+ use_tty = 'use_tty' in sys .argv )
6
+ sys .stdout .write (cont )
You can’t perform that action at this time.
0 commit comments