void Return_InBlock() { if (InputLine == "") { ProcessInput(blockText); blockText = ""; inBlock = false; } else { blockText += "\n" + InputLine; string whiteSpace = null; if (auto_indent) { System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(@"^(\s+).*"); whiteSpace = r.Replace(InputLine, "$1"); if (InputLine.EndsWith(BlockStart)) { whiteSpace += "\t"; } } Prompt(true, true); if (auto_indent) { InputLine += whiteSpace; } } }
bool ProcessKeyPressEvent(Gdk.EventKey ev) { // Short circuit to avoid getting moved back to the input line // when paging up and down in the shell output if (ev.Key == Gdk.Key.Page_Up || ev.Key == Gdk.Key.KP_Page_Up || ev.Key == Gdk.Key.Page_Down || ev.Key == Gdk.Key.KP_Page_Down) { return(false); } lock (m_Lock) { // Needed so people can copy and paste, but always end up // typing in the prompt. if (Cursor.Compare(InputLineBegin) < 0) { Buffer.MoveMark(Buffer.SelectionBound, InputLineEnd); Buffer.MoveMark(Buffer.InsertMark, InputLineEnd); } // if (ev.State == Gdk.ModifierType.ControlMask && ev.Key == Gdk.Key.space) // TriggerCodeCompletion (); if (ev.Key == Gdk.Key.Return || ev.Key == Gdk.Key.KP_Enter) { if (inBlock) { if (InputLine == "") { ProcessInput(blockText); blockText = ""; inBlock = false; } else { blockText += "\n" + InputLine; string whiteSpace = null; if (AutoIndent) { System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(@"^(\s+).*"); whiteSpace = r.Replace(InputLine, "$1"); if (InputLine.EndsWith(BlockStart)) { whiteSpace += "\t"; } } Prompt(true, true); if (AutoIndent) { InputLine += whiteSpace; } } } else { // Special case for start of new code block if (!string.IsNullOrEmpty(BlockStart) && InputLine.Trim().EndsWith(BlockStart)) { inBlock = true; blockText = InputLine; Prompt(true, true); if (AutoIndent) { InputLine += "\t"; } return(true); } // Bookkeeping if (InputLine != "") { // Everything but the last item (which was input), //in the future stack needs to get put back into the // past stack while (commandHistoryFuture.Count > 1) { commandHistoryPast.Push(commandHistoryFuture.Pop()); } // Clear the pesky junk input line commandHistoryFuture.Clear(); // Record our input line commandHistoryPast.Push(InputLine); if (scriptLines == "") { scriptLines += InputLine; } else { scriptLines += "\n" + InputLine; } ProcessInput(InputLine); } else { ProcessInput(null); } } return(true); } // The next two cases handle command history else if (ev.Key == Gdk.Key.Up || ev.Key == Gdk.Key.KP_Up) { if (!inBlock && commandHistoryPast.Count > 0) { if (commandHistoryFuture.Count == 0) { commandHistoryFuture.Push(InputLine); } else { if (commandHistoryPast.Count == 1) { return(true); } commandHistoryFuture.Push(commandHistoryPast.Pop()); } InputLine = commandHistoryPast.Peek(); } return(true); } else if (ev.Key == Gdk.Key.Down || ev.Key == Gdk.Key.KP_Down) { if (!inBlock && commandHistoryFuture.Count > 0) { if (commandHistoryFuture.Count == 1) { InputLine = commandHistoryFuture.Pop(); } else { commandHistoryPast.Push(commandHistoryFuture.Pop()); InputLine = commandHistoryPast.Peek(); } } return(true); } else if (ev.Key == Gdk.Key.Left || ev.Key == Gdk.Key.KP_Left) { // Keep our cursor inside the prompt area if (Cursor.Compare(InputLineBegin) <= 0) { return(true); } } else if (ev.Key == Gdk.Key.Home || ev.Key == Gdk.Key.KP_Home) { Buffer.MoveMark(Buffer.InsertMark, InputLineBegin); // Move the selection mark too, if shift isn't held if ((ev.State & Gdk.ModifierType.ShiftMask) == ev.State) { Buffer.MoveMark(Buffer.SelectionBound, InputLineBegin); } return(true); } else if (ev.Key == Gdk.Key.period) { return(false); } // Short circuit to avoid getting moved back to the input line // when paging up and down in the shell output else if (ev.Key == Gdk.Key.Page_Up || ev.Key == Gdk.Key.KP_Page_Up || ev.Key == Gdk.Key.Page_Down || ev.Key == Gdk.Key.KP_Page_Down) { return(false); } } return(false); }
bool ProcessReturn() { if (inBlock) { if (InputLine == "") { ProcessInput(blockText); blockText = ""; inBlock = false; } else { blockText += "\n" + InputLine; string whiteSpace = null; if (AutoIndent) { System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(@"^(\s+).*"); whiteSpace = r.Replace(InputLine, "$1"); if (InputLine.EndsWith(BlockStart, StringComparison.InvariantCulture)) { whiteSpace += "\t"; } } Prompt(true, true); if (AutoIndent) { InputLine += whiteSpace; } } } else { // Special case for start of new code block if (!string.IsNullOrEmpty(BlockStart) && InputLine.Trim().EndsWith(BlockStart, StringComparison.InvariantCulture)) { inBlock = true; blockText = InputLine; Prompt(true, true); if (AutoIndent) { InputLine += "\t"; } return(true); } // Bookkeeping if (InputLine != "") { // Everything but the last item (which was input), //in the future stack needs to get put back into the // past stack while (commandHistoryFuture.Count > 1) { commandHistoryPast.Push(commandHistoryFuture.Pop()); } // Clear the pesky junk input line commandHistoryFuture.Clear(); // Record our input line commandHistoryPast.Push(InputLine); if (scriptLines == "") { scriptLines += InputLine; } else { scriptLines += "\n" + InputLine; } ProcessInput(InputLine); } } return(true); }