bin.interactive
¶
Module Contents¶
-
bin.interactive.
__email__
= martin@martineve.com[source]¶ A class to handle an interactive prompt.
Portions of this file are Copyright 2014, Adrian Sampson. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # “Software”), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software.
-
class
bin.interactive.
Interactive
(global_variables)[source]¶ Bases:
debug.Debuggable
-
input_options
(self, options, require=False, prompt=None, fallback_prompt=None, numrange=None, default=None, max_width=72)[source]¶ Prompts a user for input. The sequence of options defines the choices the user has. A single-letter shortcut is inferred for each option; the user’s choice is returned as that single, lower-case letter. The options should be provided as lower-case strings unless a particular shortcut is desired; in that case, only that letter should be capitalized.
By default, the first option is the default. default can be provided to override this. If require is provided, then there is no default. The prompt and fallback prompt are also inferred but can be overridden.
If numrange is provided, it is a pair of (high, low) (both ints) indicating that, in addition to options, the user may enter an integer in that inclusive range.
max_width specifies the maximum number of columns in the automatically generated prompt string.
-
input_
(self, prompt=None)[source]¶ Like raw_input, but decodes the result to a Unicode string. Raises a UserError if stdin is not available. The prompt is sent to stdout rather than stderr. A printed between the prompt and the input cursor.
-
_colorize
(self, color, text)[source]¶ Returns a string that prints the given text in the given color in a terminal that is ANSI color-aware. The color must be something in DARK_COLORS or LIGHT_COLORS.
-
colorize
(self, color, text)[source]¶ Colorize text if colored output is enabled. (Like _colorize but conditional.)
-
_colordiff
(self, a, b, highlight='red', minor_highlight='lightgray')[source]¶ Given two values, return the same pair of strings except with their differences highlighted in the specified color. Strings are highlighted intelligently to show differences; other values are stringified and highlighted in their entirety.
-
displayable_path
(self, path, separator='; ')[source]¶ Attempts to decode a bytestring path to a unicode object for the purpose of displaying it to the user. If the path argument is a list or a tuple, the elements are joined with separator.
-
_fsencoding
(self)[source]¶ Get the system’s filesystem encoding. On Windows, this is always UTF-8 (not MBCS).
-
colordiff
(self, a, b, highlight='red')[source]¶ Colorize differences between two values if color is enabled. (Like _colordiff but conditional.)
-
print_
(self, *strings)[source]¶ Like print, but rather than raising an error when a character is not in the terminal’s encoding’s character set, just silently replaces it.
-