Skip to content
Myr

Merge pull request #114 from iKevinY/doc-fixes

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Documentation Fixes

authored by Armin Ronacher · committed by Armin Ronacher · parents e0ea94a, 24c01d5 · Browse files · 2 files+22 added−22 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+22 added−22 removed

  • other:+22 added−22 removed

2 files+22 added−22 removed

modified:docs/utils.rst+17 added-17 removed
10 unmodified lines
11Printing to Stdout12------------------1314The most obvious helper is the :func:`echo` function, which in many ways15works like the Python print statement or function. The main difference is15works like the Python ``print`` statement or function. The main difference is16that it works the same in Python 2 and 3, it intelligently detects17misconfigured output streams, and will never fail (except in Python 3; for17misconfigured output streams, and it will never fail (except in Python 3; for18more information see :ref:`python3-limitations`).1920Example::21
1 unmodified line
2324 click.echo('Hello World!')2526Most importantly, it can print both Unicode and binary data, unlike the27builtin ``print`` function in Python 3, which cannot output any bytes. It28will, however, emit a trailing newline by default which needs to be29supressed by passing ``nl=False``::27built-in ``print`` function in Python 3, which cannot output any bytes. It28will, however, emit a trailing newline by default, which needs to be29suppressed by passing ``nl=False``::3031 click.echo(b'\xe2\x98\x83', nl=False)3233
10 unmodified lines
44is installed, then ANSI codes are intelligently handled.4546Primarily this means that:4748- click's echo function will automatically strip ANSI color codes if the49 stream is not connected to a terminal.50- the echo function will transparently connect to the terminal on48- click's :func:`echo` function will automatically strip ANSI color codes49 if the stream is not connected to a terminal.50- the :func:`echo` function will transparently connect to the terminal on51 Windows and translate ANSI codes to terminal API calls. This means52 that colors will work on Windows the same way they do on other53 operating systems.54
3 unmodified lines
58To install `colorama`, run this command::5960 $ pip install colorama6162For styling a string the :func:`style` function can be used::62For styling a string, the :func:`style` function can be used::6364 import click6566 click.echo(click.style('Hello World!', fg='green'))67 click.echo(click.style('Some more text', bg='blue', fg='white'))68 click.echo(click.style('ATTENTION', blink=True))68 click.echo(click.style('ATTENTION', blink=True, bold=True))6970The combination of :func:`echo` and :func:`style` is also available in71a single function called :func:`secho`::7273 click.secho('Hello World!', fg='green')74 click.secho('Some more text', bg='blue', fg='white')75 click.secho('ATTENTION', blink=True)75 click.secho('ATTENTION', blink=True, bold=True)767778.. _colorama: https://pypi.python.org/pypi/colorama79
39 unmodified lines
119standard input. However, this is buffered input and will not show up until120the line has been terminated. In certain circumstances, you might not want121to do that and instead read individual characters as they are being written.122123For thi,s click provides the :func:`getchar` function which reads a single123For this, click provides the :func:`getchar` function which reads a single124character from the terminal buffer and returns it as a Unicode character.125126Note that this function will always read from the terminal, even if stdin127is instead a pipe.
14 unmodified lines
142143Note that this reads raw input, which means that things like arrow keys144will show up in the platform's native escape format. The only characters145translated are ``^C`` and ``^D`` which are converted into keyboard146interrupt and end of file exceptions. This is done because otherwise it's147too easy to forget about that and to create scripts that cannot be148properly exited.146interrupts and end of file exceptions respectively. This is done because147otherwise, it's too easy to forget about that and to create scripts that148cannot be properly exited.149150151Waiting for Key Press152---------------------
68 unmodified lines
221------------------222223Because filenames might not be Unicode, formatting them can be a bit224tricky. Generally, this is easier in Python 2 than on 3, as you can just225write the bytes to stdout with the print function, but in Python 3, you will226always need to operate in Unicode.225write the bytes to stdout with the ``print`` function, but in Python 3, you226will always need to operate in Unicode.227228The way this works with click is through the :func:`format_filename`229function. It does a best-effort conversion of the filename to Unicode and230will never fail. This makes it possible to use these filenames in the
106 unmodified lines
modified:README+5 added-5 removed
1$ click_23 click is a Python package for creating beautiful command line interfaces3 Click is a Python package for creating beautiful command line interfaces4 in a composable way with as little amount of code as necessary. It's the5 "Command Line Interface Creation Kit". It's highly configurable but comes6 with good defaults out of the box.78 It aims at making writing command line tools fun and quick without causing9 user frustration at not being able to implement an intended CLI API.8 It aims to make writing command line tools quick and fun without causing9 user frustration from the inability to implement a desired CLI API.1011 Click in three points:12 1213 - arbitrary nesting of commands14 - automatic help page generation15 - supports lazy loading of subcommands at runtime 15 - supports lazy loading of subcommands at runtime1617 Read the docs at http://click.pocoo.org/1819 This library is work in progress. Please give feedback!