add currentmodule back in myst form and remove click. additions
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by denuoweb · committed by denuoweb · parent 29eb946 · Browse files · 2 files·+25 added−19 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+25 added−19 removed
- other:+25 added−19 removed
Provenance
- Commit
bea2a2e- Tree
ded01d0- Author
denuoweb <jaron@rosenau.info>- Committer
denuoweb <jaron@rosenau.info>- Parent
29eb946
2 files changed+25 added−19 removed
modified:docs/unicode-support.md+3 added
123456793 unmodified lines```{currentmodule} click```
# Unicode Support
Click has to take extra care to support Unicode text in different environments.
93 unmodified linesmodified:docs/utils.md+22 added-19 removed
1+```{currentmodule} click2+```3+4 # Utilities5 6 Besides the functionality that Click provides to interface with argument parsing and handling, it also provides a bunch7 of addon functionality that is useful for writing command line utilities.8 9 ## Printing to Stdout10 8-The most obvious helper is the {func}`click.echo` function, which in many ways works like the Python `print` statement or11+The most obvious helper is the {func}`echo` function, which in many ways works like the Python `print` statement or12 function. The main difference is that it works the same in many different terminal environments.13 14 Example:15 9 unmodified lines25 ```python26 click.echo(b'\xe2\x98\x83', nl=False)27 ```28 26-Last but not least {func}`click.echo` uses click's intelligent internal output streams to stdout and stderr which support29+Last but not least {func}`echo` uses click's intelligent internal output streams to stdout and stderr which support30 unicode output on the Windows console. This means for as long as you are using `click.echo` you can output unicode31 characters (there are some limitations on the default font with regards to which characters can be displayed).32 33 ```{versionadded} 6.017 unmodified lines51 52 ```{versionadded} 2.053 ```54 52-The {func}`click.echo` function supports ANSI colors and styles. On Windows this uses [colorama].55+The {func}`echo` function supports ANSI colors and styles. On Windows this uses [colorama].56 57 Primarily this means that:58 56-- Click's {func}`click.echo` function will automatically strip ANSI color codes if the stream is not connected to a terminal.57-- the {func}`click.echo` function will transparently connect to the terminal on Windows and translate ANSI codes to terminal59+- Click's {func}`echo` function will automatically strip ANSI color codes if the stream is not connected to a terminal.60+- the {func}`echo` function will transparently connect to the terminal on Windows and translate ANSI codes to terminal61 API calls. This means that colors will work on Windows the same way they do on other operating systems.62 63 On Windows, Click uses colorama without calling `colorama.init()`. You can still call that in your code, but it's not64 required for Click.65 63-For styling a string, the {func}`click.style` function can be used:66+For styling a string, the {func}`style` function can be used:67 68 ```python69 import click70 1 unmodified line72 click.echo(click.style('Some more text', bg='blue', fg='white'))73 click.echo(click.style('ATTENTION', blink=True, bold=True))74 ```75 73-The combination of {func}`click.echo` and {func}`click.style` is also available in a single function called {func}`click.secho`:76+The combination of {func}`echo` and {func}`style` is also available in a single function called {func}`secho`:77 78 ```python79 click.secho('Hello World!', fg='green')80 click.secho('Some more text', bg='blue', fg='white')2 unmodified lines83 84 ## Pager Support85 86 In some situations, you might want to show long texts on the terminal and let a user scroll through it. This can be84-achieved by using the {func}`click.echo_via_pager` function which works similarly to the {func}`click.echo` function, but always87+achieved by using the {func}`echo_via_pager` function which works similarly to the {func}`echo` function, but always88 writes to stdout and, if possible, through a pager.89 90 Example:91 20 unmodified lines112 113 ```{versionadded} 2.0114 ```115 113-To clear the terminal screen, you can use the {func}`click.clear` function that is provided starting with Click 2.0. It does116+To clear the terminal screen, you can use the {func}`clear` function that is provided starting with Click 2.0. It does117 what the name suggests: it clears the entire visible screen in a platform-agnostic way:118 119 ```120 import click8 unmodified lines129 Normally, when reading input from the terminal, you would read from standard input. However, this is buffered input and130 will not show up until the line has been terminated. In certain circumstances, you might not want to do that and instead131 read individual characters as they are being written.132 130-For this, Click provides the {func}`click.getchar` function which reads a single character from the terminal buffer and133+For this, Click provides the {func}`getchar` function which reads a single character from the terminal buffer and134 returns it as a Unicode character.135 136 Note that this function will always read from the terminal, even if stdin is instead a pipe.137 25 unmodified lines163 164 Sometimes, it's useful to pause until the user presses any key on the keyboard. This is especially useful on Windows165 where `cmd.exe` will close the window at the end of the command execution by default, instead of waiting.166 164-In click, this can be accomplished with the {func}`click.pause` function. This function will print a quick message to the167+In click, this can be accomplished with the {func}`pause` function. This function will print a quick message to the168 terminal (which can be customized) and wait for the user to press a key. In addition to that, it will also become a NOP169 (no operation instruction) if the script is not run interactively.170 171 Example:7 unmodified lines179 180 ```{versionadded} 2.0181 ```182 180-Click supports launching editors automatically through {func}`click.edit`. This is very useful for asking users for multi-line183+Click supports launching editors automatically through {func}`edit`. This is very useful for asking users for multi-line184 input. It will automatically open the user's defined editor or fall back to a sensible default. If the user closes the185 editor without saving, the return value will be `None`, otherwise the entered text.186 187 Example usage:22 unmodified lines210 211 ```{versionadded} 2.0212 ```213 211-Click supports launching applications through {func}`click.launch`. This can be used to open the default application214+Click supports launching applications through {func}`launch`. This can be used to open the default application215 associated with a URL or filetype. This can be used to launch web browsers or picture viewers, for instance. In addition216 to this, it can also launch the file manager and automatically select the provided file.217 218 Example usage:6 unmodified lines225 ## Printing Filenames226 227 Because filenames might not be Unicode, formatting them can be a bit tricky.228 226-The way this works with click is through the {func}`click.format_filename` function. It does a best-effort conversion of the229+The way this works with click is through the {func}`format_filename` function. It does a best-effort conversion of the230 filename to Unicode and will never fail. This makes it possible to use these filenames in the context of a full Unicode231 string.232 233 Example:7 unmodified lines241 For command line utilities, it's very important to get access to input and output streams reliably. Python generally242 provides access to these streams through `sys.stdout` and friends, but unfortunately, there are API differences between243 2.x and 3.x, especially with regards to how these streams respond to Unicode and binary data.244 242-Because of this, click provides the {func}`click.get_binary_stream` and {func}`click.get_text_stream` functions, which produce245+Because of this, click provides the {func}`get_binary_stream` and {func}`get_text_stream` functions, which produce246 consistent results with different Python versions and for a wide variety of terminal configurations.247 248 The end result is that these functions will always return a functional stream object (except in very odd cases; see249 {doc}`/unicode-support`).17 unmodified lines267 268 ```{versionadded} 3.0269 ```270 268-Starting with Click 3.0 the logic for opening files from the {func}`click.File` type is exposed through the {func}`click.open_file`271+Starting with Click 3.0 the logic for opening files from the {func}`File` type is exposed through the {func}`open_file`272 function. It can intelligently open stdin/stdout as well as any other file.273 274 Example:275 18 unmodified lines294 ```295 296 Very often, you want to open a configuration file that belongs to your application. However, different operating systems297 store these configuration files in different locations depending on their standards. Click provides a295-{func}`click.get_app_dir` function which returns the most appropriate location for per-user config files for your application298+{func}`get_app_dir` function which returns the most appropriate location for per-user config files for your application299 depending on the OS.300 301 Example usage:302 17 unmodified lines320 ## Showing Progress Bars321 322 Sometimes, you have command line scripts that need to process a lot of data, but you want to quickly show the user some323 progress about how long that will take. Click supports simple progress bar rendering for that through the321-{func}`click.progressbar` function.324+{func}`progressbar` function.325 326 ```{note} If you find that you have requirements beyond what Click's progress bar supports, try using [tqdm].327 ```328 25 unmodified lines354 for user in bar:355 modify_the_user(user)356 ```357 355-Note that {func}`click.progressbar` updates the bar *after* each iteration of the loop. So code like this will render358+Note that {func}`progressbar` updates the bar *after* each iteration of the loop. So code like this will render359 correctly:360 361 ```python362 import time31 unmodified lines