예제 #1
0
파일: outline.py 프로젝트: baverman/vial
    def on_select(self, item, cursor):
        focus_window(self.last_window)
        mark()

        item = item[0]
        if 'offset' in item:
            line = vfunc.byte2line(item['offset'] + 1)
        else:
            line = item['line']

        vim.command('normal! {}Gzz'.format(line))
예제 #2
0
파일: outline.py 프로젝트: solarnz/vial
    def on_select(self, item, cursor):
        focus_window(self.last_window)
        mark()

        item = item[0]
        if 'offset' in item:
            line = vfunc.byte2line(item['offset'] + 1)
        else:
            line = item['line']

        vim.command('normal! {}Gzz'.format(line))
예제 #3
0
파일: plugin.py 프로젝트: baverman/vial
def escape():
    if len(vim.windows) < 2:
        return

    cur = vfunc.winnr()

    for n, w in reversed(list(enumerate(vim.windows, 1))):
        if not buffer_with_file(w.buffer):
            if not '[Command Line]'in w.buffer.name:
                focus_window(n)
            vim.command('q')
            if n != cur:
                if cur > n:
                    cur -= 1

                focus_window(cur)

            return
예제 #4
0
def escape():
    if len(vim.windows) < 2:
        return

    cur = vfunc.winnr()

    for n, w in reversed(list(enumerate(vim.windows, 1))):
        if not buffer_with_file(w.buffer):
            if not '[Command Line]' in w.buffer.name:
                focus_window(n)
            vim.command('q')
            if n != cur:
                if cur > n:
                    cur -= 1

                focus_window(cur)

            return
예제 #5
0
def execute(mode):
    cbuf = vim.current.buffer
    cwin = vim.current.window
    if mode == 0: # paragraph
        start = cbuf.mark('{')[0]
        stop = cbuf.mark('}')[0]
    elif mode == 1: # visual
        start = max(0, cbuf.mark('<')[0] - 1)
        stop = cbuf.mark('>')[0]
    else: # whole buffer
        start = 0
        stop = len(cbuf)

    input = '\n'.join(cbuf[start:stop])
    executable = cbuf[0].lstrip('#! ')
    with open('/tmp/vial-pipe-result.txt', 'wb') as f:
        Popen(executable, shell=True, stderr=f,
              stdout=f, stdin=PIPE).communicate(input)

    make_scratch('vial-pipe', title='Result')
    vim.command('norm! ggdG')
    vim.command('0read /tmp/vial-pipe-result.txt')
    focus_window(cwin)
예제 #6
0
 def on_cancel(self):
     focus_window(self.last_window)
예제 #7
0
 def on_select(self, item, cursor):
     focus_window(self.last_window)
     mark()
     vim.command('e {}'.format(item[2]))
예제 #8
0
def http():
    lines = vim.current.buffer[:]
    line, _ = vim.current.window.cursor
    line -= 1

    headers, templates = get_headers_and_templates(lines, line)
    pwd_func = lambda p: vfunc.inputsecret('{}: '.format(p))
    input_func = lambda p: vfunc.input('{}: '.format(p))
    try:
        method, url, query, body, tlist, rend = prepare_request(
            lines, line, headers, input_func, pwd_func)
    except PrepareException as e:
        echoerr(str(e))
        return

    rctx = RequestContext()
    rctx.request(method, url, query, body, headers)

    cwin = vim.current.window

    win, buf = make_scratch('__vial_http_req__', title='Request')
    rlines = rctx.raw_request.splitlines()

    hlines = []
    for r in rctx.history[:-1]:
        hlines.append(
            bstr('Redirect {} from {}'.format(r.status, r.request[1]),
                 'utf-8'))
    if hlines:
        hlines.append(b'----------------')

    buf[:] = hlines + rlines
    win.cursor = 1, 0

    win, buf = make_scratch('__vial_http_hdr__', title='Response headers')
    if PY2:
        buf[:] = [r.rstrip('\r\n') for r in rctx.response.msg.headers]
    else:
        buf[:] = [
            '{}: {}'.format(*r).encode('utf-8')
            for r in rctx.response.msg._headers
        ]

    win.cursor = 1, 0

    size = len(rctx.content)

    win, buf = make_scratch('__vial_http_raw__', title='Raw Response')
    buf[:] = rctx.content.splitlines()
    win.cursor = 1, 0

    if PY2:
        rcontent_type = rctx.response.msg.gettype()
    else:
        rcontent_type = rctx.response.msg.get_content_type()

    content, ctype, jdata = format_content(rcontent_type, rctx.content)

    win, buf = make_scratch('__vial_http__')
    win.options['statusline'] = 'Response: {} {} {}ms {}ms {}'.format(
        rctx.response.status, rctx.response.reason, rctx.ctime, rctx.rtime,
        sizeof_fmt(size))
    vim.command('set filetype={}'.format(ctype))
    buf[:] = content.splitlines(False)
    win.cursor = 1, 0

    focus_window(cwin)

    def set_cookies(*args):
        cookies = rctx.cookies
        args = args or sorted(cookies.keys())
        return 'Cookie: ' + ';'.join('{}={}'.format(k, cookies[k])
                                     for k in args)

    ctx = {
        'body': content,
        'json': jdata,
        'headers': Headers(rctx.response.getheaders()),
        'cookies': rctx.cookies,
        'rcookies': rctx.rcookies,
        'set_cookies': set_cookies
    }

    for t in tlist:
        if t in templates:
            lines = render_template(templates[t], **ctx).splitlines()
        else:
            lines = ['ERROR: template {} not found'.format(t)]
        vfunc.append(rend + 1, [''] + lines)
        rend += 1 + len(lines)
예제 #9
0
def http():
    lines = vim.current.buffer[:]
    line, _ = vim.current.window.cursor
    line -= 1

    headers, templates = get_headers_and_templates(lines, line)
    pwd_func = lambda p: vfunc.inputsecret('{}: '.format(p))
    input_func = lambda p: vfunc.input('{}: '.format(p))
    try:
        method, url, query, body, tlist, rend = prepare_request(lines, line, headers, input_func, pwd_func)
    except PrepareException as e:
        echoerr(str(e))
        return

    rctx = RequestContext()
    rctx.request(method, url, query, body, headers)

    cwin = vim.current.window

    win, buf = make_scratch('__vial_http_req__', title='Request')
    rlines = rctx.raw_request.splitlines()

    hlines = []
    for r in rctx.history[:-1]:
        hlines.append(bstr('Redirect {} from {}'.format(
            r.status, r.request[1]), 'utf-8'))
    if hlines:
        hlines.append(b'----------------')

    buf[:] = hlines + rlines
    win.cursor = 1, 0

    win, buf = make_scratch('__vial_http_hdr__', title='Response headers')
    if PY2:
        buf[:] = [r.rstrip('\r\n') for r in rctx.response.msg.headers]
    else:
        buf[:] = ['{}: {}'.format(*r).encode('utf-8') for r in rctx.response.msg._headers]

    win.cursor = 1, 0

    size = len(rctx.content)

    win, buf = make_scratch('__vial_http_raw__', title='Raw Response')
    buf[:] = rctx.content.splitlines()
    win.cursor = 1, 0

    if PY2:
        rcontent_type = rctx.response.msg.gettype()
    else:
        rcontent_type = rctx.response.msg.get_content_type()

    content, ctype, jdata = format_content(rcontent_type, rctx.content)

    win, buf = make_scratch('__vial_http__')
    win.options['statusline'] = 'Response: {} {} {}ms {}ms {}'.format(
        rctx.response.status, rctx.response.reason,
        rctx.ctime, rctx.rtime, sizeof_fmt(size))
    vim.command('set filetype={}'.format(ctype))
    buf[:] = content.splitlines(False)
    win.cursor = 1, 0

    focus_window(cwin)

    def set_cookies(*args):
        cookies = rctx.cookies
        args = args or sorted(cookies.keys())
        return 'Cookie: ' + ';'.join('{}={}'.format(k, cookies[k]) for k in args)

    ctx = {'body': content, 'json': jdata,
           'headers': Headers(rctx.response.getheaders()),
           'cookies': rctx.cookies,
           'rcookies': rctx.rcookies,
           'set_cookies': set_cookies}

    for t in tlist:
        if t in templates:
            lines = render_template(templates[t], **ctx).splitlines()
        else:
            lines = ['ERROR: template {} not found'.format(t)]
        vfunc.append(rend + 1, [''] + lines)
        rend += 1 + len(lines)
예제 #10
0
파일: outline.py 프로젝트: baverman/vial
 def on_cancel(self):
     focus_window(self.last_window)
예제 #11
0
 def on_select(self, item, cursor):
     focus_window(self.last_window)
     mark()
     vim.command('e {}'.format(item[2]))
예제 #12
0
 def on_select(self, item, cursor):
     focus_window(self.last_window)
     mark()
     vim.command('normal! {}Gzz^'.format(item[1]))
예제 #13
0
파일: plugin.py 프로젝트: baverman/vial
 def on_select(self, item, cursor):
     focus_window(self.last_window)
     mark()
     vim.command('normal! {}Gzz^'.format(item[1]))
예제 #14
0
 def reset(self):
     cwin = vim.current.window
     _, self.buf = make_scratch('__vial_pytest__', self.init, 'pytest')
     vim.command('normal! ggdG')
     focus_window(cwin)
     redraw()
예제 #15
0
def goto_file():
    filename, line = vfunc.expand('<cWORD>').split(':')[:2]
    for win in vim.windows:
        if vfunc.buflisted(win.buffer.number):
            focus_window(win)
            vim.command('e +{} {}'.format(line, filename))
예제 #16
0
def http():
    lines = vim.current.buffer[:]
    line, _ = vim.current.window.cursor
    line -= 1

    headers, templates = get_headers_and_templates(lines, line)
    pwd_func = lambda p: vfunc.inputsecret('{}: '.format(p))
    input_func = lambda p: vfunc.input('{}: '.format(p))
    try:
        method, url, query, body, tlist, rend = prepare_request(
            lines, line, headers, input_func, pwd_func)
    except PrepareException as e:
        echoerr(str(e))
        return

    u = urlparse.urlsplit(url)
    if not u.hostname:
        host = headers.pop('host', '')
        if not host.startswith('http://') and not host.startswith('https://'):
            host = 'http://' + host
        u = urlparse.urlsplit(host + url)

    path = u.path
    if u.query:
        path += '?' + u.query

    if query:
        path += ('&' if u.query else '?') + urllib.urlencode(query)

    if u.scheme == 'https':
        import ssl
        cn = httplib.HTTPSConnection(u.hostname,
                                     u.port or 443,
                                     timeout=CONNECT_TIMEOUT,
                                     context=ssl._create_unverified_context())
    else:
        cn = httplib.HTTPConnection(u.hostname,
                                    u.port or 80,
                                    timeout=CONNECT_TIMEOUT)

    cn = send_collector(cn)

    start = time.time()
    cn.connect()
    ctime = int((time.time() - start) * 1000)

    cn.sock.settimeout(READ_TIMEOUT)

    cn.request(method, path, body, headers)
    response = cn.getresponse()
    rtime = int((time.time() - start) * 1000)

    cwin = vim.current.window

    win, buf = make_scratch('__vial_http_req__', title='Request')
    buf[:] = cn._sdata.splitlines()
    win.cursor = 1, 0

    win, buf = make_scratch('__vial_http_hdr__', title='Response headers')
    if PY2:
        buf[:] = [r.rstrip('\r\n') for r in response.msg.headers]
    else:
        buf[:] = [
            '{}: {}'.format(*r).encode('utf-8') for r in response.msg._headers
        ]

    win.cursor = 1, 0

    content = response.read()
    size = len(content)

    win, buf = make_scratch('__vial_http_raw__', title='Raw Response')
    buf[:] = content.splitlines()
    win.cursor = 1, 0

    if PY2:
        rcontent_type = response.msg.gettype()
    else:
        rcontent_type = response.msg.get_content_type()

    content, ctype, jdata = format_content(rcontent_type, content)

    win, buf = make_scratch('__vial_http__')
    win.options['statusline'] = 'Response: {} {} {}ms {}ms {}'.format(
        response.status, response.reason, ctime, rtime, sizeof_fmt(size))
    vim.command('set filetype={}'.format(ctype))
    buf[:] = content.splitlines(False)
    win.cursor = 1, 0

    focus_window(cwin)

    cj = Cookie.SimpleCookie()
    if PY2:
        cheaders = response.msg.getheaders('set-cookie')
    else:
        cheaders = response.msg.get_all('set-cookie')
    for h in cheaders or []:
        cj.load(h)
    rcookies = {k: v.value for k, v in iteritems(cj)}
    cookies = {k: v.coded_value for k, v in iteritems(cj)}

    def set_cookies(*args):
        args = args or sorted(cookies.keys())
        return 'Cookie: ' + ';'.join('{}={}'.format(k, cookies[k])
                                     for k in args)

    ctx = {
        'body': content,
        'json': jdata,
        'headers': Headers(response.getheaders()),
        'cookies': cookies,
        'rcookies': rcookies,
        'set_cookies': set_cookies
    }

    for t in tlist:
        if t in templates:
            lines = render_template(templates[t], **ctx).splitlines()
        else:
            lines = ['ERROR: template {} not found'.format(t)]
        vfunc.append(rend + 1, [''] + lines)
        rend += 1 + len(lines)