Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ TBD
Features
--------
* Deprecate reading configuration values from `my.cnf` files.
* Add `binary_display` configuration option.


Bug Fixes
Expand Down
8 changes: 7 additions & 1 deletion mycli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def __init__(
self.post_redirect_command = c['main'].get('post_redirect_command')
self.null_string = c['main'].get('null_string')
self.numeric_alignment = c['main'].get('numeric_alignment', 'right')
self.binary_display = c['main'].get('binary_display')

# set ssl_mode if a valid option is provided in a config file, otherwise None
ssl_mode = c["main"].get("ssl_mode", None)
Expand Down Expand Up @@ -888,6 +889,7 @@ def output_res(results: Generator[SQLResult], start: float) -> None:
special.is_redirected(),
self.null_string,
self.numeric_alignment,
self.binary_display,
max_width,
)

Expand Down Expand Up @@ -926,6 +928,7 @@ def output_res(results: Generator[SQLResult], start: float) -> None:
special.is_redirected(),
self.null_string,
self.numeric_alignment,
self.binary_display,
max_width,
)
self.echo("")
Expand Down Expand Up @@ -1404,6 +1407,7 @@ def run_query(
special.is_redirected(),
self.null_string,
self.numeric_alignment,
self.binary_display,
)
for line in output:
self.log_output(line)
Expand All @@ -1424,6 +1428,7 @@ def run_query(
special.is_redirected(),
self.null_string,
self.numeric_alignment,
self.binary_display,
)
for line in output:
click.echo(line, nl=new_line)
Expand All @@ -1440,6 +1445,7 @@ def format_output(
is_redirected: bool = False,
null_string: str | None = None,
numeric_alignment: str = 'right',
binary_display: str | None = None,
max_width: int | None = None,
) -> itertools.chain[str]:
if is_redirected:
Expand All @@ -1461,7 +1467,7 @@ def format_output(
if null_string is not None and default_kwargs.get('missing_value') == DEFAULT_MISSING_VALUE:
output_kwargs['missing_value'] = null_string

if use_formatter.format_name not in sql_format.supported_formats:
if use_formatter.format_name not in sql_format.supported_formats and binary_display != 'utf8':
# will run before preprocessors defined as part of the format in cli_helpers
output_kwargs["preprocessors"] = (preprocessors.convert_to_undecoded_string,)

Expand Down
5 changes: 5 additions & 0 deletions mycli/myclirc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ null_string = <null>
# How to align numeric data in tabular output: right or left.
numeric_alignment = right

# How to display binary values in tabular output: "hex", or "utf8". "utf8"
# means attempt to render valid UTF-8 sequences as strings, then fall back
# to hex rendering if not possible.
binary_display = hex

# A command to run after a successful output redirect, with {} to be replaced
# with the escaped filename. Mac example: echo {} | pbcopy. Escaping is not
# reliable/safe on Windows.
Expand Down
5 changes: 5 additions & 0 deletions test/myclirc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ null_string = <nope>
# How to align numeric data in tabular output: right or left.
numeric_alignment = right

# How to display binary values in tabular output: "hex", or "utf8". "utf8"
# means attempt to render valid UTF-8 sequences as strings, then fall back
# to hex rendering if not possible.
binary_display = hex

# A command to run after a successful output redirect, with {} to be replaced
# with the escaped filename. Mac example: echo {} | pbcopy. Escaping is not
# reliable/safe on Windows.
Expand Down