private void OutputInput(int totalWidth)
        {
            const string Prefix = "> ";
            var          row    = Console.WindowHeight - 1;

            if (SetCursorPosition(0, row))
            {
                WriteText(Prefix, ConsoleColor.Gray, ConsoleColor.DarkGray);
                if (SetCursorPosition(Prefix.Length, row))
                {
                    var width = totalWidth - Prefix.Length - (isWindows ? 1 : 0);
                    var text  = CurrentInput.TrimStart().FitRight(width);
                    WriteText(text, ConsoleColor.White, ConsoleColor.DarkGray);
                }
            }
        }
Exemplo n.º 2
0
        private void ProcessOtherButtons(string button)
        {
            switch (button)
            {
            case "C":
                ClearDisplay();
                break;

            case "CE":
                CurrentInput = "0";
                break;

            case "±":
                if (!CurrentInput.Contains('-'))
                {
                    CurrentInput = "-" + CurrentInput;
                }
                else
                {
                    CurrentInput = CurrentInput.Substring(1);
                }
                break;

            case "<-":
                if (CurrentInput.Length == 0 || CurrentInput == "-" || CurrentInput == "Error" || CurrentInput == "NaN")
                {
                    CurrentInput = "0";
                }
                else
                {
                    CurrentInput = CurrentInput.Remove(CurrentInput.Length - 1);
                }
                break;

            case "x^2":
                NCalc.Expression powExp = new NCalc.Expression("Round(Pow(" + CurrentInput + ", 2), 3)");
                CurrentInput = powExp.Evaluate().ToString();
                break;

            case "√":
                NCalc.Expression sqrtExp = new NCalc.Expression("Round(Sqrt(" + CurrentInput + "), 3)");
                CurrentInput = sqrtExp.Evaluate().ToString();
                break;

            case "1/x":
                CurrentInput = new NCalc.Expression($"Round(1/{CurrentInput}, 3)").Evaluate().ToString();
                break;

            case "MS":
                calcmemory = CurrentInput;
                break;

            case "M+":
                calcmemory = new NCalc.Expression(calcmemory + "+" + CurrentInput).Evaluate().ToString();
                break;

            case "M-":
                calcmemory = new NCalc.Expression(calcmemory + "-" + CurrentInput).Evaluate().ToString();
                break;

            case "MR":
                if (!String.IsNullOrEmpty(calcmemory))
                {
                    CurrentInput = calcmemory;
                }
                break;

            case "MC":
                calcmemory = "0";
                break;

            case ".":
                if (!CurrentInput.Contains("."))
                {
                    CurrentInput += ".";
                }
                break;

            case "=":
                NCalc.Expression exp = new NCalc.Expression(TextExpression + CurrentInput);
                TextExpression = string.Empty;
                CurrentInput   = exp.Evaluate().ToString();
                break;

            default:
                if (binaryOperationPressed)
                {
                    // if previous operation is bin operation to clear old input values
                    CurrentInput           = button;
                    binaryOperationPressed = false;
                }
                else
                {
                    CurrentInput = CurrentInput.TrimStart('0') + button;                             // add new value to display and remove start 0
                }
                break;
            }
        }