Exemplo n.º 1
0
def cmd_edit(tl, args):
    """allows editing a given todo item
    
    :description: This action will open an editor. 
        If you're done editing, save the file and close the editor or cancel
        editing by pressing ``Ctrl+C``.
    
    * item: the index number of the item to edit
    """
    with ColorRenderer() as cr:
        if not args.item:
            open_editor(conf.todo_file)
            quit(0)
        item = tl.get_item_by_index(args.item)
        if not item:
            print("Could not find item '{item_id}'".format(item_id=args.item))
            return

        print(" ", cr.render(item))
        try:
            output = get_editor_input(item.text)
            # remove new lines
            edited_item = TodoItem(
                output.replace("\r\n", " ").replace("\n", " ").strip())
            tl.replace_item(item, edited_item)
            suppress_if_quiet(u"  {item}".format(item=cr.render(edited_item)),
                              args)
            edited_item.check()
        except KeyboardInterrupt:
            # editing has been aborted
            pass
Exemplo n.º 2
0
def cmd_edit(tl, args):
    """allows editing a given todo item
    
    :description: This action will open an editor. 
        If you're done editing, save the file and close the editor or cancel
        editing by pressing ``Ctrl+C``.
    
    * item: the index number of the item to edit
    """
    with ColorRenderer() as cr:
        if not args.item:
            open_editor(conf.todo_file)
            quit(0)
        item = tl.get_item_by_index(args.item)
        if not item:
            print("Could not find item '{item_id}'".format(item_id = args.item))
            return
        
        print(" ", cr.render(item))
        try:
            output = get_editor_input(item.text)
            # remove new lines
            edited_item = TodoItem(output.replace("\r\n", " ").replace("\n", " ").strip())
            tl.replace_item(item, edited_item)
            suppress_if_quiet(u"  {item}".format(item = cr.render(edited_item)), args)
            edited_item.check()
        except KeyboardInterrupt:
            # editing has been aborted
            pass
Exemplo n.º 3
0
def cmd_add(tl, args):
    """adds a new todo item to the todo list
    """
    with ColorRenderer() as cr:
        if not args.text:
            # no arguments given, open editor and let user enter data there
            output = get_editor_input("")
            item = tl.add_item(output.replace("\r\n", " ").replace("\n", " ").strip())
        elif isinstance(args.text, list):
            # string not enclosed in ""
            item = tl.add_item(" ".join(args.text))
        else:
            # single string 
            item = tl.add_item(args.text)
        msg = u"Added {item}".format(item = cr.render(item))
        suppress_if_quiet(msg, args)
        logger.debug(msg)
        item.check()
Exemplo n.º 4
0
def cmd_edit(tl, args):
    """allows editing a given todo item
    """
    with ColorRenderer() as cr:
        if not args.item:
            open_editor(conf.todo_file)
            quit(0)
        item = tl.get_item_by_index(args.item)
        if not item:
            print("Could not find item '{item_id}'".format(item_id = args.item))
            return
        
        print(" ", cr.render(item))
        try:
            output = get_editor_input(item.text)
            # remove new lines
            edited_item = TodoItem(output.replace("\r\n", " ").replace("\n", " ").strip())
            tl.replace_item(item, edited_item)
            suppress_if_quiet(u"  {item}".format(item = cr.render(edited_item)), args)
            edited_item.check()
        except KeyboardInterrupt:
            # editing has been aborted
            pass
Exemplo n.º 5
0
def cmd_add(tl, args):
    """adds a new todo item to the todo list
        
    :description: The source of the todo item can either be the command line or an editor.
    
    Required fields of :param:`args`:
    * text: the text of the todo item to add
    """
    with ColorRenderer() as cr:
        if not args.text:
            # no arguments given, open editor and let user enter data there
            output = get_editor_input("")
            item = tl.add_item(output.replace("\r\n", " ").replace("\n", " ").strip())
        elif isinstance(args.text, list):
            # string not enclosed in ""
            item = tl.add_item(" ".join(args.text))
        else:
            # single string 
            item = tl.add_item(args.text)
        msg = u"Added {item}".format(item = cr.render(item))
        suppress_if_quiet(msg, args)
        logger.debug(msg)
        item.check()
Exemplo n.º 6
0
def cmd_add(tl, args):
    """adds a new todo item to the todo list
        
    :description: The source of the todo item can either be the command line or an editor.
    
    Required fields of :param:`args`:
    * text: the text of the todo item to add
    """
    with ColorRenderer() as cr:
        if not args.text:
            # no arguments given, open editor and let user enter data there
            output = get_editor_input("")
            item = tl.add_item(
                output.replace("\r\n", " ").replace("\n", " ").strip())
        elif isinstance(args.text, list):
            # string not enclosed in ""
            item = tl.add_item(" ".join(args.text))
        else:
            # single string
            item = tl.add_item(args.text)
        msg = u"Added {item}".format(item=cr.render(item))
        suppress_if_quiet(msg, args)
        logger.debug(msg)
        item.check()