forked from gui-cs/Terminal.Gui
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.fs
48 lines (34 loc) · 1.94 KB
/
Program.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
open Terminal.Gui
type ExampleWindow() as this =
inherit Window()
do
this.Title <- sprintf "Example App (%O to quit)" Application.QuitKey
// Create input components and labels
let usernameLabel = new Label(Text = "Username:")
let userNameText = new TextField(X = Pos.Right(usernameLabel) + Pos.op_Implicit(1), Width = Dim.Fill())
let passwordLabel = new Label(Text = "Password:", X = Pos.Left(usernameLabel), Y = Pos.Bottom(usernameLabel) + Pos.op_Implicit(1))
let passwordText = new TextField(Secret = true, X = Pos.Left(userNameText), Y = Pos.Top(passwordLabel), Width = Dim.Fill())
// Create login button
let btnLogin = new Button(Text = "Login", Y = Pos.Bottom(passwordLabel) + Pos.op_Implicit(1), X = Pos.Center(), IsDefault = true)
// When login button is clicked display a message popup
btnLogin.Accepting.Add(fun _ ->
if userNameText.Text = "admin" && passwordText.Text = "password" then
MessageBox.Query("Logging In", "Login Successful", "Ok") |> ignore
ExampleWindow.UserName <- userNameText.Text.ToString()
Application.RequestStop()
else
MessageBox.ErrorQuery("Logging In", "Incorrect username or password", "Ok") |> ignore
)
// Add the views to the Window
this.Add(usernameLabel, userNameText, passwordLabel, passwordText, btnLogin)
static member val UserName = "" with get, set
[<EntryPoint>]
let main argv =
Application.Init()
Application.Run<ExampleWindow>().Dispose()
// Before the application exits, reset Terminal.Gui for clean shutdown
Application.Shutdown()
// To see this output on the screen it must be done after shutdown,
// which restores the previous screen.
printfn "Username: %s" ExampleWindow.UserName
0 // return an integer exit code