Example #1
0
 private static void ReplaceChar(ConsoleKeyInfo?key, object arg)
 {
     _singleton._groupUndoHelper.StartGroup(ReplaceChar, arg);
     DeleteChar(key, arg);
     ViInsertMode(key, arg);
 }
Example #2
0
 /// <summary>
 /// Clear the input from the start of the input to the cursor.  The cleared text is placed
 /// in the kill ring.
 /// </summary>
 public static void BackwardKillLine(ConsoleKeyInfo?key = null, object arg = null)
 {
     _singleton.Kill(0, _singleton._current, true);
 }
Example #3
0
        /// <summary>
        /// Clear the input from the start of the current word to the cursor.  If the cursor
        /// is between words, the input is cleared from the start of the previous word to the
        /// cursor.  The cleared text is placed in the kill ring.
        /// </summary>
        public static void BackwardKillWord(ConsoleKeyInfo?key = null, object arg = null)
        {
            int i = _singleton.FindBackwardWordPoint(_singleton.Options.WordDelimiters);

            _singleton.Kill(i, _singleton._current - i, true);
        }
Example #4
0
 /// <summary>
 /// Attempt to execute the current input.  If the current input is incomplete (for
 /// example there is a missing closing parenthesis, bracket, or quote, then the
 /// continuation prompt is displayed on the next line and PSReadline waits for
 /// keys to edit the current input.
 /// </summary>
 public static void ValidateAndAcceptLine(ConsoleKeyInfo?key = null, object arg = null)
 {
     _singleton.AcceptLineImpl(true);
 }
Example #5
0
        /// <summary>
        /// Go to the matching brace, paren, or square bracket.
        /// </summary>
        public static void GotoBrace(ConsoleKeyInfo?key = null, object arg = null)
        {
            if (_singleton._current >= _singleton._buffer.Length)
            {
                Ding();
                return;
            }

            _singleton.MaybeParseInput();

            Token token = null;
            var   index = 0;

            for (; index < _singleton._tokens.Length; index++)
            {
                token = _singleton._tokens[index];
                if (token.Extent.StartOffset == _singleton._current)
                {
                    break;
                }
            }

            TokenKind toMatch;
            int       direction;

            switch (token.Kind)
            {
            case TokenKind.LParen:   toMatch = TokenKind.RParen; direction = 1; break;

            case TokenKind.LCurly:   toMatch = TokenKind.RCurly; direction = 1; break;

            case TokenKind.LBracket: toMatch = TokenKind.RBracket; direction = 1; break;

            case TokenKind.RParen:   toMatch = TokenKind.LParen; direction = -1; break;

            case TokenKind.RCurly:   toMatch = TokenKind.LCurly; direction = -1; break;

            case TokenKind.RBracket: toMatch = TokenKind.LBracket; direction = -1; break;

            default:
                // Nothing to match (don't match inside strings/comments)
                Ding();
                return;
            }

            var matchCount = 0;
            var limit      = (direction > 0) ? _singleton._tokens.Length - 1 : -1;

            for (; index != limit; index += direction)
            {
                var t = _singleton._tokens[index];
                if (t.Kind == token.Kind)
                {
                    matchCount++;
                }
                else if (t.Kind == toMatch)
                {
                    matchCount--;
                    if (matchCount == 0)
                    {
                        _singleton.MoveCursor(t.Extent.StartOffset);
                        return;
                    }
                }
            }
            Ding();
        }
Example #6
0
 public static void ReverseSearchHistory(ConsoleKeyInfo?key = null, object arg = null)
 {
     _singleton.InteractiveHistorySearch(-1);
 }
Example #7
0
 /// <summary>
 /// Delete the character under the cursor, or if the line is empty, exit the process
 /// </summary>
 public static void DeleteCharOrExit(ConsoleKeyInfo?key = null, object arg = null)
 {
     _singleton.DeleteCharImpl(1, orExit: true);
 }
        private static int ProgressCnt = 0; // is used in the progress event (for the switch case)
        #region Startup Functions
        public static int Startup()
        {
            ConsoleKeyInfo?userInput        = null; // value that gets the key input
            int            userChoice       = -1;   // value for parsing the user input
            string         userSearchTerm   = "";
            string         userSearchedPath = "";

            SearchLogic newSearch = new SearchLogic();                //start a new search after all conditions are filled

            newSearch.ResultFoundEvent += NewSearch_ResultFoundEvent; // register to the results found event
            newSearch.ShowProgress     += NewSearch_ShowProgress;     // register to the progres event

            Console.Clear();
            Console.WriteLine("Welcome to Ori's files search engine.");
            Console.WriteLine();
            Console.WriteLine("*** Note - the search engine will not search protected folders ***");
            Console.WriteLine();
            Console.WriteLine("Please choose an operation:");
            Console.WriteLine();
            Console.WriteLine("1. Search all computer -  NOTE:This search may take long time");
            Console.WriteLine("2. Search in a known directory and its sub-directories");
            Console.WriteLine("3. Show all searches in DB");
            Console.WriteLine("4. Exit");
            Console.WriteLine();
            Console.WriteLine();

            while (userChoice < 1 || userChoice > 4) //make sure user choice is from 1-4
            {
                if (userInput != null)
                {
                    Console.WriteLine("Please choose operation 1-4");
                }

                userInput = System.Console.ReadKey(true);                    //gets the key input
                int.TryParse(userInput?.KeyChar.ToString(), out userChoice); //parse the key input to a number
            }

            switch (userChoice)
            {
            case 1:

                userSearchTerm = GetUserTerm();
                break;

            case 2:
                bool beenHere = false;     //flag for the path retry message

                userSearchTerm = GetUserTerm();

                Console.WriteLine("Please enter path to search:");
                while (!System.IO.Directory.Exists(userSearchedPath))     //if the path does not exists
                {
                    if (beenHere)
                    {
                        Console.WriteLine("Directory not found. Please use a valid path.");
                    }

                    userSearchedPath = Console.ReadLine();     //gets the path from user
                    beenHere         = true;
                }
                break;

            case 3:
                List <string> CurrentDbData = newSearch.ReturnDBData();    // new list to get the current DB searches and results
                if (CurrentDbData.Count > 0)
                {
                    CurrentDbData.ForEach(row => Console.WriteLine(row));     //run the get DBData func and print the rows to console
                }
                else
                {
                    Console.WriteLine("There is no data in the DB");
                }

                return(0);

            case 4: return(4);    //exit
            }

            Console.WriteLine($"Please wait while Im searching:'{userSearchTerm}' .........");
            Console.WriteLine();
            newSearch.MainSearchFunc(userSearchTerm, userSearchedPath); //send the search term + path to the main search function

            return(0);
        }
Example #9
0
 /// <summary>
 /// Attempt to show help content.
 /// Show the short help of the parameter next to the cursor.
 /// </summary>
 public static void ShowParameterHelp(ConsoleKeyInfo?key = null, object arg = null)
 {
     _singleton.DynamicHelpImpl(isFullHelp: false);
 }
Example #10
0
 private static void ViBackwardReplaceLine(ConsoleKeyInfo?key, object arg)
 {
     _singleton._groupUndoHelper.StartGroup(ViBackwardReplaceLine, arg);
     BackwardDeleteLine(key, arg);
     ViInsertMode(key, arg);
 }
Example #11
0
        public static void CaptureScreen(ConsoleKeyInfo?key = null, object arg = null)
        {
            int selectionTop    = _singleton._console.CursorTop;
            int selectionHeight = 1;
            int currentY        = selectionTop;

            Internal.IConsole console = _singleton._console;

            // We'll keep the current selection line (currentY) at least 4 lines
            // away from the top or bottom of the window.
            const int   margin           = 5;
            Func <bool> tooCloseToTop    = () => { return((currentY - console.WindowTop) < margin); };
            Func <bool> tooCloseToBottom = () => { return(((console.WindowTop + console.WindowHeight) - currentY) < margin); };

            // Current lines starts out selected
            InvertLines(selectionTop, selectionHeight);
            bool done = false;

            while (!done)
            {
                var k = ReadKey();
                switch (k.Key)
                {
                case ConsoleKey.K:
                case ConsoleKey.UpArrow:
                    if (tooCloseToTop())
                    {
                        ScrollDisplayUpLine();
                    }

                    if (currentY > 0)
                    {
                        currentY -= 1;
                        if ((k.Modifiers & ConsoleModifiers.Shift) == ConsoleModifiers.Shift)
                        {
                            if (currentY < selectionTop)
                            {
                                // Extend selection up, only invert newly selected line.
                                InvertLines(currentY, 1);
                                selectionTop     = currentY;
                                selectionHeight += 1;
                            }
                            else if (currentY >= selectionTop)
                            {
                                // Selection shortend 1 line, invert unselected line.
                                InvertLines(currentY + 1, 1);
                                selectionHeight -= 1;
                            }
                            break;
                        }
                        goto updateSelectionCommon;
                    }
                    break;

                case ConsoleKey.J:
                case ConsoleKey.DownArrow:
                    if (tooCloseToBottom())
                    {
                        ScrollDisplayDownLine();
                    }

                    if (currentY < (console.BufferHeight - 1))
                    {
                        currentY += 1;
                        if ((k.Modifiers & ConsoleModifiers.Shift) == ConsoleModifiers.Shift)
                        {
                            if (currentY == (selectionTop + selectionHeight))
                            {
                                // Extend selection down, only invert newly selected line.
                                InvertLines(selectionTop + selectionHeight, 1);
                                selectionHeight += 1;
                            }
                            else if (currentY == (selectionTop + 1))
                            {
                                // Selection shortend 1 line, invert unselected line.
                                InvertLines(selectionTop, 1);
                                selectionTop     = currentY;
                                selectionHeight -= 1;
                            }
                            break;
                        }
                        goto updateSelectionCommon;
                    }
                    break;

updateSelectionCommon:
                    // Shift not pressed - unselect current selection
                    InvertLines(selectionTop, selectionHeight);
                    selectionTop    = currentY;
                    selectionHeight = 1;
                    InvertLines(selectionTop, selectionHeight);
                    break;

                case ConsoleKey.Enter:
                    InvertLines(selectionTop, selectionHeight);
                    DumpScreenToClipboard(selectionTop, selectionHeight);
                    ScrollDisplayToCursor();
                    return;

                case ConsoleKey.Escape:
                    done = true;
                    continue;

                case ConsoleKey.C:
                case ConsoleKey.G:
                    if (k.Modifiers == ConsoleModifiers.Control)
                    {
                        done = true;
                        continue;
                    }
                    Ding();
                    break;

                default:
                    Ding();
                    break;
                }
            }
            InvertLines(selectionTop, selectionHeight);
            ScrollDisplayToCursor();
        }
Example #12
0
 private static void ViReplaceBrace(ConsoleKeyInfo?key, object arg)
 {
     _singleton._groupUndoHelper.StartGroup(ViReplaceBrace, arg);
     ViDeleteBrace(key, arg);
     ViInsertMode(key, arg);
 }
Example #13
0
        /// <summary>
        /// Replaces until given character.
        /// </summary>
        public static void ViReplaceToBeforeCharBackward(ConsoleKeyInfo?key = null, object arg = null)
        {
            var keyChar = ReadKey().KeyChar;

            ViReplaceToBeforeCharBack(keyChar, key, arg);
        }
Example #14
0
        /// <summary>
        /// Deletes until given character.
        /// </summary>
        public static void ViReplaceToChar(ConsoleKeyInfo?key = null, object arg = null)
        {
            var keyChar = ReadKey().KeyChar;

            ViReplaceToChar(keyChar, key, arg);
        }
Example #15
0
 public static void EndOfHistory(ConsoleKeyInfo?key = null, object arg = null)
 {
     _singleton._currentHistoryIndex = _singleton._history.Count;
     _singleton.UpdateFromHistory(moveCursor: true);
 }
Example #16
0
 static void CauseCrash(ConsoleKeyInfo?key = null, object arg = null)
 {
     throw new Exception("intentional crash for test purposes");
 }
Example #17
0
 public static void ForwardSearchHistory(ConsoleKeyInfo?key = null, object arg = null)
 {
     _singleton.InteractiveHistorySearch(+1);
 }
Example #18
0
 /// <summary>
 /// Move the cursor to the end of the input.
 /// </summary>
 public static void MoveToEndOfLine(ConsoleKeyInfo?key = null, object arg = null)
 {
     _singleton._current = Math.Max(0, _singleton._buffer.Length + ViEndOfLineFactor);
     _singleton.PlaceCursor();
 }
Example #19
0
        /// <summary>
        /// Delete the character under the cursor.
        /// </summary>
        public static void DeleteChar(ConsoleKeyInfo?key = null, object arg = null)
        {
            int qty = (arg is int) ? (int)arg : 1;

            _singleton.DeleteCharImpl(qty, orExit: false);
        }
Example #20
0
 private static void Ignore(ConsoleKeyInfo?key = null, object arg = null)
 {
 }
Example #21
0
 /// <summary>
 /// Attempt to execute the current input.  If the current input is incomplete (for
 /// example there is a missing closing parenthesis, bracket, or quote, then the
 /// continuation prompt is displayed on the next line and PSReadline waits for
 /// keys to edit the current input.
 /// </summary>
 public static void AcceptLine(ConsoleKeyInfo?key = null, object arg = null)
 {
     _singleton.AcceptLineImpl(false);
 }
Example #22
0
 public static void Abort(ConsoleKeyInfo?key = null, object arg = null)
 {
 }
Example #23
0
 /// <summary>
 /// The continuation prompt is displayed on the next line and PSReadline waits for
 /// keys to edit the current input.  This is useful to enter multi-line input as
 /// a single command even when a single line is complete input by itself.
 /// </summary>
 public static void AddLine(ConsoleKeyInfo?key = null, object arg = null)
 {
     Insert('\n');
 }
Example #24
0
        public static void DigitArgument(ConsoleKeyInfo?key = null, object arg = null)
        {
            if (!key.HasValue || char.IsControl(key.Value.KeyChar))
            {
                Ding();
                return;
            }

            if (_singleton._options.EditMode == EditMode.Vi && key.Value.KeyChar == '0')
            {
                BeginningOfLine();
                return;
            }

            bool sawDigit = false;

            _singleton._statusLinePrompt = "digit-argument: ";
            var argBuffer = _singleton._statusBuffer;

            argBuffer.Append(key.Value.KeyChar);
            if (key.Value.KeyChar == '-')
            {
                argBuffer.Append('1');
            }
            else
            {
                sawDigit = true;
            }

            _singleton.Render(); // Render prompt
            while (true)
            {
                var        nextKey = ReadKey();
                KeyHandler handler;
                if (_singleton._dispatchTable.TryGetValue(nextKey, out handler))
                {
                    if (handler.Action == DigitArgument)
                    {
                        if (nextKey.KeyChar == '-')
                        {
                            if (argBuffer[0] == '-')
                            {
                                argBuffer.Remove(0, 1);
                            }
                            else
                            {
                                argBuffer.Insert(0, '-');
                            }
                            _singleton.Render(); // Render prompt
                            continue;
                        }

                        if (nextKey.KeyChar >= '0' && nextKey.KeyChar <= '9')
                        {
                            if (!sawDigit && argBuffer.Length > 0)
                            {
                                // Buffer is either '-1' or '1' from one or more Alt+- keys
                                // but no digits yet.  Remove the '1'.
                                argBuffer.Length -= 1;
                            }
                            sawDigit = true;
                            argBuffer.Append(nextKey.KeyChar);
                            _singleton.Render(); // Render prompt
                            continue;
                        }
                    }
                    else if (handler.Action == Abort ||
                             handler.Action == CancelLine ||
                             handler.Action == CopyOrCancelLine)
                    {
                        break;
                    }
                }

                int intArg;
                if (int.TryParse(argBuffer.ToString(), out intArg))
                {
                    _singleton.ProcessOneKey(nextKey, _singleton._dispatchTable, ignoreIfNoAction: false, arg: intArg);
                }
                else
                {
                    Ding();
                }
                break;
            }

            // Remove our status line
            argBuffer.Clear();
            _singleton.ClearStatusMessage(render: true);
        }
Example #25
0
 /// <summary>
 /// Clear the input from the cursor to the end of the input.  The cleared text is placed
 /// in the kill ring.
 /// </summary>
 public static void KillLine(ConsoleKeyInfo?key = null, object arg = null)
 {
     _singleton.Kill(_singleton._current, _singleton._buffer.Length - _singleton._current, false);
 }
Example #26
0
 public static void ScrollDisplayTop(ConsoleKeyInfo?key = null, object arg = null)
 {
     _singleton._console.SetWindowPosition(0, 0);
 }
Example #27
0
        /// <summary>
        /// Clear the input from the cursor to the end of the current word.  If the cursor
        /// is between words, the input is cleared from the cursor to the end of the next word.
        /// The cleared text is placed in the kill ring.
        /// </summary>
        public static void KillWord(ConsoleKeyInfo?key = null, object arg = null)
        {
            int i = _singleton.FindForwardWordPoint(_singleton.Options.WordDelimiters);

            _singleton.Kill(_singleton._current, i - _singleton._current, false);
        }
Example #28
0
 public static void BeginningOfHistory(ConsoleKeyInfo?key = null, object arg = null)
 {
     _singleton.SaveCurrentLine();
     _singleton._currentHistoryIndex = 0;
     _singleton.UpdateFromHistory(moveCursor: true);
 }
Example #29
0
        /// <summary>
        /// Clear the input from the start of the current word to the cursor.  If the cursor
        /// is between words, the input is cleared from the start of the previous word to the
        /// cursor.  The cleared text is placed in the kill ring.
        /// </summary>
        public static void UnixWordRubout(ConsoleKeyInfo?key = null, object arg = null)
        {
            int i = _singleton.FindBackwardWordPoint("");

            _singleton.Kill(i, _singleton._current - i, true);
        }
Example #30
0
 /// <summary>
 /// Erase the entire command line.
 /// </summary>
 public static void ViReplaceLine(ConsoleKeyInfo?key = null, object arg = null)
 {
     _singleton._groupUndoHelper.StartGroup(ViReplaceLine, arg);
     DeleteLine(key, arg);
     ViInsertMode(key, arg);
 }