Skip to content

Commit 1965569

Browse files
Added support for ANSI colors only.
- Added --ansicolor option. - Check PROMPT_TOOLKIT_ANSI_COLORS_ONLY environment variable.
1 parent 77463d8 commit 1965569

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

pymux/client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,19 @@ def run_command(self, command, pane_id=None):
5959
'pane_id': pane_id
6060
})
6161

62-
def attach(self, detach_other_clients=False, true_color=False):
62+
def attach(self, detach_other_clients=False, ansi_colors_only=False, true_color=False):
6363
"""
6464
Attach client user interface.
6565
"""
6666
assert isinstance(detach_other_clients, bool)
67+
assert isinstance(ansi_colors_only, bool)
6768
assert isinstance(true_color, bool)
6869

6970
self._send_size()
7071
self._send_packet({
7172
'cmd': 'start-gui',
7273
'detach-others': detach_other_clients,
74+
'ansi-colors-only': ansi_colors_only,
7375
'true-color': true_color,
7476
'term': os.environ.get('TERM', ''),
7577
'data': ''

pymux/entry_points/run_pymux.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
pymux: Pure Python terminal multiplexer.
44
Usage:
55
pymux [(standalone|start-server|attach)] [-d]
6-
[--truecolor] [(-S <socket>)] [(-f <file>)]
6+
[--truecolor] [--ansicolor] [(-S <socket>)] [(-f <file>)]
77
[(--log <logfile>)]
88
[--] [<command>]
99
pymux list-sessions
@@ -48,6 +48,8 @@ def run():
4848
filename = a['<file>']
4949
command = a['<command>']
5050
true_color = a['--truecolor']
51+
ansi_colors_only = a['--ansicolor'] or \
52+
bool(os.environ.get('PROMPT_TOOLKIT_ANSI_COLORS_ONLY', False))
5153

5254
# Parse pane_id from socket_name. It looks like "socket_name,pane_id".
5355
if socket_name and ',' in socket_name:
@@ -76,7 +78,7 @@ def run():
7678
logging.basicConfig(filename=a['<logfile>'], level=logging.DEBUG)
7779

7880
if a['standalone']:
79-
mux.run_standalone(true_color=true_color)
81+
mux.run_standalone(true_color=true_color, ansi_colors_only=ansi_colors_only)
8082

8183
elif a['list-sessions'] or a['<command>'] in ('ls', 'list-sessions'):
8284
for c in list_clients():
@@ -107,12 +109,14 @@ def run():
107109
if socket_name:
108110
Client(socket_name).attach(
109111
detach_other_clients=detach_other_clients,
110-
true_color=true_color)
112+
true_color=true_color,
113+
ansi_colors_only=ansi_colors_only)
111114
else:
112115
# Connect to the first server.
113116
for c in list_clients():
114117
c.attach(detach_other_clients=detach_other_clients,
115-
true_color=true_color)
118+
true_color=true_color,
119+
ansi_colors_only=ansi_colors_only)
116120
break
117121
else: # Nobreak.
118122
print('No pymux instance found.')
@@ -132,7 +136,8 @@ def run():
132136
# daemon. (Otherwise the `waitpid` call won't work.)
133137
mux.run_server()
134138
else:
135-
Client(socket_name).attach(true_color=true_color)
139+
Client(socket_name).attach(
140+
true_color=true_color, ansi_colors_only=ansi_colors_only)
136141

137142
else:
138143
if socket_name_from_env:

pymux/server.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,14 @@ def _process(self, data):
8888
elif packet['cmd'] == 'start-gui':
8989
detach_other_clients = bool(packet['detach-others'])
9090
true_color = bool(packet['true-color'])
91+
ansi_colors_only = bool(packet['ansi-colors-only'])
9192
term = packet['term']
9293

9394
if detach_other_clients:
9495
for c in self.pymux.connections:
9596
c.detach_and_close()
9697

97-
self._create_cli(true_color=true_color, term=term)
98+
self._create_cli(true_color=true_color, ansi_colors_only=ansi_colors_only, term=term)
9899

99100
def _send_packet(self, data):
100101
"""
@@ -126,14 +127,15 @@ def _run_command(self, packet):
126127
finally:
127128
self._close_cli()
128129

129-
def _create_cli(self, true_color=False, term='xterm'):
130+
def _create_cli(self, true_color=False, ansi_colors_only=False, term='xterm'):
130131
"""
131132
Create CommandLineInterface for this client.
132133
Called when the client wants to attach the UI to the server.
133134
"""
134135
output = Vt100_Output(_SocketStdout(self._send_packet),
135136
lambda: self.size,
136137
true_color=true_color,
138+
ansi_colors_only=ansi_colors_only,
137139
term=term,
138140
write_binary=False)
139141
input = _ClientInput(self._send_packet)

0 commit comments

Comments
 (0)