Skip to content

Commit fd49dba

Browse files
authored
Merge pull request #1198 from FatBoyXPC/add-collapsed-output-to-special-commands
Add collapsed output special command
2 parents 1f34a49 + 421b07e commit fd49dba

File tree

5 files changed

+25
-0
lines changed

5 files changed

+25
-0
lines changed

mycli/AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Contributors:
3232
* Daniel West
3333
* Daniël van Eeden
3434
* Fabrizio Gennari
35+
* FatBoyXPC
3536
* François Pietka
3637
* Frederic Aoustin
3738
* Georgy Frolov

mycli/main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,7 @@ def one_iteration(text=None):
676676
return
677677

678678
special.set_expanded_output(False)
679+
special.set_forced_horizontal_output(False)
679680

680681
try:
681682
text = self.handle_editor_command(text)
@@ -745,6 +746,9 @@ def one_iteration(text=None):
745746
else:
746747
max_width = None
747748

749+
if special.forced_horizontal():
750+
max_width = None
751+
748752
formatted = self.format_output(title, cur, headers, special.is_expanded_output(), max_width)
749753

750754
t = time() - start

mycli/packages/special/iocommands.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
TIMING_ENABLED = False
2222
use_expanded_output = False
23+
force_horizontal_output = False
2324
PAGER_ENABLED = True
2425
tee_file = None
2526
once_file = None
@@ -97,6 +98,14 @@ def set_expanded_output(val):
9798
def is_expanded_output():
9899
return use_expanded_output
99100

101+
@export
102+
def set_forced_horizontal_output(val):
103+
global force_horizontal_output
104+
force_horizontal_output = val
105+
106+
@export
107+
def forced_horizontal():
108+
return force_horizontal_output
100109

101110
_logger = logging.getLogger(__name__)
102111

mycli/sqlexecute.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,12 @@ def run(self, statement):
298298
if sql.endswith("\\G"):
299299
special.set_expanded_output(True)
300300
sql = sql[:-2].strip()
301+
# \g is treated specially since we might want collapsed output when
302+
# auto vertical output is enabled
303+
elif sql.endswith('\\g'):
304+
special.set_expanded_output(False)
305+
special.set_forced_horizontal_output(True)
306+
sql = sql[:-2].strip()
301307

302308
cur = self.conn.cursor()
303309
try: # Special command

test/test_sqlexecute.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ def test_favorite_query_expanded_output(executor):
172172
results = run(executor, "\\fd test-ae")
173173
assert_result_equal(results, status="test-ae: Deleted")
174174

175+
@dbtest
176+
def test_collapsed_output_special_command(executor):
177+
set_expanded_output(True)
178+
results = run(executor, 'select 1\\g')
179+
assert is_expanded_output() is False
175180

176181
@dbtest
177182
def test_special_command(executor):

0 commit comments

Comments
 (0)