proc selectMenu {entry} {
  set last_row ""
  for {set i 0} {$i < 20} {incr i} {
    expect {
      -re {\e\[[01]m\e\[37m\e\[40m\e\[(\d+);\d+H([ -~]+)\e\[0m} {
        if {[regexp "$entry" "$expect_out(2,string)"]} {
          send "\r"
          return
        } else {
          if {"$expect_out(1,string)" != "$last_row"} {
            send "\033\[B"
            set last_row $expect_out(1,string)
          }
        }
      }
      -re {\e\[(\d+);\d+H[^;]*\e\[0m\e\[37m\e\[40m(\e\[\d+C)*([ -~]+)\e\[0m} {
        if {[regexp "$entry" "$expect_out(3,string)"]} {
          send "\r"
          return
        } else {
          if {"$expect_out(1,string)" != "$last_row"} {
            send "\033\[B"
            set last_row $expect_out(1,string)
          }
        }
      }
      eof {
        abort "VM terminates unexpectedly"
      }
      timeout {
        abort "Timeout"
      }
    }
  }
  abort "Cannot find $entry"
}
