#!/usr/bin/env python
#

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

from __future__ import absolute_import, print_function

import os
import sys

from optparse import OptionParser

try:
    import gterm
except ImportError:
    import graphterm.bin.gterm as 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(parser.get_usage(), file=sys.stderr)
    sys.exit(1)

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

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