Skip to content
Merged
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 mycli/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Contributors:
* Daniel West
* Daniël van Eeden
* Fabrizio Gennari
* FatBoyXPC
* François Pietka
* Frederic Aoustin
* Georgy Frolov
Expand Down
4 changes: 4 additions & 0 deletions mycli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ def one_iteration(text=None):
return

special.set_expanded_output(False)
special.set_forced_horizontal_output(False)

try:
text = self.handle_editor_command(text)
Expand Down Expand Up @@ -743,6 +744,9 @@ def one_iteration(text=None):
else:
max_width = None

if special.forced_horizontal():
max_width = None

formatted = self.format_output(title, cur, headers, special.is_expanded_output(), max_width)

t = time() - start
Expand Down
9 changes: 9 additions & 0 deletions mycli/packages/special/iocommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

TIMING_ENABLED = False
use_expanded_output = False
force_horizontal_output = False
PAGER_ENABLED = True
tee_file = None
once_file = None
Expand Down Expand Up @@ -97,6 +98,14 @@ def set_expanded_output(val):
def is_expanded_output():
return use_expanded_output

@export
def set_forced_horizontal_output(val):
global force_horizontal_output
force_horizontal_output = val

@export
def forced_horizontal():
return force_horizontal_output

_logger = logging.getLogger(__name__)

Expand Down
6 changes: 6 additions & 0 deletions mycli/sqlexecute.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,12 @@ def run(self, statement):
if sql.endswith("\\G"):
special.set_expanded_output(True)
sql = sql[:-2].strip()
# \g is treated specially since we might want collapsed output when
# auto vertical output is enabled
elif sql.endswith('\\g'):
special.set_expanded_output(False)
special.set_forced_horizontal_output(True)
sql = sql[:-2].strip()

cur = self.conn.cursor()
try: # Special command
Expand Down
5 changes: 5 additions & 0 deletions test/test_sqlexecute.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ def test_favorite_query_expanded_output(executor):
results = run(executor, "\\fd test-ae")
assert_result_equal(results, status="test-ae: Deleted")

@dbtest
def test_collapsed_output_special_command(executor):
set_expanded_output(True)
results = run(executor, 'select 1\\g')
assert is_expanded_output() is False

@dbtest
def test_special_command(executor):
Expand Down
Loading