summaryrefslogtreecommitdiff
path: root/config/vim/plugin/pickachu/main.py
blob: d9a42b361f4a800c95052d8b4c6a0dd8eb4f1661 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import vim
from . import apps

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# name:        main.py
# description: This file evaluates the command arguments
#              provided by the user, calls the runApp function,
#              and inserts valid output to the user's buffer.
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

DEFAULT_APP = vim.eval('g:pickachu_default_app')


def MainFunction():
	# This section is for getting the
	# arguments from the user's Vim
	# command.
	arglength = int(vim.eval('a:0'))
	CHOOSEN_APP = DEFAULT_APP
	CHOOSEN_FORMAT = None
	if arglength > 0:
		CHOOSEN_APP = vim.eval('a:1')
	if arglength > 1:
		CHOOSEN_FORMAT = vim.eval('a:2')

	# We run apps.py's runApp function to get an output.
	output = apps.runApp(CHOOSEN_APP, CHOOSEN_FORMAT)

	# Now, if runApp gave us an output, we can use the
	# Vim API to print the output to the user's buffer.
	if output:
		pos_y, pos_x = vim.current.window.cursor
		vim.current.line = vim.current.line[:pos_x+1] + output + vim.current.line[pos_x+1:]
		vim.current.window.cursor = (pos_y, pos_x + len(output))
	else:
		print('Pickachu - Canceled')