public void OnAction(ConsoleAction action) { ConsoleOutput output = _input.Console.ConsoleOutput; switch (action) { case ConsoleAction.ExecuteCommand: string cmd = _input.Value; string executedCmd = cmd; if (output.HasCommandEntry) { executedCmd = output.DequeueCommandEntry() + cmd; } // Replace our tab symbols with actual tab characters. executedCmd = executedCmd.Replace(_input.Console.TabSymbol, "\t"); // Log the command to be executed if logger is set. LogInput?.Invoke(executedCmd); // Execute command. _input.Console.Interpreter.Execute(output, executedCmd); _input.Clear(); break; case ConsoleAction.NewLine: output.AddCommandEntry(_input.Value); _input.Clear(); break; } }
public ConsoleCommand(string name, ConsoleAction action) { CommandName = name; Action = action; Parameters = new IParameter[0]; ReturnMessage = DefaultReturnMessage; }
public void OnAction(ConsoleAction action) { switch (action) { case ConsoleAction.AutocompleteForward: _input.Console.Interpreter.Autocomplete(_input, true); break; case ConsoleAction.AutocompleteBackward: _input.Console.Interpreter.Autocomplete(_input, false); break; case ConsoleAction.ExecuteCommand: case ConsoleAction.Paste: case ConsoleAction.Cut: case ConsoleAction.Tab: case ConsoleAction.NewLine: ResetAutocompleteEntry(); break; case ConsoleAction.DeletePreviousChar: if (_input.Length > 0 && _input.Caret.Index > 0) { ResetAutocompleteEntry(); } break; case ConsoleAction.DeleteCurrentChar: if (_input.Length > _input.Caret.Index) { ResetAutocompleteEntry(); } break; } }
public void OnAction(ConsoleAction action) { switch (action) { case ConsoleAction.DeletePreviousChar: if (_input.Selection.HasSelection) { _input.Remove(_input.Selection.SelectionStart, _input.Selection.SelectionLength); } else if (_input.Length > 0 && _input.CaretIndex > 0) { _input.Remove(Math.Max(0, _input.CaretIndex - 1), 1); } break; case ConsoleAction.DeleteCurrentChar: if (_input.Selection.HasSelection) { _input.Remove(_input.Selection.SelectionStart, _input.Selection.SelectionLength); } else if (_input.Length > _input.CaretIndex) { _input.Remove(_input.CaretIndex, 1); } break; } }
public void OnAction(ConsoleAction action) { switch (action) { case ConsoleAction.MoveLeft: _input.Caret.MoveBy(-1); break; case ConsoleAction.MoveLeftWord: MoveToPreviousWord(); break; case ConsoleAction.MoveRight: _input.Caret.MoveBy(1); break; case ConsoleAction.MoveRightWord: MoveToNextWord(); break; case ConsoleAction.MoveToBeginning: _input.Caret.Index = 0; break; case ConsoleAction.MoveToEnd: _input.Caret.Index = _input.Length; break; } }
private void bgwExecuteQuery_ProgressChanged(object sender, ProgressChangedEventArgs e) { switch ((ConsoleAction)e.ProgressPercentage) { case ConsoleAction.ReadStart: tbInput.Text = null; tbInput.Enabled = true; btnXeqQuery.Enabled = false; grpInput.BackColor = Color.Red; tbInput.Focus(); break; case ConsoleAction.ReadEnd: tbInput.Enabled = false; btnXeqQuery.Enabled = true; grpInput.BackColor = tpInterpreter.BackColor; break; case ConsoleAction.ReadLn: readMode = ConsoleAction.ReadLn; break; case ConsoleAction.ReadCh: readMode = ConsoleAction.ReadCh; break; case ConsoleAction.Write: tbAnswer.AppendText(e.UserState as string); break; case ConsoleAction.WriteLn: tbAnswer.AppendText(e.UserState as string); break; case ConsoleAction.NewLn: tbAnswer.AppendText(Environment.NewLine); break; case ConsoleAction.Clear: tbAnswer.Clear(); break; case ConsoleAction.Reset: tbInput.Clear(); break; case ConsoleAction.BtnsOn: btnMore.Enabled = btnStop.Enabled = true; btnXeqQuery.Enabled = false; lblMoreOrStop.Visible = true; break; case ConsoleAction.BtnsOff: tbInput.Enabled = false; btnMore.Enabled = btnStop.Enabled = false; lblMoreOrStop.Visible = false; break; } }
public void Test_Action_For_NegativeTests_NotEndingQuotes_ShouldFail() { var action = new ConsoleAction(typeof(ActionParameterTests).GetMethod("Action_With_MultipleParameters"), this); var inputString = ""; inputString = "-f \"file1.txt --k false"; Assert.ThrowsException <ArgumentException>(() => action.ParseParameters(inputString)); }
public void Test_Action_With_DateTimeParameter_ExplicitVariants_ShouldFail_With_DefaultVariant(params string[] parameters) { var inputString = string.Join(" ", parameters); var action = new ConsoleAction(typeof(ActionParameterTests).GetMethod("Action_With_DateTimeParameter_ExplicitVariants"), this); var res = action.ParseParameters(inputString); Assert.AreEqual(default(DateTime), res.value); }
public void Test_Action_With_StringParameter_ExplicitType_ExplicitDefaultValue(params string[] parameters) { var inputString = string.Join(" ", parameters); var action = new ConsoleAction(typeof(ActionParameterTests).GetMethod("Action_With_StringParameter_ExplicitType"), this); var res = action.ParseParameters(inputString); Assert.AreEqual(typeof(string), res.file.GetType()); }
public static void Main(string[] args) { using var serviceProvider = ConfigureServices(); IStockService stockService = serviceProvider.GetService <IStockService>(); IExchangeService exchangeService = serviceProvider.GetService <IExchangeService>(); ConsoleAction consoleAction = new ConsoleAction(stockService, exchangeService); consoleAction.Start(); }
public void OnAction(ConsoleAction action) { switch (action) { case ConsoleAction.CapsLock: CheckKeysToggled(); break; } }
public void Test_Action_With_DateTimeParameter(params string[] parameters) { var action = new ConsoleAction(typeof(ActionParameterTests).GetMethod("Action_With_DateTimeParameter"), this); var inputString = string.Join(" ", parameters); var res = action.ParseParameters(inputString); Assert.AreEqual(DateTime.Parse(parameters[1].Trim('"')), res.value); Assert.AreEqual(typeof(DateTime), res.value.GetType()); }
public void Test_Action_With_DateTimeParameter_ExplicitVariants(params string[] parameters) { var inputString = string.Join(" ", parameters); var action = new ConsoleAction(typeof(ActionParameterTests).GetMethod("Action_With_DateTimeParameter_ExplicitVariants"), this); var res = action.ParseParameters(inputString); Assert.ThrowsException <RuntimeBinderException>(() => res.x); Assert.AreEqual(DateTime.Parse(parameters[1].Trim('"')), res.value); Assert.AreEqual(typeof(DateTime), res.value.GetType()); }
public void OnAction(ConsoleAction action) { string cmd = _input.Value; switch (action) { case ConsoleAction.ExecuteCommand: case ConsoleAction.NewLine: // If the cmd matches the currently indexed historical entry then set a special flag // which when moving backward in history, does not actually move backward, but will instead // return the same entry that was returned before. This is similar to how Powershell and Cmd Prompt work. if (_inputHistory.Count == 0 || _inputHistoryIndexer == int.MaxValue || !_inputHistory[_inputHistoryIndexer].Equals(cmd)) { _inputHistoryIndexer = int.MaxValue; } else { _inputHistoryDoNotDecrement = true; } // Find the last historical entry if any. string lastHistoricalEntry = null; if (_inputHistory.Count > 0) { lastHistoricalEntry = _inputHistory[_inputHistory.Count - 1]; } // Only add current command to input history if it is not an empty string and // does not match the last historical entry. if (cmd != "" && !cmd.Equals(lastHistoricalEntry, StringComparison.Ordinal)) { _inputHistory.Add(cmd); } break; case ConsoleAction.PreviousCommandInHistory: if (!_inputHistoryDoNotDecrement) { _inputHistoryIndexer--; } ManageHistory(); break; case ConsoleAction.NextCommandInHistory: _inputHistoryIndexer++; ManageHistory(); break; case ConsoleAction.AutocompleteForward: case ConsoleAction.AutocompleteBackward: _inputHistoryIndexer = int.MaxValue; break; } }
public void Test_Action_With_StringParameter_ExplicitDefaultValue_Default() { var action = new ConsoleAction(typeof(ActionParameterTests).GetMethod("Action_With_StringParameter_ExplicitDefaultValue"), this); var res1 = action.ParseParameters(""); Assert.AreEqual("test", res1.file); var res2 = action.ParseParameters("-x something"); Assert.AreEqual("test", res2.file); }
public void ProcessAction(ConsoleAction action) { InputHistory.OnAction(action); Autocompletion.OnAction(action); CopyPasting.OnAction(action); Movement.OnAction(action); Tabbing.OnAction(action); Deletion.OnAction(action); CommandExecution.OnAction(action); CaseSenitivity.OnAction(action); }
public void Test_Action_With_DateTimeParameter_ExplicitDefaultValue_Default() { var action = new ConsoleAction(typeof(ActionParameterTests).GetMethod("Action_With_DateTimeParameter_ExplicitDefaultValue"), this); var res1 = action.ParseParameters(""); Assert.AreEqual(new DateTime(2020, 01, 01), res1.value); var res2 = action.ParseParameters("-x something"); Assert.AreEqual(new DateTime(2020, 01, 01), res2.value); }
public void Test_Action_With_DecimalParameter_Default() { var action = new ConsoleAction(typeof(ActionParameterTests).GetMethod("Action_With_DecimalParameter"), this); var res1 = action.ParseParameters(""); Assert.AreEqual(default(decimal), res1.value); var res2 = action.ParseParameters("-x something"); Assert.AreEqual(default(decimal), res2.value); }
public void OnAction(ConsoleAction action) { switch (action) { case ConsoleAction.Tab: _input.Append(_input.Console.TabSymbol); break; case ConsoleAction.RemoveTab: RemoveTab(); break; } }
public void Test_Action_For_NegativeTests_MultipleSameParameter_ShouldFail() { var action = new ConsoleAction(typeof(ActionParameterTests).GetMethod("Action_With_MultipleParameters"), this); var inputString = ""; inputString = "-f file1.txt --file anotherfile.txt"; Assert.ThrowsException <ArgumentException>(() => action.ParseParameters(inputString)); //TODO - shouldn't be able to send -f twice. Current code picks up first one. Should be a bug.... but is it???? //inputString = "-f file1.txt -f anotherfile.txt"; //Assert.ThrowsException<ArgumentException>(() => action.ParseParameters(inputString)); }
private ConsoleAction readMode; // for distinguishing between various ways of reading input public DiagnosticConsole() { InitializeComponent(); Text = "Prolog diagnostic console"; stop = null; semaGetInput = new ManualResetEvent(false); charBuffer = new Queue <int>(); winIO = new WinIO(this, charBuffer); bgwExecuteQuery.ReportProgress((int)ConsoleAction.BtnsOff); service = new LogicService(winIO); readMode = ConsoleAction.None; }
public void Test_Action_For_NegativeTests_ParameterConvertError_ShouldFail() { var action = new ConsoleAction(typeof(ActionParameterTests).GetMethod("Action_With_MultipleParameters"), this); var inputString = ""; inputString = "-f \"file1.txt --k notbool"; Assert.ThrowsException <ArgumentException>(() => action.ParseParameters(inputString)); inputString = "-f \"file1.txt --r notint"; Assert.ThrowsException <ArgumentException>(() => action.ParseParameters(inputString)); inputString = "-f \"file1.txt --m nodouble"; Assert.ThrowsException <ArgumentException>(() => action.ParseParameters(inputString)); }
public void Test_Action_With_MultipleParameters(params string[] parameters) { var inputString = string.Join(" ", parameters); var action = new ConsoleAction(typeof(ActionParameterTests).GetMethod("Action_With_MultipleParameters"), this); var res = action.ParseParameters(inputString); Assert.AreEqual(parameters[1].Trim('"'), res.file); Assert.AreEqual(typeof(string), res.file.GetType()); Assert.AreEqual(bool.Parse(parameters[3].Trim('"')), res.keepOpen); Assert.AreEqual(typeof(bool), res.keepOpen.GetType()); Assert.AreEqual(int.Parse(parameters[5].Trim('"')), res.recordsToRead); Assert.AreEqual(typeof(int), res.recordsToRead.GetType()); Assert.AreEqual(double.Parse(parameters[7].Trim('"')), res.maxMemory); Assert.AreEqual(typeof(double), res.maxMemory.GetType()); }
public void OnAction(ConsoleAction action) { switch (action) { case ConsoleAction.Cut: if (_input.Selection.HasSelection) { Native.SetClipboardText(_input.Selection.SelectionValue); _input.Remove(_input.Selection.SelectionStart, _input.Selection.SelectionLength); } break; case ConsoleAction.Copy: if (_input.Selection.HasSelection) { Native.SetClipboardText(_input.Selection.SelectionValue); } break; case ConsoleAction.Paste: // Clear any selected input. if (_input.Selection.HasSelection) { _input.Remove(_input.Selection.SelectionStart, _input.Selection.SelectionLength); } string clipboardVal = Native.GetClipboardText().Replace("\n", _input.Console.NewlineSymbol); clipboardVal = clipboardVal.Replace("\t", _input.Console.TabSymbol); _singleElementArray[0] = _input.Console.NewlineSymbol; string[] newlineSplits = clipboardVal.Split(_singleElementArray, StringSplitOptions.None); if (newlineSplits.Length > 1) { for (int i = 0; i < newlineSplits.Length - 1; i++) { string entry = newlineSplits[i]; if (i == 0) { entry = _input.Substring(0, _input.Caret.Index) + entry; } _input.Console.ConsoleOutput.AddCommandEntry(entry); } _input.Remove(0, _input.Caret.Index); } _input.Append(newlineSplits[newlineSplits.Length - 1]); break; } }
internal bool AreModifiersAppliedForAction(ConsoleAction action, InputState input) { bool modifiersAccepted = false; List <Int3> requiredModifiers; if (_map.BackwardTryGetValues(action, out requiredModifiers)) { foreach (Int3 modifiers in requiredModifiers) { var modifier1 = (Keys)modifiers.X; var modifier2 = (Keys)modifiers.Y; modifiersAccepted = modifiersAccepted || (modifier1 == Keys.None || input.IsKeyDown(modifier1)) && (modifier2 == Keys.None || input.IsKeyDown(modifier2)); } } return(modifiersAccepted); }
public void Test_Action_With_MultipleParameters_MoreCases() { var action = new ConsoleAction(typeof(ActionParameterTests).GetMethod("Action_With_MultipleParameters"), this); dynamic res = null; var inputString = ""; inputString = "-f file1.txt -k false -r 2000 -m 2.4"; res = action.ParseParameters(inputString); Assert.AreEqual(typeof(string), res.file.GetType()); Assert.AreEqual(typeof(bool), res.keepOpen.GetType()); Assert.AreEqual(typeof(int), res.recordsToRead.GetType()); Assert.AreEqual(typeof(double), res.maxMemory.GetType()); Assert.AreEqual("file1.txt", res.file); Assert.AreEqual(false, res.keepOpen); Assert.AreEqual(2000, res.recordsToRead); Assert.AreEqual(2.4, res.maxMemory); inputString = "--file file1.txt"; res = action.ParseParameters(inputString); Assert.AreEqual(typeof(string), res.file.GetType()); Assert.AreEqual(typeof(bool), res.keepOpen.GetType()); Assert.AreEqual(typeof(int), res.recordsToRead.GetType()); Assert.AreEqual(typeof(double), res.maxMemory.GetType()); Assert.AreEqual("file1.txt", res.file); Assert.AreEqual(true, res.keepOpen); Assert.AreEqual(1000, res.recordsToRead); Assert.AreEqual(1.5, res.maxMemory); inputString = "-f \"file1 with space.txt\" -k false -r 2000 -m 2.4"; res = action.ParseParameters(inputString); Assert.AreEqual(typeof(string), res.file.GetType()); Assert.AreEqual(typeof(bool), res.keepOpen.GetType()); Assert.AreEqual(typeof(int), res.recordsToRead.GetType()); Assert.AreEqual(typeof(double), res.maxMemory.GetType()); Assert.AreEqual("file1 with space.txt", res.file); Assert.AreEqual(false, res.keepOpen); Assert.AreEqual(2000, res.recordsToRead); Assert.AreEqual(2.4, res.maxMemory); }
internal bool TryGetAction(InputState input, out ConsoleAction action) { foreach (Keys key in input.PressedKeys) { // First look for actions with two modifiers. foreach (Keys modifier1 in input.DownKeys) { foreach (Keys modifier2 in input.DownKeys) { if (_map.ForwardTryGetValue(new Int3((int)modifier1, (int)modifier2, (int)key), out action)) { return(true); } } } // Then look for actions with one modifier. foreach (Keys modifier in input.DownKeys) { if (_map.ForwardTryGetValue(new Int3((int)Keys.None, (int)modifier, (int)key), out action)) { return(true); } } } // If not found; look for actions without modifiers. foreach (Keys key in input.PressedKeys) { if (_map.ForwardTryGetValue(new Int3((int)Keys.None, (int)Keys.None, (int)key), out action)) { return(true); } } action = default(ConsoleAction); return(false); }
// Use this for initialization void Start() { FieldInit(); vvIO.vvConsole.setConsoleParent(this); goals_ = GameObject.FindGameObjectsWithTag("goal"); redTile2_ = new Vector3(-1.5f, 0.9f, -1.063f); redTile1_ = new Vector3(-1.5f, 0.9f, -0.415f); blueTile2_ = new Vector3(1.5f, 0.9f, -1.063f); blueTile1_ = new Vector3(1.5f, 0.9f, -0.415f); Transform selectedBot = clawbot; cmdTable_["match-load"] = new ConsoleAction(matchLoad); switch(scr_.robotType) { case 0: selectedBot = clawbot; break; case 1: selectedBot = tu_roller; break; } switch (scr_.startTile) { case 0: selectedBot.position = redTile1_; selectedBot.eulerAngles = new Vector3(0, 90, 0); break; case 1: selectedBot.position = blueTile1_; selectedBot.eulerAngles = new Vector3(0, -90, 0); break; case 2: selectedBot.position = redTile2_; selectedBot.eulerAngles = new Vector3(0, 90, 0); break; case 3: selectedBot.position = blueTile2_; selectedBot.eulerAngles = new Vector3(0, -90, 0); break; } robot_ = Instantiate(selectedBot); }
public void Action(ConsoleAction action) { _isStandardAction = true; switch (action) { case ConsoleAction.CopySelectionOrExit: if (HasSelection) { CopySelectionToClipboard(); } else { Exit(); } break; case ConsoleAction.Exit: Exit(); break; case ConsoleAction.CursorLeft: MoveLeft(false); break; case ConsoleAction.CursorRight: MoveRight(false); break; case ConsoleAction.CursorLeftWord: MoveLeft(true); break; case ConsoleAction.CursorRightWord: MoveRight(true); break; case ConsoleAction.CursorStartOfLine: Begin(); break; case ConsoleAction.CursorEndOfLine: End(); break; case ConsoleAction.HistoryPrevious: GoHistory(false); break; case ConsoleAction.HistoryNext: GoHistory(true); break; case ConsoleAction.DeleteCharacterLeft: Backspace(false); _stackIndex = -1; _hasShift = false; break; case ConsoleAction.DeleteCharacterLeftAndCopy: break; case ConsoleAction.DeleteCharacterRight: Delete(false); _stackIndex = -1; _hasShift = false; break; case ConsoleAction.DeleteCharacterRightAndCopy: break; case ConsoleAction.DeleteWordLeft: Backspace(true); _stackIndex = -1; _hasShift = false; break; case ConsoleAction.DeleteWordRight: Delete(true); _stackIndex = -1; _hasShift = false; break; case ConsoleAction.Completion: break; case ConsoleAction.DeleteTextRightAndCopy: break; case ConsoleAction.DeleteWordRightAndCopy: break; case ConsoleAction.DeleteWordLeftAndCopy: break; case ConsoleAction.CopySelection: CopySelectionToClipboard(); break; case ConsoleAction.CutSelection: CopySelectionToClipboard(); RemoveSelection(); break; case ConsoleAction.PasteClipboard: PasteClipboard(); break; case ConsoleAction.ValidateLine: Enter(false); break; case ConsoleAction.ForceValidateLine: Enter(true); break; default: throw new ArgumentOutOfRangeException(nameof(action), action, $"Invalid action {action}"); } }
public void Test_Action_With_MultipleParameters() { var action = new ConsoleAction(typeof(ActionTests).GetMethod("Action_With_MultipleParameters"), this); Assert.IsNotNull(action); }
public void Console(string Message) { ConsoleAction?.Invoke(Message); }
void Start() { FieldInit(); vvIO.vvConsole.setConsoleParent(this); cmdTable_["gates-down"] = new ConsoleAction(gatesDown); cmdTable_["doubler"] = new ConsoleAction(Doubler); cmdTable_["negator"] = new ConsoleAction(Negator); cmdTable_["match-load"] = new ConsoleAction(matchLoad); redGate = GameObject.Find("redGate"); blueGate = GameObject.Find("blueGate"); goals = GameObject.FindGameObjectsWithTag("goal"); Transform selectedBot = clawbot; switch (scr_.robotType) { case 0: selectedBot = clawbot; break; case 1: selectedBot = conv; break; case 2: selectedBot = nz; break; case 3: selectedBot = vertical; break; case 4: selectedBot = dbot; break; } switch (scr_.startTile) { case 0: selectedBot.position = new Vector3(-1.5f, 0.77f, 0.3f); selectedBot.eulerAngles = new Vector3(0, 90, 0); break; case 1: selectedBot.position = new Vector3(1.5f, 0.77f, 0.3f); selectedBot.eulerAngles = new Vector3(0, -90, 0); break; case 2: selectedBot.position = new Vector3(-0.88f, 0.77f, -1.47f); selectedBot.eulerAngles = new Vector3(0, 0, 0); break; case 3: selectedBot.position = new Vector3(0.88f, 0.77f, -1.47f); selectedBot.eulerAngles = new Vector3(0, 0, 0); break; } robot_ = Instantiate(selectedBot); }