diff --git a/.editorconfig b/.editorconfig index 576839082..040e7abd9 100644 --- a/.editorconfig +++ b/.editorconfig @@ -6,6 +6,7 @@ csharp_new_line_before_open_brace = methods,local_functions csharp_new_line_before_else = false csharp_new_line_before_catch = false csharp_new_line_before_finally = false +end_of_line = crlf csharp_indent_case_contents = true csharp_indent_switch_labels = false diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..35720cb73 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,13 @@ +# Set the default behavior for all files. +* text=auto + +# Normalized and converts to +# native line endings on checkout. +*.cs text + +# Convert to LF line endings on checkout. +*.sh text eol=lf + +# Binary files. +*.png binary +*.jpg binary \ No newline at end of file diff --git a/.gitignore b/.gitignore index c4865c0ac..632d369b3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,9 @@ bin obj -*~ +~$* *.userprefs *~ packages .vs -*.csproj.user +# User-specific files +*.user diff --git a/Example/demo.cs b/Example/demo.cs index 3cc63d77c..ab05806b3 100644 --- a/Example/demo.cs +++ b/Example/demo.cs @@ -6,6 +6,7 @@ using System.Diagnostics; using System.Globalization; using System.Reflection; using NStack; +using System.Text; static class Demo { //class Box10x : View, IScrollView { @@ -81,22 +82,26 @@ static class Demo { } } - static void ShowTextAlignments () { - var container = new Dialog ( - "Text Alignments", 50, 20, - new Button ("Ok", is_default: true) { Clicked = () => { Application.RequestStop (); } }, - new Button ("Cancel") { Clicked = () => { Application.RequestStop (); } }); - + var container = new Window ($"Show Text Alignments") { + X = 0, + Y = 0, + Width = Dim.Fill (), + Height = Dim.Fill () + }; + container.OnKeyUp += (KeyEvent ke) => { + if (ke.Key == Key.Esc) + container.Running = false; + }; int i = 0; - string txt = "Hello world, how are you doing today"; + string txt = "Hello world, how are you doing today?"; container.Add ( - new Label(new Rect(0, 1, 40, 3), $"{i+1}-{txt}") { TextAlignment = TextAlignment.Left }, - new Label(new Rect(0, 3, 40, 3), $"{i+2}-{txt}") { TextAlignment = TextAlignment.Right }, - new Label(new Rect(0, 5, 40, 3), $"{i+3}-{txt}") { TextAlignment = TextAlignment.Centered }, - new Label(new Rect(0, 7, 40, 3), $"{i+4}-{txt}") { TextAlignment = TextAlignment.Justified } + new Label ($"{i+1}-{txt}") { TextAlignment = TextAlignment.Left, Y = 3, Width = Dim.Fill () }, + new Label ($"{i+2}-{txt}") { TextAlignment = TextAlignment.Right, Y = 5, Width = Dim.Fill () }, + new Label ($"{i+3}-{txt}") { TextAlignment = TextAlignment.Centered, Y = 7, Width = Dim.Fill () }, + new Label ($"{i+4}-{txt}") { TextAlignment = TextAlignment.Justified, Y = 9, Width = Dim.Fill () } ); Application.Run (container); @@ -408,6 +413,44 @@ static class Demo { #endregion + #region OnKeyDown / OnKeyUp Demo + private static void OnKeyDownUpDemo () + { + var container = new Dialog ( + "OnKeyDown & OnKeyUp demo", 80, 20, + new Button ("Close") { Clicked = () => { Application.RequestStop (); } }) { + Width = Dim.Fill (), + Height = Dim.Fill (), + }; + + var list = new List (); + var listView = new ListView (list) { + X = 0, + Y = 0, + Width = Dim.Fill () - 1, + Height = Dim.Fill () - 2, + }; + listView.ColorScheme = Colors.TopLevel; + container.Add (listView); + + void KeyUpDown (KeyEvent keyEvent, string updown) + { + if ((keyEvent.Key & Key.CtrlMask) != 0) { + list.Add ($"Key{updown,-4}: Ctrl "); + } else if ((keyEvent.Key & Key.AltMask) != 0) { + list.Add ($"Key{updown,-4}: Alt "); + } else { + list.Add ($"Key{updown,-4}: {(((uint)keyEvent.KeyValue & (uint)Key.CharMask) > 26 ? $"{(char)keyEvent.KeyValue}" : $"{keyEvent.Key}")}"); + } + listView.MoveDown (); + } + + container.OnKeyDown += (KeyEvent keyEvent) => KeyUpDown (keyEvent, "Down"); + container.OnKeyUp += (KeyEvent keyEvent) => KeyUpDown (keyEvent, "Up"); + Application.Run (container); + } + #endregion + public static Label ml; public static MenuBar menu; public static CheckBox menuKeysStyle; @@ -418,7 +461,6 @@ static class Demo { CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.GetCultureInfo ("en-US"); //Application.UseSystemConsole = true; - Console.WindowHeight = 35; Application.Init (); @@ -426,11 +468,13 @@ static class Demo { //Open (); #if true + int margin = 3; var win = new Window ("Hello") { X = 1, Y = 1, - Width = Dim.Fill (), - Height = Dim.Fill ()-1 + + Width = Dim.Fill () - margin, + Height = Dim.Fill () - margin }; #else var tframe = top.Frame; @@ -451,7 +495,7 @@ static class Demo { menu = new MenuBar (new MenuBarItem [] { new MenuBarItem ("_File", new MenuItem [] { - new MenuItem ("Text Editor Demo", "", () => { Editor (top); }), + new MenuItem ("Text _Editor Demo", "", () => { Editor (top); }), new MenuItem ("_New", "Creates new file", NewFile), new MenuItem ("_Open", "", Open), new MenuItem ("_Hex", "", () => ShowHex (top)), @@ -469,18 +513,19 @@ static class Demo { menuItems[3] }), new MenuBarItem ("_List Demos", new MenuItem [] { - new MenuItem ("Select Multiple Items", "", () => ListSelectionDemo (true)), - new MenuItem ("Select Single Item", "", () => ListSelectionDemo (false)), + new MenuItem ("Select _Multiple Items", "", () => ListSelectionDemo (true)), + new MenuItem ("Select _Single Item", "", () => ListSelectionDemo (false)), }), - new MenuBarItem ("Assorted", new MenuItem [] { - new MenuItem ("Show text alignments", "", () => ShowTextAlignments ()) + new MenuBarItem ("A_ssorted", new MenuItem [] { + new MenuItem ("_Show text alignments", "", () => ShowTextAlignments ()), + new MenuItem ("_OnKeyDown/Up", "", () => OnKeyDownUpDemo ()) }), - new MenuBarItem ("Test Menu and SubMenus", new MenuItem [] { - new MenuItem ("SubMenu1Item1", + new MenuBarItem ("_Test Menu and SubMenus", new MenuItem [] { + new MenuItem ("SubMenu1Item_1", new MenuBarItem (new MenuItem[] { - new MenuItem ("SubMenu2Item1", + new MenuItem ("SubMenu2Item_1", new MenuBarItem (new MenuItem [] { - new MenuItem ("SubMenu3Item1", + new MenuItem ("SubMenu3Item_1", new MenuBarItem (new MenuItem [] { menuItems [2] }) ) }) @@ -488,6 +533,7 @@ static class Demo { }) ) }), + new MenuBarItem ("_About...", "Demonstrates top-level menu item", () => MessageBox.ErrorQuery (50, 7, "About Demo", "This is a demo app for gui.cs", "Ok")), }); menuKeysStyle = new CheckBox (3, 25, "UseKeysUpDownAsKeysLeftRight", true); @@ -498,7 +544,7 @@ static class Demo { ShowEntries (win); int count = 0; - ml = new Label (new Rect (3, 18, 47, 1), "Mouse: "); + ml = new Label (new Rect (3, 17, 47, 1), "Mouse: "); Application.RootMouseEvent += delegate (MouseEvent me) { ml.TextColor = Colors.TopLevel.Normal; ml.Text = $"Mouse: ({me.X},{me.Y}) - {me.Flags} {count++}"; @@ -520,24 +566,31 @@ static class Demo { new StatusItem(Key.F2, "~F2~ Load", null), new StatusItem(Key.F3, "~F3~ Save", null), new StatusItem(Key.ControlX, "~^X~ Quit", () => { if (Quit ()) top.Running = false; }), - }); + }) { + Parent = null, + }; win.Add (drag, dragText); #if true - // This currently causes a stack overflow, because it is referencing a window that has not had its size allocated yet + // FIXED: This currently causes a stack overflow, because it is referencing a window that has not had its size allocated yet - var bottom = new Label ("This should go on the bottom!"); + var bottom = new Label ("This should go on the bottom of the same top-level!"); win.Add (bottom); + var bottom2 = new Label ("This should go on the bottom of another top-level!"); + top.Add (bottom2); - Application.OnResized = () => { - bottom.X = Pos.Left (win); - bottom.Y = Pos.Bottom (win); + Application.OnLoad = () => { + bottom.X = win.X; + bottom.Y = Pos.Bottom (win) - Pos.Top (win) - margin; + bottom2.X = Pos.Left (win); + bottom2.Y = Pos.Bottom (win); }; #endif + top.Add (win); //top.Add (menu); - top.Add (menu, statusBar, ml); + top.Add (menu, statusBar); Application.Run (); } } diff --git a/FSharpExample/.editorconfig b/FSharpExample/.editorconfig new file mode 100644 index 000000000..924c8fe00 --- /dev/null +++ b/FSharpExample/.editorconfig @@ -0,0 +1,4 @@ +[*.fs] +indent_style = space +indent_size = 4 +tab_width = 4 diff --git a/FSharpExample/FSharpExample.fsproj b/FSharpExample/FSharpExample.fsproj index 3e9230e44..d251896a4 100644 --- a/FSharpExample/FSharpExample.fsproj +++ b/FSharpExample/FSharpExample.fsproj @@ -10,7 +10,11 @@ - + + + + + diff --git a/FSharpExample/FSharpExample.sln b/FSharpExample/FSharpExample.sln new file mode 100644 index 000000000..90e5c5be2 --- /dev/null +++ b/FSharpExample/FSharpExample.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30011.22 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FSharpExample", "FSharpExample.fsproj", "{6E4DF691-FA5F-4D7C-8DBC-8656103C5CB1}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Terminal.Gui", "..\Terminal.Gui\Terminal.Gui.csproj", "{FA48E777-1308-489D-95A0-89DE46B65A93}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6E4DF691-FA5F-4D7C-8DBC-8656103C5CB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6E4DF691-FA5F-4D7C-8DBC-8656103C5CB1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6E4DF691-FA5F-4D7C-8DBC-8656103C5CB1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6E4DF691-FA5F-4D7C-8DBC-8656103C5CB1}.Release|Any CPU.Build.0 = Release|Any CPU + {FA48E777-1308-489D-95A0-89DE46B65A93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FA48E777-1308-489D-95A0-89DE46B65A93}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FA48E777-1308-489D-95A0-89DE46B65A93}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FA48E777-1308-489D-95A0-89DE46B65A93}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A023D2E3-EF0F-4986-8E6C-323F967788B7} + EndGlobalSection +EndGlobal diff --git a/FSharpExample/Program.fs b/FSharpExample/Program.fs index 6a9418fa8..a2ec888c5 100644 --- a/FSharpExample/Program.fs +++ b/FSharpExample/Program.fs @@ -1,37 +1,441 @@ // Learn more about F# at http://fsharp.org -open System open Terminal.Gui +open System +open Mono.Terminal +open System.Collections.Generic +open System.Diagnostics +open System.Globalization +open System.Reflection open NStack +type Demo() = class end + let ustr (x:string) = ustring.Make(x) + let mutable ml2 = Unchecked.defaultof