0

I've encountered this weird issue that might be connected to my IDE or C# overrall. Whenever I am inputting something in the console that is being read my Console.ReadLine(), it is being duplicated and shown below until I press return. I want to input a whole String for example, but what I see is reading char by char which kind of messes up debugging and presence of my program. I am attaching the code below along with the screenshot of the issue.

using System;
using System.Text.RegularExpressions;

namespace Zadanie_1
{
    
    class Program
    {
        static void ShowMenu()
        {
            Console.WriteLine("Witaj w grze Siszarp!");
            Console.WriteLine("[1] Zacznij nową grę");
            Console.WriteLine("[X] Zamknij program"); 
        }
        static void PickOption(ConsoleKeyInfo keyPressed)
        {
            switch (keyPressed.KeyChar)
            {
                case '1':
                    Console.Clear();
                    Option1Picked();
                    break;
                case 'X':
                    Environment.Exit(0);
                    break;
            }
        }
        
        static bool IsCharacterNameValid(String characterName)
        {
            if (characterName.Length < 2)
            {
                Console.WriteLine("Niepoprawna nazwa!");
                return false;
            }
                
            if (!Regex.IsMatch(characterName, @"^[a-zA-Z]+$"))
            {
                Console.WriteLine("Niepoprawna nazwa!");
                return false;
            }
                
            return true;
        }

        static void EnterCharacterName()
        {
            String characterName;
            do
            {
                Console.Write("Podaj nazwę bohatera:");
                characterName = Console.ReadLine();
            
            } while (!IsCharacterNameValid(characterName));

        }

        static void Option1Picked()
        {
            EnterCharacterName();
        }
        
        static void Main(string[] args)
        {
            ShowMenu();
            ConsoleKeyInfo keyPressed = Console.ReadKey();
            PickOption(keyPressed);

        }
    }
}

as you can see the input is being read char by char instead of a whole string

jasiu
  • 91
  • 5
  • I don't think this is an issue with your implementation. How do you run the program? Have you tried running it in a different terminal/shell? – M. Dennhardt Oct 12 '21 at 13:52
  • @M.Dennhardt yeah, it works when I run it it an external console, but that kinda sucks as I'd rather test my program in Rider's built-in console. – jasiu Oct 13 '21 at 16:16
  • Since it is running as expected in an external console, this appears to be an issue with Rider. There are [several open bugs](https://youtrack.jetbrains.com/issues/RIDER?q=readline%20State:%20Open) related to Run Console on the tracker, e.g. [39941](https://youtrack.jetbrains.com/issue/RIDER-39941). However, I could not find anything exactly like your problem with a quick search. You could try up-/downgrading Rider and see if that fixes it. You could also try checking or unchecking "Use external console" in the "Run/Debug Configurations" window. – M. Dennhardt Oct 14 '21 at 06:31

0 Answers0