blob: 22e58b4d1484b59aca57e7feb621eb4adefd92b3 [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
ichizok24714a12022-01-29 12:10:43 +00008import os
Bram Moolenaar6463ca22016-02-13 17:04:46 +01009import sys
Bram Moolenaarbbe8d912016-06-05 16:10:57 +020010import time
Bram Moolenaar6463ca22016-02-13 17:04:46 +010011
12if __name__ == "__main__":
13
14 if len(sys.argv) > 1:
Bram Moolenaarf65333c2016-03-08 18:27:21 +010015 if sys.argv[1].startswith("err"):
16 print(sys.argv[1], file=sys.stderr)
17 sys.stderr.flush()
Bram Moolenaar620ca2d2017-12-09 19:13:13 +010018 elif sys.argv[1].startswith("incomplete"):
19 print(sys.argv[1], end='')
20 sys.stdout.flush()
21 sys.exit(0)
Bram Moolenaar65240682019-02-10 22:23:26 +010022 elif sys.argv[1].startswith("busy"):
23 time.sleep(100)
24 sys.exit(0)
Bram Moolenaarf65333c2016-03-08 18:27:21 +010025 else:
26 print(sys.argv[1])
27 sys.stdout.flush()
Bram Moolenaarb2658a12016-04-26 17:16:24 +020028 if sys.argv[1].startswith("quit"):
29 sys.exit(0)
Bram Moolenaar6463ca22016-02-13 17:04:46 +010030
ichizok24714a12022-01-29 12:10:43 +000031 if os.getenv('CI'):
32 try:
33 import thread_util
34 thread_util.set_high_priority()
35 except Exception:
36 pass
37
Bram Moolenaar6463ca22016-02-13 17:04:46 +010038 while True:
39 typed = sys.stdin.readline()
Bram Moolenaar54ed0df2020-05-06 19:38:30 +020040 if typed == "": # EOF -- stop
41 break
Bram Moolenaar6463ca22016-02-13 17:04:46 +010042 if typed.startswith("quit"):
43 print("Goodbye!")
44 sys.stdout.flush()
45 break
Bram Moolenaarc25558b2016-03-03 21:02:23 +010046 if typed.startswith("echo "):
Bram Moolenaar6463ca22016-02-13 17:04:46 +010047 print(typed[5:-1])
48 sys.stdout.flush()
Bram Moolenaar88989cc2017-02-06 21:56:09 +010049 if typed.startswith("echosplit "):
50 for part in typed[10:-1].split('|'):
51 sys.stdout.write(part)
52 sys.stdout.flush()
53 time.sleep(0.05)
Bram Moolenaare98d1212016-03-08 15:37:41 +010054 if typed.startswith("double "):
Bram Moolenaar9a6e33a2016-02-16 19:25:12 +010055 print(typed[7:-1] + "\nAND " + typed[7:-1])
56 sys.stdout.flush()
Bram Moolenaarbbe8d912016-06-05 16:10:57 +020057 if typed.startswith("split "):
58 print(typed[6:-1], end='')
59 sys.stdout.flush()
60 time.sleep(0.05)
61 print(typed[6:-1], end='')
62 sys.stdout.flush()
63 time.sleep(0.05)
64 print(typed[6:-1])
65 sys.stdout.flush()
Bram Moolenaare98d1212016-03-08 15:37:41 +010066 if typed.startswith("echoerr "):
67 print(typed[8:-1], file=sys.stderr)
68 sys.stderr.flush()
69 if typed.startswith("doubleerr "):
70 print(typed[10:-1] + "\nAND " + typed[10:-1], file=sys.stderr)
71 sys.stderr.flush()
Bram Moolenaar24058382019-01-24 23:11:49 +010072 if typed.startswith("XXX"):
73 print(typed, end='')
74 sys.stderr.flush()
75 break
Bram Moolenaar6463ca22016-02-13 17:04:46 +010076