@@ -6,21 +6,33 @@ Examples
6
6
7
7
``` python
8
8
import editor
9
- commit_msg = editor.edit(contents = " # Enter commit message here" )
9
+ commit_msg = editor.edit(contents = b " # Enter commit message here" )
10
10
```
11
+
11
12
Opens an editor, prefilled with the contents, ` # Enter commit message here ` .
12
- When the editor is closed, returns the contents in variable ` commit_msg ` .
13
+ When the editor is closed, returns the contents (bytes) in variable ` commit_msg ` .
14
+ Note that the argument to ` contents ` needs to be a bytes object on Python 3.
13
15
14
16
15
17
``` python
16
- import editor
17
18
editor.edit(file = " README.txt" )
18
19
```
19
- Opens README.txt in an editor. Changes are saved in place.
20
+
21
+ Opens README.txt in an editor. Changes are saved in place. If there is
22
+ a ` contents ` argument then the file contents will be overwritten.
23
+
24
+ ``` python
25
+ editor.edit(... , use_tty = True )
26
+ ```
27
+
28
+ Opens the editor in a TTY. This is usually done in programs which output is
29
+ piped to other programs. In this case the TTY is used as the editor's stdout,
30
+ allowing interactive usage.
20
31
21
32
22
33
How it Works
23
34
------------
35
+
24
36
` editor ` first looks for the ${EDITOR} environment variable. If set, it uses
25
37
the value as-is, without fallbacks.
26
38
@@ -33,5 +45,5 @@ For example, on Linux, `editor` will look for the following editors in order:
33
45
* emacs
34
46
* nano
35
47
36
- When calling the ` edit() ` function, ` editor ` will open the editor in a subprocess,
37
- inheriting the parent process's stdin, stdout
48
+ When calling ` editor. edit` , an editor will be opened in a subprocess, inheriting
49
+ the parent process's stdin, stdout.
0 commit comments