Handle negotiation of terminal type
971123
private void handleNegotiation() throws IOException {
        if (telnetCommand.contains(new String(new byte[] { TERMINAL_TYPE }))) {
            //  IAC SB TERMINAL_TYPE IS XXX IAC SE
            boolean isSuccess = false;
            clientTerminalType = telnetCommand.substring(4, telnetCommand.length() - 2);
            for (String terminalType : terminalTypeMapping.keySet()) {
                if (clientTerminalType.contains(terminalType)) {
                    isSuccess = true;
                    clientTerminalType = terminalType;
                    echoPrompt();
                    break;
                }
            }
            if (!isSuccess) {
                socketChannel.write(ByteBuffer.wrap("TerminalType negotiate failed.".getBytes()));
                throw new RuntimeException("TerminalType negotiate failed.");
            }
        }
    }
521624
def to_iruby
      available_terminals = {
        'png'      => 'image/png',
        'pngcairo' => 'image/png',
        'jpeg'     => 'image/jpeg',
        'svg'      => 'image/svg+xml',
        'dumb'     => 'text/plain'
      }
      terminal, options = term.is_a?(Array) ? [term[0], term[1]] : [term, {}]
      terminal = 'svg' unless available_terminals.keys.include?(terminal)
      [available_terminals[terminal], send("to_#{terminal}".to_sym, **options)]
    end
427890
def handle(self, pkt, raddress, rport):
        """"""
        if isinstance(pkt, TftpPacketDAT):
            return self.handleDat(pkt)

        # Every other packet type is a problem.
        elif isinstance(pkt, TftpPacketACK):
            # Umm, we ACK, you don't.
            self.sendError(TftpErrors.IllegalTftpOp)
            raise TftpException("Received ACK from peer when expecting DAT")

        elif isinstance(pkt, TftpPacketWRQ):
            self.sendError(TftpErrors.IllegalTftpOp)
            raise TftpException("Received WRQ from peer when expecting DAT")

        elif isinstance(pkt, TftpPacketERR):
            self.sendError(TftpErrors.IllegalTftpOp)
            raise TftpException("Received ERR from peer: " + str(pkt))

        else:
            self.sendError(TftpErrors.IllegalTftpOp)
            raise TftpException("Received unknown packet type from peer: " + str(pkt))
986678
def mt_interact(self):
        """"""
        import _thread
        _thread.start_new_thread(self.listener, ())
        while 1:
            line = sys.stdin.readline()
            if not line:
                break
            self.write(line)
719864
def _handle_type(self, other):
        """"""
        if isinstance(other, Int):
            return Int
        elif isinstance(other, Float):
            return Float
        else:
            raise TypeError(
                f"Unsuported operation between `{type(self)}` and `{type(other)}`."
            )
732267
function(value) {
    this.terminal._caretChange = Caret.NO_CHANGE;

    return this.requisition.update(value).then(function(updated) {
      // Abort UI changes if this UI update has been overtaken
      if (!updated) {
        return RESOLVED;
      }
      this.textChanged();
      return this.terminal.unsetChoice();
    }.bind(this));
  }
1081963
def handle_options(argv) # :nodoc:
      set_default_options

      OptionParser.new do |opts|
        opts.banner = "#{Rake.application.name} [-f rakefile] {options} targets..."
        opts.separator ""
        opts.separator "Options are ..."

        opts.on_tail("-h", "--help", "-H", "Display this help message.") do
          puts opts
          exit
        end

        standard_rake_options.each { |args| opts.on(*args) }
        opts.environment("RAKEOPT")
      end.parse(argv)
    end
835298
def terminal(self, out=None, border=None):
        
        for qrcode in self:
            qrcode.terminal(out=out, border=border)
1204341
function snapToTerminal(terminal)
		{
			if (terminal != null)
			{
				snapToPoint.call(this, new mxPoint(view.getRoutingCenterX(terminal),
						view.getRoutingCenterY(terminal)));
			}
		}
654231
def interact(title, description, prompt, binary, options):
    """"""
    args = [binary]
    p = subprocess.Popen(args=args,
                         stdin=subprocess.PIPE,
                         stdout=subprocess.PIPE,
                         env=os.environ)
    p.args = args  # TODO: remove after Python 2 deprecation.
    expect(p, [b'OK'])

    title = util.assuan_serialize(title.encode('ascii'))
    write(p, b'SETTITLE ' + title + b'\n')
    expect(p, [b'OK'])

    if description:
        description = util.assuan_serialize(description.encode('ascii'))
        write(p, b'SETDESC ' + description + b'\n')
        expect(p, [b'OK'])

    if prompt:
        prompt = util.assuan_serialize(prompt.encode('ascii'))
        write(p, b'SETPROMPT ' + prompt + b'\n')
        expect(p, [b'OK'])

    log.debug('setting %d options', len(options))
    for opt in options:
        write(p, b'OPTION ' + opt + b'\n')
        expect(p, [b'OK', b'ERR'])

    write(p, b'GETPIN\n')
    pin = expect(p, [b'OK', b'D '], confidential=True)

    p.communicate()  # close stdin and wait for the process to exit
    exit_code = p.wait()
    if exit_code:
        raise subprocess.CalledProcessError(exit_code, binary)

    return pin.decode('ascii').strip()
413341
def handle(send, msg, args):
    """"""
    output = textutils.gen_xkcd_sub(msg, True)
    if output is None:
        return
    if args['type'] == 'action':
        send("correction: * %s %s" % (args['nick'], output))
    else:
        send("%s actually meant: %s" % (args['nick'], output))
1025134
def process_non_terminals(index)
      seq = ""

      index.chop.chars.each do |char|
        seq << char

        if @map.has_key?(seq) && @map[seq]
          fail MiniTermKME, "Ambiguous entry #{index.inspect}"
        end

        @map[seq] = false
      end
    end
287114
private void handleCommand(byte b) throws IOException {
        if (b == SE) {
            telnetCommand += (char) b;
            handleNegotiation();
            reset();
        } else if (isWill || isDo) {
            if (isWill && b == TERMINAL_TYPE) {
                socketChannel
                    .write(ByteBuffer.wrap(new byte[] { IAC, SB, TERMINAL_TYPE, ECHO, IAC, SE }));
            } else if (b != ECHO && b != GA && b != NAWS) {
                telnetCommand += (char) b;
                socketChannel.write(ByteBuffer.wrap(telnetCommand.getBytes()));
            }
            reset();
        } else if (isWont || isDont) {
            telnetCommand += (char) b;
            socketChannel.write(ByteBuffer.wrap(telnetCommand.getBytes()));
            reset();
        } else if (isSb) {
            telnetCommand += (char) b;
        }
    }
17806
def ask_input(self, prompt):
        """"""
        self._vim.command('call inputsave()')
        self._vim.command('let user_input = input("{} ")'.format(prompt))
        self._vim.command('call inputrestore()')
        response = self._vim.eval('user_input')
        self._vim.command('unlet user_input')
        return response
161248
def handleOACK(self, pkt):
        """"""
        if len(pkt.options.keys()) > 0:
            if pkt.match_options(self.context.options):
                log.info("Successful negotiation of options")
                # Set options to OACK options
                self.context.options = pkt.options
                for key in self.context.options:
                    log.info("    %s = %s" % (key, self.context.options[key]))
            else:
                log.error("Failed to negotiate options")
                raise TftpException("Failed to negotiate options")
        else:
            raise TftpException("No options found in OACK")
555598
def negotiate_forced_aspect(self, options, accepts):
        """"""
        if not options:
            return None

        priorities = {}

        for i, o in enumerate(options):
            p = accepts.get(o, None)
            if p is None:
                p = accepts.get("*", None)
            if p is not None:
                # Prevent that a priority of 0 mess with the order of options
                priorities[o] = max(p, 0.000001) * (1 - i * 0.1 / len(options))

        if not priorities:
            return None

        order = priorities.keys()
        order.sort(key=priorities.get)
        return order[::-1]
1160633
def _handle_unknown_command(self):
        
        while self.query_socket.getsockopt(zmq.RCVMORE):
            # Making sure we 'empty' enveloped message. Otherwise, we can't
            # respond.
            self.query_socket.recv()
        self.query_socket.send(b"ERROR Unknown request type")