diff -ur v3/chat_conn.py v4/chat_conn.py --- v3/chat_conn.py 2019-08-13 12:57:29.000000000 +0900 +++ v4/chat_conn.py 2019-08-13 22:46:56.000000000 +0900 @@ -382,14 +382,14 @@ return e.to_attr( locals() ) -def client(host, port, name0, func_in, func_out): +def client(host, port, name0, cmd_io): cli = cli_new(host, port, name0) th_quit = threading.Event() def th_func(): rest = rest_new() while not th_quit.wait(0): - s = func_in() + s = cmd_io.func_in() if s == False: break if not s: @@ -407,15 +407,25 @@ if not r: continue (f, s) = r + ''' + if s.endswith(cli.name): + cmd_io.func_out_me( s[:len(cli.name)] ) if f: s = '{}> {}'.format(f, s) - func_out(s) + cmd_io.func_out(s) + ''' + cmd_io.func_out(f, s, cli.name) th_quit.set() th.join() cli.dis_conn() def cmd_io_new(cmd): + k = 'me:' + me_f = cmd.startswith(k) + if me_f: + cmd = cmd[len(k):] + que = queue.Queue() def func_in(): @@ -424,17 +434,25 @@ try: s = que.get(timeout=tmout) except: - s = None + pass elif readable(sys.stdin): s = sys.stdin.readline().strip() return s - def func_out(s): + def cmd_exec(s, cmd): + echo_cmd = 'echo "{}" | {}'.format(s, cmd) + ret = subprocess.check_output(echo_cmd, shell=True).decode('utf-8').strip() + if ret: + que.put(ret) + + def func_out(f, s, name): if cmd: - echo_cmd = 'echo "{}" | {}'.format(s, cmd) - ret = subprocess.check_output(echo_cmd, shell=True).decode('utf-8').strip() - if ret: - que.put(ret) + if me_f: + k = ' >' + name + if s.endswith(k): + cmd_exec( s[:-len(k)], cmd ) + else: + cmd_exec( '{}> {}'.format(f, s), cmd ) else: print(s) @@ -442,7 +460,8 @@ def help(v): ss = [ - 'Usage: {} [conn [] [host=] [cmd=]]'.format(sys.argv[0]), + 'Usage: {} [conn [] [host=] \\'.format(sys.argv[0]), + ' [cmd=[me:]]]', ' conn: client mode', ' user name: default "guest"', ' hostname: default "localhost"', @@ -473,5 +492,5 @@ name0 = pop('guest') cmd_io = cmd_io_new(cmd) - client(host, port, name0, cmd_io.func_in, cmd_io.func_out) + client(host, port, name0, cmd_io) # EOF