I would like to put the text from a certain line into a variable. Would I be able to do this using Console.CursorLeft and Console.CursorTop somehow? Is it even possible for a program to know what letter the cursor is currently on? I have a program in which you can use the arrow keys to highlight a certain line, but it requires you to already know what's on the line and repeat it.
This is the program so far which works just so you can get an idea of what I'm trying to do.
open System
Console.BackgroundColor <- ConsoleColor.White
Console.ForegroundColor <- ConsoleColor.Black
printfn "OPTION 1"
Console.BackgroundColor <- ConsoleColor.Black
Console.ForegroundColor <- ConsoleColor.White
printfn "Option 2"
printfn "Option 3"
Console.SetCursorPosition(0, 0)
let mutable exit = false
while not exit do
let mutable key = Console.ReadKey()
if key.Key.Equals(ConsoleKey.UpArrow) then
Console.SetCursorPosition(0, Console.CursorTop - 1)
if key.Key.Equals(ConsoleKey.DownArrow) then
Console.SetCursorPosition(0, Console.CursorTop + 1)
if key.Key.Equals(ConsoleKey.Enter) then
let selected = Console.CursorTop + 1
Console.SetCursorPosition(0, 3)
printfn "You selected %i" (selected)
exit <- true
let mutable test = Console.CursorTop
Console.SetCursorPosition(0, 0)
printfn "Option 1"
printfn "Option 2"
printfn "Option 3"
if test = 0 then
Console.SetCursorPosition(0, 0)
Console.BackgroundColor <- ConsoleColor.White
Console.ForegroundColor <- ConsoleColor.Black
printfn "OPTION 1"
if test = 1 then
Console.SetCursorPosition(0, 1)
Console.BackgroundColor <- ConsoleColor.White
Console.ForegroundColor <- ConsoleColor.Black
printfn "OPTION 2"
if test = 2 then
Console.SetCursorPosition(0, 2)
Console.BackgroundColor <- ConsoleColor.White
Console.ForegroundColor <- ConsoleColor.Black
printfn "OPTION 3"
Console.BackgroundColor <- ConsoleColor.Black
Console.ForegroundColor <- ConsoleColor.White
Console.SetCursorPosition(0, test)
Console.Read() |> ignore