summaryrefslogtreecommitdiff
path: root/config/vim/plugin/pickachu/apps.py
blob: 00a68265372f5a1d98298bb329942de7a640e8f5 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import vim
import subprocess
from . import processors

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# name:        apps.py
# description: this function contains a dictionary object
#              where you can easily add new apps with processor
#              functions to handle their output. Note: a
#              processor is optional.
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

ZENITY_COMMAND = vim.eval("g:pickachu_default_command")
# Note: This is not the final date format that displays on
#       the users' buffer. This is the format we force
#       Zenity/Qarma to provide us.
RETURNED_DATE_FORMAT = "%m/%d/%Y"
if ZENITY_COMMAND == 'qarma':
	RETURNED_DATE_FORMAT = "MM/dd/yy"

apps = {
	'date': {
		'cmd': ZENITY_COMMAND,
		'processor': processors.dateProcessor,
		'options': [
			'--calendar',
			'--date-format=' + RETURNED_DATE_FORMAT
		]
	},
	'file': {
		'cmd': ZENITY_COMMAND,
		'options': [
            '--file-selection'
        ]
	},
	'color': {
		'cmd': ZENITY_COMMAND,
		'options': [
			'--color-selection'
    ],
		'processor': processors.colorProcessor
	}
}

def runApp(choosenApp, format=None):
	app = apps.get(choosenApp, None)
	if app:
		output = None
		try:
			command_array = [app['cmd']]
			if app.get('options', False):
				for option in app['options']:
					command_array.append(option)
			# Logging
			command_array.append('2> /tmp/pickachu_log')
			output = subprocess.check_output(command_array).decode('utf-8')
		except:
			return None

		if app.get('processor', None):
			if format:
				return app['processor'](output.rstrip(), format)
			else:
				return app['processor'](output.rstrip())
		else:
			return output.rstrip()
	else:
		print("App does not exist.")