import re import sqlite3 import subprocess import tempfile from pyfzf.pyfzf import FzfPrompt from model import Model from bcolors import bcolors from screen import Screen class Task: def __init__(self): self.model = Model() self.fzf = FzfPrompt() self.screen = Screen() self.header = '' self.info = '' def search(self): tasks = [] tasksData = self.model.get_all_tasks() if not tasksData: self.add() tasksData = self.model.get_all_tasks() for t in tasksData: tasks.append('%s: %s [ %s ]' % (t['aid'], t['description'], t['tag_names'])) selected = self.fzf.prompt(tasks) if selected: m = re.search(r'^(.+):', selected[0]) aid = m.group(1) if aid: self.edit_task(aid) else: self.screen.add_fail('Task was not selected...') def add(self): self.screen.print_init('Adding task') description = input('Description: ') aid = self.model.create_task_draft(description) self.screen.add_message('task has been created') self.manage_task(aid) def manage_task(self, aid): task = self.model.get_task(aid) self.header = 'Managing task: [' + task['aid'] + '] ' + task['description'] long_term = ' ' if task['long_term'] and task['long_term'] != 'FALSE': long_term = 'x' tags = '' if task['tags']: tags = ' '.join([t['name'] for t in task['tags']]) self.info = '''%s Description: %s Tags: [%s] Long Term: [%s] Created: %s ''' % (task['aid'], task['description'], tags, long_term, task['created_at']) if task['done'] and task['done'] != 'FALSE': self.info += bcolors.ENDC + bcolors.OKGREEN + '\nFinished: ' + task['finished_at'] if task['active'] and task['active'] != 'FALSE': self.info += bcolors.ENDC + bcolors.WARNING + '\nACTIVE' self.manage_task_menu(aid) def manage_task_menu(self, aid): about = ''' Short instruction ----------------- ? - help (this dialog) e - edit content * - toggle long term + - add tag - - remove tag ! - toggle active v - toggle done x - delete task & - add child task > - go to child < - back q - exit ''' self.screen.change_path('~task', '?e*+-!v&>