mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
Sample using F#
This commit is contained in:
16
FSharpExample/FSharpExample.fsproj
Normal file
16
FSharpExample/FSharpExample.fsproj
Normal file
@@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.fs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Terminal.Gui" Version="0.9.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
37
FSharpExample/Program.fs
Normal file
37
FSharpExample/Program.fs
Normal file
@@ -0,0 +1,37 @@
|
||||
// Learn more about F# at http://fsharp.org
|
||||
|
||||
open System
|
||||
open Terminal.Gui
|
||||
open NStack
|
||||
|
||||
|
||||
let ustr (x:string) = ustring.Make(x)
|
||||
|
||||
let stop = Action Application.RequestStop
|
||||
|
||||
let newFile() =
|
||||
let ok = new Button (ustr "Ok", true, Clicked=stop)
|
||||
let cancel = new Button (ustr "Cancel", Clicked=stop)
|
||||
let d = new Dialog (ustr ("New File"), 50, 20, ok, cancel)
|
||||
Application.Run (d)
|
||||
|
||||
let quit() =
|
||||
if MessageBox.Query (50, 7, "Quit demo", "Are you sure you want to quit the demo?", "Yes", "No") = 0 then
|
||||
Application.Top.Running <- false
|
||||
|
||||
let buildMenu() =
|
||||
new MenuBar ([|
|
||||
new MenuBarItem (ustr ("File"),
|
||||
[| MenuItem(ustr("_New"), "Creates a new file", System.Action newFile);
|
||||
MenuItem(ustr("_Quit"), null, System.Action quit)
|
||||
|])|])
|
||||
|
||||
[<EntryPoint>]
|
||||
let main argv =
|
||||
Application.Init ()
|
||||
let top = Application.Top
|
||||
let win = new Window ("Hello"|>ustr, X=Pos.At(0), Y=Pos.At(1), Width=Dim.Fill(), Height=Dim.Fill())
|
||||
top.Add (buildMenu())
|
||||
top.Add (win)
|
||||
Application.Run ()
|
||||
0 // return an integer exit code
|
||||
Reference in New Issue
Block a user