//Key_Bind_f
        private void Bind_f(CommandMessage msg)
        {
            var c = msg.Parameters != null ? msg.Parameters.Length : 0;

            if (c != 1 && c != 2)
            {
                Host.Console.Print("bind <key> [command] : attach a command to a key\n");
                return;
            }

            var b = StringToKeynum(msg.Parameters[0]);

            if (b == -1)
            {
                Host.Console.Print($"\"{msg.Parameters[0]}\" isn't a valid key\n");
                return;
            }

            if (c == 1)
            {
                if (!String.IsNullOrEmpty(_Bindings[b]))    // keybindings[b])
                {
                    Host.Console.Print($"\"{msg.Parameters[0]}\" = \"{_Bindings[b]}\"\n");
                }
                else
                {
                    Host.Console.Print($"\"{msg.Parameters[0]}\" is not bound\n");
                }
                return;
            }

            // copy the rest of the command line
            // start out with a null string

            var args = String.Empty;

            if (msg.Parameters.Length > 1)
            {
                args = msg.ParametersFrom(1);
            }

            SetBinding(b, args);
        }
Exemple #2
0
        // Cmd_Alias_f
        // Creates a new command that executes a command string (possibly ; seperated)
        private void Alias_f(CommandMessage msg)
        {
            if (msg.Parameters == null || msg.Parameters?.Length == 0)
            {
                ConsoleWrapper.Print("Current alias commands:\n");

                foreach (var alias in this.Aliases)
                {
                    ConsoleWrapper.Print($"{alias.Key} : {alias.Value}\n");
                }

                return;
            }

            var name = msg.Parameters[0];

            if (name.Length >= CommandFactory.MAX_ALIAS_NAME)
            {
                ConsoleWrapper.Print("Alias name is too long\n");
                return;
            }

            var args = string.Empty;

            // copy the rest of the command line
            if (msg.Parameters.Length > 1)
            {
                args = msg.ParametersFrom(1);
            }

            if (this.Aliases.ContainsKey(name))
            {
                this.Aliases[name] = args;
            }
            else
            {
                this.Aliases.Add(name, args);
            }
        }