Exemple #1
0
        public string Edit(string value)
        {
            bool      loop      = true;
            TextInput textInput = new TextInput(consoleTextInputIO, false);

            top     = 0;
            left    = 0;
            curLine = 0;

            consoleTextInputIO.Clear();

            while (loop)
            {
                DisplayStatusBar(top, left, curLine);
                consoleTextInputIO.SetCursor(top, left);
                TextInputResult textResult = textInput.GetText("");
                if (textResult.ConsoleKeyInfo.Key == System.ConsoleKey.Enter)
                {
                    lines.Insert(curLine, textResult.Result);
                    curLine++;
                    top++;
                    continue;
                }

                switch (textResult.ConsoleKeyInfo.Key)
                {
                case System.ConsoleKey.C:
                    loop = false;
                    break;
                }
            }

            consoleTextInputIO.Clear();
            return(StringListToString(lines));
        }
Exemple #2
0
        public TextInputResult GetText(string value)
        {
            List <char>    result    = StringToCharList(value);
            int            index     = 0;
            bool           loop      = true;
            int            curTop    = textInputIO.GetCursorTop();
            int            curLeft   = textInputIO.GetCursorLeft();
            int            startLeft = textInputIO.GetCursorLeft();
            ConsoleKeyInfo cki       = new ConsoleKeyInfo();

            inputMode = InputMode.Insert;
            textInputIO.ChangeCursorToInsert();

            while (loop)
            {
                textInputIO.SetCursor(curTop, curLeft);
                cki = textInputIO.ReadKey(true);
                if (cki.KeyChar > 31 && cki.KeyChar < 127)
                {
                    switch (inputMode)
                    {
                    case InputMode.Insert:
                        result.Insert(index, cki.KeyChar);
                        break;

                    case InputMode.Override:
                        if (index < result.Count)
                        {
                            result[index] = cki.KeyChar;
                        }
                        else
                        {
                            result.Insert(index, cki.KeyChar);
                        }
                        break;
                    }
                    index++;
                    curLeft++;
                    textInputIO.SetCursor(curTop, startLeft);
                    textInputIO.WriteLine(CharListToString(result));
                    continue;
                }

                switch (cki.Key)
                {
                case ConsoleKey.Backspace:
                    if (index > 0)
                    {
                        result.RemoveAt(index - 1);
                    }
                    else
                    {
                        continue;
                    }
                    index--;
                    curLeft--;
                    break;

                case ConsoleKey.C:
                    result = new List <char>();
                    loop   = false;
                    break;

                case ConsoleKey.Delete:
                    if (index < result.Count)
                    {
                        result.RemoveAt(index);
                    }
                    break;

                case ConsoleKey.DownArrow:
                    loop = false;
                    break;

                case ConsoleKey.End:
                    index   = result.Count;
                    curLeft = startLeft + result.Count;
                    break;

                case ConsoleKey.Enter:
                    loop = false;
                    break;

                case ConsoleKey.Home:
                    index   = 0;
                    curLeft = startLeft;
                    break;

                case ConsoleKey.Insert:
                    if (inputMode == InputMode.Insert)
                    {
                        inputMode = InputMode.Override;
                        textInputIO.ChangeCursorToOverride();
                    }
                    else
                    {
                        inputMode = InputMode.Insert;
                        textInputIO.ChangeCursorToInsert();
                    }
                    break;

                case ConsoleKey.LeftArrow:
                    if (index > 0)
                    {
                        index--;
                        curLeft--;
                    }
                    break;

                case ConsoleKey.RightArrow:
                    if (index < result.Count)
                    {
                        index++;
                        curLeft++;
                    }
                    break;

                case ConsoleKey.Tab:
                    if (processTab)
                    {
                        switch (inputMode)
                        {
                        case InputMode.Insert:
                            if (index + TAB_SIZE < MAX_WIDTH)
                            {
                                for (int i = index; i < index + TAB_SIZE; i++)
                                {
                                    result.Insert(i, ' ');
                                }
                                index   += TAB_SIZE;
                                curLeft += TAB_SIZE;
                            }
                            break;

                        case InputMode.Override:
                            if (index + TAB_SIZE < result.Count)
                            {
                                for (int i = index; i < index + TAB_SIZE; i++)
                                {
                                    result[i] = ' ';
                                }
                                index   += TAB_SIZE;
                                curLeft += TAB_SIZE;
                            }
                            break;
                        }
                    }
                    else
                    {
                        loop = false;
                    }
                    break;

                case ConsoleKey.UpArrow:
                    loop = false;
                    break;
                }

                textInputIO.SetCursor(curTop, startLeft);
                textInputIO.WriteLine(CharListToString(result));
            }

            TextInputResult textInputResult = new TextInputResult();

            textInputResult.ConsoleKeyInfo = cki;
            textInputResult.Result         = CharListToString(result);
            textInputResult.CursorLeft     = curLeft;
            textInputResult.InputMode      = inputMode;

            return(textInputResult);
        }