Skip to content

Commit

Permalink
Merge branch 'v1_8_1'
Browse files Browse the repository at this point in the history
  • Loading branch information
tig committed Sep 21, 2022
2 parents 8443f29 + a11cf57 commit d432d26
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/api-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
dotnet-version: 6.0.100

- name: Setup DocFX
uses: crazy-max/ghaction-chocolatey@v1
uses: crazy-max/ghaction-chocolatey@v2
with:
args: install docfx

Expand Down
48 changes: 48 additions & 0 deletions StandaloneExample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using NStack;
using System.Text;
using Rune = System.Rune;
using System.Runtime.InteropServices;
using System.Diagnostics;

static class Demo {
class Box10x : View {
Expand Down Expand Up @@ -220,6 +222,19 @@ static void Main (string [] args)
Width = Dim.Fill (),
Height = Dim.Fill () - 1
};

StringBuilder aboutMessage = new StringBuilder ();
aboutMessage.AppendLine (@"A comprehensive sample library for");
aboutMessage.AppendLine (@"");
aboutMessage.AppendLine (@" _______ _ _ _____ _ ");
aboutMessage.AppendLine (@" |__ __| (_) | | / ____| (_) ");
aboutMessage.AppendLine (@" | | ___ _ __ _ __ ___ _ _ __ __ _| || | __ _ _ _ ");
aboutMessage.AppendLine (@" | |/ _ \ '__| '_ ` _ \| | '_ \ / _` | || | |_ | | | | | ");
aboutMessage.AppendLine (@" | | __/ | | | | | | | | | | | (_| | || |__| | |_| | | ");
aboutMessage.AppendLine (@" |_|\___|_| |_| |_| |_|_|_| |_|\__,_|_(_)_____|\__,_|_| ");
aboutMessage.AppendLine (@"");
aboutMessage.AppendLine (@"https://github.com/gui-cs/Terminal.Gui");

var menu = new MenuBar (new MenuBarItem [] {
new MenuBarItem ("_File", new MenuItem [] {
new MenuItem ("_New", "Creates new file", NewFile),
Expand All @@ -238,6 +253,12 @@ static void Main (string [] args)
miScrollViewCheck = new MenuBarItem ("ScrollView", new MenuItem [] {
new MenuItem ("Box10x", "", () => ScrollViewCheck()) {CheckType = MenuItemCheckStyle.Radio, Checked = true },
new MenuItem ("Filler", "", () => ScrollViewCheck()) {CheckType = MenuItemCheckStyle.Radio }
}),
new MenuBarItem ("_Help", new MenuItem [] {
new MenuItem ("_gui.cs API Overview", "", () => OpenUrl ("https://gui-cs.github.io/Terminal.Gui/articles/overview.html"), null, null, Key.F1),
new MenuItem ("gui.cs _README", "", () => OpenUrl ("https://github.com/gui-cs/Terminal.Gui"), null, null, Key.F2),
new MenuItem ("_About...", "About UI Catalog",
() => MessageBox.Query ("About UI Catalog", aboutMessage.ToString(), "_Ok"), null, null, Key.CtrlMask | Key.A)
})
});

Expand All @@ -261,5 +282,32 @@ static void Main (string [] args)

Application.Shutdown ();
}

private static void OpenUrl (string url)
{
try {
if (RuntimeInformation.IsOSPlatform (OSPlatform.Windows)) {
url = url.Replace ("&", "^&");
Process.Start (new ProcessStartInfo ("cmd", $"/c start {url}") { CreateNoWindow = true });
} else if (RuntimeInformation.IsOSPlatform (OSPlatform.Linux)) {
using (var process = new Process {
StartInfo = new ProcessStartInfo {
FileName = "xdg-open",
Arguments = url,
RedirectStandardError = true,
RedirectStandardOutput = true,
CreateNoWindow = true,
UseShellExecute = false
}
}) {
process.Start ();
}
} else if (RuntimeInformation.IsOSPlatform (OSPlatform.OSX)) {
Process.Start ("open", url);
}
} catch {
throw;
}
}
}
}
6 changes: 3 additions & 3 deletions Terminal.Gui/Windows/MessageBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,9 @@ static int QueryFull (bool useErrorColors, int width, int height, ustring title,
} else {
maxWidthLine = width;
}
int textWidth = TextFormatter.MaxWidth (message, maxWidthLine);
int textWidth = Math.Min (TextFormatter.MaxWidth (message, maxWidthLine), Application.Driver.Cols);
int textHeight = TextFormatter.MaxLines (message, textWidth); // message.Count (ustring.Make ('\n')) + 1;
int msgboxHeight = Math.Max (1, textHeight) + 4; // textHeight + (top + top padding + buttons + bottom)
int msgboxHeight = Math.Min (Math.Max (1, textHeight) + 4, Application.Driver.Rows); // textHeight + (top + top padding + buttons + bottom)

// Create button array for Dialog
int count = 0;
Expand Down Expand Up @@ -300,7 +300,7 @@ static int QueryFull (bool useErrorColors, int width, int height, ustring title,

if (width == 0 & height == 0) {
// Dynamically size Width
d.Width = Math.Max (maxWidthLine, Math.Max (title.ConsoleWidth, Math.Max (textWidth + 2, d.GetButtonsWidth ()))); // textWidth + (left + padding + padding + right)
d.Width = Math.Min (Math.Max (maxWidthLine, Math.Max (title.ConsoleWidth, Math.Max (textWidth + 2, d.GetButtonsWidth ()))), Application.Driver.Cols); // textWidth + (left + padding + padding + right)
}

// Setup actions
Expand Down
104 changes: 104 additions & 0 deletions UnitTests/MessageBoxTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,109 @@ public void MessageBox_With_A_Enough_Fixed_Size ()

Application.Run ();
}

[Fact, AutoInitShutdown]
public void MessageBox_With_A_Label_Without_Spaces ()
{
var iterations = -1;
Application.Begin (Application.Top);

Application.Iteration += () => {
iterations++;

if (iterations == 0) {
MessageBox.Query ("mywindow", new string ('f', 2000), "ok");

Application.RequestStop ();
} else if (iterations == 1) {
Application.Top.Redraw (Application.Top.Bounds);
GraphViewTests.AssertDriverContentsWithFrameAre (@"
┌ mywindow ────────────────────────────────────────────────────────────────────┐
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ [◦ ok ◦] │
└──────────────────────────────────────────────────────────────────────────────┘
", output);

Application.RequestStop ();
}
};

Application.Run ();
}

[Fact, AutoInitShutdown]
public void MessageBox_With_A_Label_With_Spaces ()
{
var iterations = -1;
Application.Begin (Application.Top);

Application.Iteration += () => {
iterations++;

if (iterations == 0) {
var sb = new StringBuilder ();
for (int i = 0; i < 1000; i++)
sb.Append ("ff ");

MessageBox.Query ("mywindow", sb.ToString (), "ok");

Application.RequestStop ();
} else if (iterations == 1) {
Application.Top.Redraw (Application.Top.Bounds);
GraphViewTests.AssertDriverContentsWithFrameAre (@"
┌ mywindow ────────────────────────────────────────────────────────────────────┐
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ [◦ ok ◦] │
└──────────────────────────────────────────────────────────────────────────────┘
", output);

Application.RequestStop ();
}
};

Application.Run ();
}
}
}

0 comments on commit d432d26

Please sign in to comment.