C
C#14mo ago
Nadekai

❔ How to display text below console.Readline

How do I accomplish this layout?
No description
25 Replies
Pobiega
Pobiega14mo ago
Console.WriteLine(); creates a blank line
Nadekai
NadekaiOP14mo ago
That's not the problem, the proble is I need to get user input line above. While also displaying the bottom line.
Pobiega
Pobiega14mo ago
how is that a problem?
Nadekai
NadekaiOP14mo ago
Because I have no idea how to do that
Pobiega
Pobiega14mo ago
Show me your current code
Nadekai
NadekaiOP14mo ago
There is nothing there.
Pobiega
Pobiega14mo ago
or do you mean printing that line before the readline?
Nadekai
NadekaiOP14mo ago
Exactly
Thinker
Thinker14mo ago
Write out all the text and then set the cursor position
Pobiega
Pobiega14mo ago
yeah write hi set cursor position write "you msut enter name" set cursor position write "enter your name: " take input
Nadekai
NadekaiOP14mo ago
uh... how do I do that?
Angius
Angius14mo ago
The specific layout you posted
No description
Angius
Angius14mo ago
No need for any cursor shenanigans Just good ol' Console.Write()
Pobiega
Pobiega14mo ago
nah, they want the "you must enter name" to be printed WHEN its asking for input
Nadekai
NadekaiOP14mo ago
Yep
Angius
Angius14mo ago
Ah Then, yeah, cursor shenanigans
Pobiega
Pobiega14mo ago
No description
Pobiega
Pobiega14mo ago
thats how you move the cursor around
Nadekai
NadekaiOP14mo ago
Alright
Pobiega
Pobiega14mo ago
the values are just random numbers, not the ones you need
Nadekai
NadekaiOP14mo ago
Thanks!
ZacharyPatten
ZacharyPatten14mo ago
it can be easier to store the position you wantthe cursor to be rather than having to manually supply it yourself:
Console.WriteLine("Hello, World!");
Console.Write("Enter some text: ");
var pos = Console.GetCursorPosition();
Console.WriteLine();
Console.WriteLine("some text...");
Console.SetCursorPosition(pos.Left, pos.Top);
string input = Console.ReadLine();
Console.WriteLine("Hello, World!");
Console.Write("Enter some text: ");
var pos = Console.GetCursorPosition();
Console.WriteLine();
Console.WriteLine("some text...");
Console.SetCursorPosition(pos.Left, pos.Top);
string input = Console.ReadLine();
in the above code, it prints all the stuff up until the user input in needed, then it grabs the current cursor position, then prints the rest of the output, then sets the cursor back to the position we captured This way you don't have to manually progam 123 Left, and 123 Top... etc
ZacharyPatten
ZacharyPatten14mo ago
--- however, in general this is not an ideal way to handle input.
No description
ZacharyPatten
ZacharyPatten14mo ago
Console.ReadLine allows long input and wraps text around also, if the user changes the size of the window, they can change the current view changing hte view can cause the text to wrap and thus change cursor positions --- I can suggest some alternatives, but depending on what you are making, spending a lot of time just to have text after a ReadLine might not be worth it
Accord
Accord14mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server