blob: 5202908e7eddde861ed8e468d423f1617a78d554 [file] [log] [blame]
Bram Moolenaar6463ca22016-02-13 17:04:46 +01001#!/usr/bin/python
2#
3# Server that will communicate over stdin/stderr
4#
5# This requires Python 2.6 or later.
6
7from __future__ import print_function
8import sys
Bram Moolenaarbbe8d912016-06-05 16:10:57 +02009import time
Bram Moolenaar6463ca22016-02-13 17:04:46 +010010
11if __name__ == "__main__":
12
13 if len(sys.argv) > 1:
Bram Moolenaarf65333c2016-03-08 18:27:21 +010014 if sys.argv[1].startswith("err"):
15 print(sys.argv[1], file=sys.stderr)
16 sys.stderr.flush()
Bram Moolenaar620ca2d2017-12-09 19:13:13 +010017 elif sys.argv[1].startswith("incomplete"):
18 print(sys.argv[1], end='')
19 sys.stdout.flush()
20 sys.exit(0)
Bram Moolenaar65240682019-02-10 22:23:26 +010021 elif sys.argv[1].startswith("busy"):
22 time.sleep(100)
23 sys.exit(0)
Bram Moolenaarf65333c2016-03-08 18:27:21 +010024 else:
25 print(sys.argv[1])
26 sys.stdout.flush()
Bram Moolenaarb2658a12016-04-26 17:16:24 +020027 if sys.argv[1].startswith("quit"):
28 sys.exit(0)
Bram Moolenaar6463ca22016-02-13 17:04:46 +010029
30 while True:
31 typed = sys.stdin.readline()
Bram Moolenaar54ed0df2020-05-06 19:38:30 +020032 if typed == "": # EOF -- stop
33 break
Bram Moolenaar6463ca22016-02-13 17:04:46 +010034 if typed.startswith("quit"):
35 print("Goodbye!")
36 sys.stdout.flush()
37 break
Bram Moolenaarc25558b2016-03-03 21:02:23 +010038 if typed.startswith("echo "):
Bram Moolenaar6463ca22016-02-13 17:04:46 +010039 print(typed[5:-1])
40 sys.stdout.flush()
Bram Moolenaar88989cc2017-02-06 21:56:09 +010041 if typed.startswith("echosplit "):
42 for part in typed[10:-1].split('|'):
43 sys.stdout.write(part)
44 sys.stdout.flush()
45 time.sleep(0.05)
Bram Moolenaare98d1212016-03-08 15:37:41 +010046 if typed.startswith("double "):
Bram Moolenaar9a6e33a2016-02-16 19:25:12 +010047 print(typed[7:-1] + "\nAND " + typed[7:-1])
48 sys.stdout.flush()
Bram Moolenaarbbe8d912016-06-05 16:10:57 +020049 if typed.startswith("split "):
50 print(typed[6:-1], end='')
51 sys.stdout.flush()
52 time.sleep(0.05)
53 print(typed[6:-1], end='')
54 sys.stdout.flush()
55 time.sleep(0.05)
56 print(typed[6:-1])
57 sys.stdout.flush()
Bram Moolenaare98d1212016-03-08 15:37:41 +010058 if typed.startswith("echoerr "):
59 print(typed[8:-1], file=sys.stderr)
60 sys.stderr.flush()
61 if typed.startswith("doubleerr "):
62 print(typed[10:-1] + "\nAND " + typed[10:-1], file=sys.stderr)
63 sys.stderr.flush()
Bram Moolenaar24058382019-01-24 23:11:49 +010064 if typed.startswith("XXX"):
65 print(typed, end='')
66 sys.stderr.flush()
67 break
Bram Moolenaar6463ca22016-02-13 17:04:46 +010068