public void Recognize() { if (_promptExpression == null) { return; } if (_terminal.TerminalMode == TerminalMode.Application) { return; //アプリケーションモードは通知の必要なし } //一応、前回チェック時とデータ受信の有無をもらってくれば処理の簡略化は可能 TerminalDocument doc = _terminal.GetDocument(); GLine prompt_candidate = FindPromptCandidateLine(doc); if (prompt_candidate == null) { return; // too large command line } string prompt; string command; if (!DeterminePromptLine(prompt_candidate, doc.CurrentLine.ID, doc.CaretColumn, out prompt, out command)) //プロンプトではないとき { NotifyNotPromptLine(); } else { Debug.WriteLineIf(DebugOpt.PromptRecog, "Prompt " + command); NotifyPromptLine(prompt_candidate, prompt, command); } }
public void Init(AbstractTerminal terminal, IShellScheme scheme, string[] current_input, IntelliSenseMode mode, char append_char) { _ownerControl = terminal.TerminalHost.TerminalControl; Debug.Assert(_ownerControl != null); TerminalDocument doc = terminal.GetDocument(); _commandStartPoint = new Point(doc.CaretColumn + (append_char == '\0' ? 0 : 1), doc.CurrentLineNumber - doc.TopLineNumber); Debug.WriteLineIf(DebugOpt.IntelliSense, String.Format("IS CtxInit M={0} CaretC={1}", mode.ToString(), doc.CaretColumn)); _scheme = scheme; _currentInput = current_input; _intelliSenseMode = mode; Debug.Assert(_currentInput != null); _charQueue.LockedInit(append_char); _buffer.Remove(0, _buffer.Length); if (_intelliSenseMode == IntelliSenseMode.CharComplement) { string last_arg = current_input[current_input.Length - 1]; _buffer.Append(last_arg); _commandStartPoint.X -= last_arg.Length; } BuildCandidates(); }
private void TryParseMultiLineCommand() { GLine current = _terminal.GetDocument().CurrentLine; GLine command_start_candidate = current; IShellScheme scheme = GetTerminalSettings().ShellScheme; //ここちょっと落ち着かないので複数行はやめておく。 //たとえば、 // > user ***** // > Password: //みたいなやりとりをすると、原理的に複数行コマンドなのかは区別が付かない。全行の右のほうまでテキストが埋まっていることで判断するくらいだが、100%ではない int limit = 1; while (command_start_candidate != null && limit > 0) { string prompt; string command; if (_terminal.PromptRecognizer.DeterminePromptLine(command_start_candidate, current.ID, current.DisplayLength, out prompt, out command)) { if (command.Length > 0) { _context.UpdateCommandList(command); } } command_start_candidate = command_start_candidate.PrevLine; limit--; } }
//ポップアップ対象の行を集めて構築。ここは受信スレッドでの実行であることに注意 private void ProcessCommandResult(int end_line_id) { List <GLine> result = new List <GLine>(); TerminalDocument doc = _terminal.GetDocument(); GLine line = doc.FindLineOrNull(_commandStartLineID); while (line != null && line.ID <= end_line_id) { //Debug.WriteLine("P]"+new string(line.Text, 0, line.DisplayLength)); result.Add(line); line = line.NextLine; } //何かとれていたら実行 if (result.Count > 0) { _currentProcessor.EndCommand(result); } else { Debug.WriteLineIf(DebugOpt.CommandPopup, String.Format("Ignored for 0-length, start={0} end={1}", _commandStartLineID, end_line_id)); } _currentProcessor = null; }
private static void SessionEntryPoint(AbstractTerminal terminal, CommandResultDocument document) { try { TerminalControl tc = terminal.TerminalHost.TerminalControl; Debug.Assert(tc != null); RenderProfile rp = (RenderProfile)tc.GetRenderProfile().Clone(); CommandResultSession session = new CommandResultSession(document, rp); //現在のRenderProfileを使ってセッションを作る TerminalDocument terminaldoc = terminal.GetDocument(); PopupViewCreationParam cp = new PopupViewCreationParam(_viewFactory); //結果のサイズに合わせる。ただし高さは20行を上限とする cp.InitialSize = new Size(tc.ClientSize.Width, (int)(RuntimeUtil.AdjustIntRange(document.Size, 0, 20) * rp.Pitch.Height) + 2); cp.OwnedByCommandTargetWindow = GEnv.Options.CommandPopupAlwaysOnTop; cp.ShowInTaskBar = GEnv.Options.CommandPopupInTaskBar; IWindowManager wm = TerminalEmulatorPlugin.Instance.GetWindowManager(); ISessionManager sm = TerminalEmulatorPlugin.Instance.GetSessionManager(); IPoderosaPopupWindow window = wm.CreatePopupView(cp); sm.StartNewSession(session, window.InternalView); sm.ActivateDocument(session.Document, ActivateReason.InternalAction); } catch (Exception ex) { RuntimeUtil.ReportException(ex); } }
private static void SessionEntryPoint(AbstractTerminal terminal, CommandResultDocument document) { try { TerminalControl tc = terminal.TerminalHost.TerminalControl; Debug.Assert(tc != null); RenderProfile rp = (RenderProfile)tc.GetRenderProfile().Clone(); CommandResultSession session = new CommandResultSession(document, rp); //現在のRenderProfileを使ってセッションを作る TerminalDocument terminaldoc = terminal.GetDocument(); PopupViewCreationParam cp = new PopupViewCreationParam(_viewFactory); //結果のサイズに合わせる。ただし高さは20行を上限とする cp.InitialSize = new Size(tc.ClientSize.Width, (int)(RuntimeUtil.AdjustIntRange(document.Size, 0, 20) * rp.Pitch.Height) + 2); cp.OwnedByCommandTargetWindow = GEnv.Options.CommandPopupAlwaysOnTop; cp.ShowInTaskBar = GEnv.Options.CommandPopupInTaskBar; IWindowManager wm = TerminalEmulatorPlugin.Instance.GetWindowManager(); ISessionManager sm = TerminalEmulatorPlugin.Instance.GetSessionManager(); IPoderosaPopupWindow window = wm.CreatePopupView(cp); sm.StartNewSession(session, window.InternalView); sm.ActivateDocument(session.Document, ActivateReason.InternalAction); } catch (Exception ex) { RuntimeUtil.ReportException(ex); } }