コード例 #1
0
ファイル: container.py プロジェクト: Jorick/pynote
def get_note(data, key):
    try:
        note = data[key]
    except IndexError:
        echo_error('This note does not exist!')
        exit(1)
    return note
コード例 #2
0
ファイル: __main__.py プロジェクト: Jorick/pynote
def new(title):
    """Create a new note."""
    try:
        note = Note.create(title)
    except FileExistsError:
        echo_error('This note already exists!')
        exit(1)
    content = click.edit(note.content.decode(), editor=config.EDITOR)
    note.content = content.encode() if content else ''
コード例 #3
0
ファイル: container.py プロジェクト: Jorick/pynote
def load_notes(path=Path(config.DATA)):
    if path.exists():
        data = [Note(f) for f in path.iterdir()
                if f.is_file() and f.suffix not in config.IGNORE_EXTENSIONS]
        return sorted(data, key=lambda n: n.age)
    else:
        echo_error('Your data directory does not exist!')
        click.echo('Please create a data directory.')
        click.echo('You can do this with "mkdir {}".'.format(config.DATA))
        exit(1)
コード例 #4
0
ファイル: __main__.py プロジェクト: Jorick/pynote
def show(ctx, key, lang):
    """Show a specific note."""
    note = get_note(ctx.data, key)
    if lang and config.COLORS:
        content = highlight_(note.content.decode(), lang)
    elif lang and config.COLORS is False:
        echo_error('Color support is not enabled!')
        exit(1)
    else:
        content = note.content.decode()

    if ctx.no_header:
        output = content
    else:
        output = note.get_header() + '\n\n' + content

    echo(output, ctx.no_pager)