Skip to content

Commit cb656a6

Browse files
committed
Add collapsed output special command
It's sometimes annoying to have auto_vertical_output enabled in myclirc and end up wanting to have the output not be expanded. The current workaround for this is to modify the setting in the rc file and restart mycli (or start a new session).
1 parent 284eb7e commit cb656a6

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

mycli/main.py

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

676676
special.set_expanded_output(False)
677+
special.set_forced_horizontal_output(False)
677678

678679
try:
679680
text = self.handle_editor_command(text)
@@ -743,6 +744,9 @@ def one_iteration(text=None):
743744
else:
744745
max_width = None
745746

747+
if special.forced_horizontal():
748+
max_width = None
749+
746750
formatted = self.format_output(title, cur, headers, special.is_expanded_output(), max_width)
747751

748752
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)