code: def set_application(self, app, callback=None):
          
          assert isinstance(app, Application)
          assert callback is None or callable(callback)
  
          self.cli = CommandLineInterface(
              application=app,
              eventloop=self.eventloop,
              output=self.vt100_output)
          self.callback = callback
  
          # Create a parser, and parser callbacks.
          cb = self.cli.create_eventloop_callbacks()
          inputstream = InputStream(cb.feed_key)
  
          # Input decoder for stdin. (Required when working with multibyte
          # characters, like chinese input.)
          stdin_decoder_cls = getincrementaldecoder(self.encoding)
          stdin_decoder = [stdin_decoder_cls()]  # nonlocal
  
          # Tell the CLI that it's running. We don't start it through the run()
          # call, but will still want _redraw() to work.
          self.cli._is_running = True
  
          def data_received(data):
              """ TelnetProtocolParser 'data_received' callback """
              assert isinstance(data, binary_type)
  
              try:
                  result = stdin_decoder[0].decode(data)
                  inputstream.feed(result)
              except UnicodeDecodeError:
                  stdin_decoder[0] = stdin_decoder_cls()
                  return ''
  
          def size_received(rows, columns):
              """ TelnetProtocolParser 'size_received' callback """
              self.size = Size(rows=rows, columns=columns)
              cb.terminal_size_changed()
  
          self.parser = TelnetProtocolParser(data_received, size_received)
docs: Set ``CommandLineInterface`` instance for this connection.
          (This can be replaced any time.)
  
          :param cli: CommandLineInterface instance.
          :param callback: Callable that takes the result of the CLI.