blob: 9b22f08536425d83f73c5e98ae9b8eb7233b6cd6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
#!/usr/bin/env python3
# -*- python -*-
# mds — A micro-display server
# Copyright © 2014 Mattias Andrée (maandree@member.fsf.org)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import sys
import socket
import threading
import readline
display = os.environ['MDS_DISPLAY'] if 'MDS_DISPLAY' in os.environ else None
if (display is None) or (':' not in display):
print('MDS_DISPLAY has not set.')
sys.exit(1)
if not display.startswith(':'):
print('Remote mds sessions are not supported.')
sys.exit(1)
socket_path = '/run/mds/%s.socket' % display.split(':')[-1]
socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
socket.connect(socket_path)
def read_loop():
while True:
data = socket.recv(2048);
if not data:
break
sys.stdout.buffer.write(b'\033[34m');
sys.stdout.buffer.write(data);
sys.stdout.buffer.write(b'\033[00m');
sys.stdout.buffer.flush();
thread = threading.Thread(target = read_loop)
thread.setDaemon(True)
thread.start()
while True:
try:
data = (input() + '\n').encode('utf-8')
except:
break
socket.send(data);
socket.close()
|