#!/usr/bin/env python
#

"""
gvi: graphterm-aware visual editor
"""

import os
import sys

from optparse import OptionParser

import gterm

Work_dir = os.getenv("PWD", "") or os.getcwd()

usage = "usage: %prog [-e ace/ckeditor] filename"
parser = OptionParser(usage=usage)
parser.add_option("-e", "--editor", dest="editor", default="ace",
                  help="Editor: ace/ckeditor")

(options, args) = parser.parse_args()

if len(args) != 1:
    print >> sys.stderr, parser.get_usage()
    sys.exit(1)

if gterm.Export_host:
    assert sys.stdin.isatty()

gterm.edit_file(args[0], dir=Work_dir, create=True, editor=options.editor)
