INNER CODE UNIT · Python

prefill_shell_cmd

gorilla-llm/gorilla-cli · go_cli.py:77

def prefill_shell_cmd(cmd):
    # Inspired from 
    stdin = 0
    # Save TTY attributes for stdin
    oldattr = termios.tcgetattr(stdin)
    # Create new attributes to fake input
    newattr = termios.tcgetattr(stdin)
    # Disable echo in stdin -> only inject cmd in stdin queue (with TIOCSTI)
    newattr[3] &= ~termios.ECHO
    # Enable non-canonical mode -> ignore special editing characters
    newattr[3] &= ~termios.ICANON
    # Use the new attributes
    termios.tcsetattr(stdin, termios.TCSANOW, newattr)
    # Write the selected command in stdin queue
    for c in cmd:
        fcntl.ioctl(stdin, termios.TIOCSTI, c)
    # Restore TTY attributes for stdin
    termios.tcsetattr(stdin, termios.TCSADRAIN, oldattr)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…