Example #1
0
        private void textBoxText_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                var cmd = textBoxText.Text;
                textBoxText.Text = "";
                if (cmd == "connect")
                {
                    DoConnect();
                    return;
                }
                if (this.client.State != SocketState.Connected)
                {
                    this.Log("请先连接网络");
                    return;
                }

                DoSend(cmd);
            }
            else if (e.KeyCode == Keys.Up)
            {
                string str;
                if (CommandHistory.TryLoadFormer(out str))
                {
                    textBoxText.Text = str;
                }
            }
            else if (e.KeyCode == Keys.Down)
            {
                string str;
                if (CommandHistory.TryLoadLatter(out str))
                {
                    textBoxText.Text = str;
                }
            }
            if (e.KeyCode == Keys.Tab)
            {
                var hintResult = AutoComplete.GetHint(textBeforeHint, textHintIndex++);
                if (hintResult != "")
                {
                    isAutoComplete             = true;
                    textBoxText.Text           = hintResult;
                    textBoxText.SelectionStart = textBoxText.Text.Length;
                    isAutoComplete             = false;
                }

                e.Handled = true;
            }
        }
Example #2
0
        private void DoSend(string cmd)
        {
            Log(string.Format("[{0:HH:mm:ss}] > {1}", DateTime.Now, cmd), Color.LightGreen);

            //包含重定向符号
            string writeFilePath = "";

            if (cmd.Contains(">"))
            {
                var index = cmd.IndexOf(">");
                writeFilePath = cmd.Substring(index + 1).Trim();
                cmd           = cmd.Substring(0, index);
            }

            CommandAgent.SetCommand(cmd, writeFilePath);
            this.client.Send(System.Text.Encoding.UTF8.GetBytes(cmd + "\n"));

            CommandHistory.Save(cmd);

            Application.DoEvents();
        }