Coder Social home page Coder Social logo

python-editor's Introduction

python-editor is a library that provides the editor module for programmatically interfacing with your system's $EDITOR.

Examples

import editor
commit_msg = editor.edit(contents=b"# Enter commit message here")

Opens an editor, prefilled with the contents, # Enter commit message here. When the editor is closed, returns the contents (bytes) in variable commit_msg. Note that the argument to contents needs to be a bytes object on Python 3.

editor.edit(file="README.txt")

Opens README.txt in an editor. Changes are saved in place. If there is a contents argument then the file contents will be overwritten.

editor.edit(..., use_tty=True)

Opens the editor in a TTY. This is usually done in programs which output is piped to other programs. In this case the TTY is used as the editor's stdout, allowing interactive usage.

How it Works

editor first looks for the ${EDITOR} environment variable. If set, it uses the value as-is, without fallbacks.

If no $EDITOR is set, editor will search through a list of known editors, and use the first one that exists on the system.

For example, on Linux, editor will look for the following editors in order:

  • vim
  • emacs
  • nano

When calling editor.edit, an editor will be opened in a subprocess, inheriting the parent process's stdin, stdout.

python-editor's People

Contributors

fmoo avatar eugene-eeo avatar hugovk avatar chkumar246 avatar blag avatar elsonrodriguez avatar josh-gree avatar nackjicholson avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.