#!/usr/bin/env python
#

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

import os
import sys

from optparse import OptionParser

import gtermapi

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 gtermapi.Export_host:
    assert sys.stdin.isatty()

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