diff -ur v2/ezpass.py v3/ezpass.py --- v2/ezpass.py 2023-07-09 12:27:46.601592416 +0900 +++ v3/ezpass.py 2023-07-15 13:38:54.431241842 +0900 @@ -3,6 +3,9 @@ import sys import os import pty +import termios +import struct +import fcntl import empty import yaml_ut @@ -10,6 +13,16 @@ sec = 1.5 +argv = sys.argv[ 1 : ] + +pw_msgs = [ ' password: ' ] + +k = '-pw_msg=' +for i in range( len( argv ) ): + if argv[ i ].startswith( k ): + s = argv.pop( i ) + pw_msgs.append( s[ len( k ) : ] ) + def b_to_s( b ): try: s = b.decode() @@ -39,10 +52,22 @@ dic = dic_new() +def get_wsz( fd ): + pfmt = 'HHHH' + wsz = struct.pack( pfmt, 0, 0, 0, 0 ) + wsz = fcntl.ioctl( fd, termios.TIOCGWINSZ, wsz ) + ( rows, cols, xpix, ypix ) = struct.unpack( pfmt, wsz ) + return ( cols, rows ) + +def set_wsz( fd, cols, rows ): + pfmt = 'HHHH' + wsz = struct.pack( pfmt, rows, cols, 0, 0 ) + fcntl.ioctl( fd, termios.TIOCSWINSZ, wsz ) + def buf_new(): e = empty.new() e.bf = '' - e.tmrs = [] + e.wsz=None def put( s ): if s.endswith( '\n' ): @@ -52,19 +77,28 @@ e.bf += s def key_in( s ): - if e.bf.endswith( ' password: ' ): - dic.put( e.bf, s ) + for pw_msg in pw_msgs: + if e.bf.endswith( pw_msg ): + dic.put( e.bf, s ) + break def get(): return e.bf def read( fd ): + if e.wsz is None: + set_sz( fd ) + b = os.read( fd, 1024 ) s = b_to_s( b ) if s: put( s ) return b + def set_sz( fd ): + ( cols, rows ) = e.wsz = get_wsz( sys.stdout.fileno() ) + set_wsz( fd, cols, rows ) + return empty.add( e, locals() ) buf = buf_new() @@ -100,8 +134,6 @@ ibuf = ibuf_new() -argv = sys.argv[ 1 : ] - if not argv: argv = [ 'bash' ]