Browse Source

PowerShell output fills console window if width is larger than 80 characters.

pull/15/head
Matt Ward 15 years ago
parent
commit
e77c921ed8
  1. 1
      src/AddIns/BackendBindings/Scripting/Project/Src/IScriptingConsole.cs
  2. 5
      src/AddIns/BackendBindings/Scripting/Project/Src/IScriptingConsoleTextEditor.cs
  3. 5
      src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingConsole.cs
  4. 50
      src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingConsoleTextEditor.cs
  5. 11
      src/AddIns/BackendBindings/Scripting/Project/Src/ThreadSafeScriptingConsole.cs
  6. 23
      src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleTests.cs
  7. 39
      src/AddIns/BackendBindings/Scripting/Test/Console/ThreadSafeScriptingConsoleTests.cs
  8. 1
      src/AddIns/BackendBindings/Scripting/Test/ICSharpCode.Scripting.Tests.csproj
  9. 8
      src/AddIns/BackendBindings/Scripting/Test/Utils/FakeConsoleTextEditor.cs
  10. 6
      src/AddIns/BackendBindings/Scripting/Test/Utils/FakeScriptingConsole.cs
  11. 1
      src/AddIns/Misc/PackageManagement/Project/PackageManagement.csproj
  12. 6
      src/AddIns/Misc/PackageManagement/Project/Src/Scripting/PackageManagementConsoleView.xaml
  13. 112
      src/AddIns/Misc/PackageManagement/Project/Src/Scripting/PowerShellHostRawUserInterface.cs
  14. 4
      src/AddIns/Misc/PackageManagement/Project/Src/Scripting/PowerShellHostUserInterface.cs
  15. 32
      src/AddIns/Misc/PackageManagement/Test/Src/Scripting/PowerShellHostUserInterfaceTests.cs

1
src/AddIns/BackendBindings/Scripting/Project/Src/IScriptingConsole.cs

@ -18,5 +18,6 @@ namespace ICSharpCode.Scripting
void Write(string text, ScriptingStyle style); void Write(string text, ScriptingStyle style);
string ReadLine(int autoIndentSize); string ReadLine(int autoIndentSize);
string ReadFirstUnreadLine(); string ReadFirstUnreadLine();
int GetMaximumVisibleColumns();
} }
} }

5
src/AddIns/BackendBindings/Scripting/Project/Src/IScriptingConsoleTextEditor.cs

@ -79,5 +79,10 @@ namespace ICSharpCode.Scripting
void MakeCurrentContentReadOnly(); void MakeCurrentContentReadOnly();
void ScrollToEnd(); void ScrollToEnd();
/// <summary>
/// Returns the total number of columns/characters that are visible without scrolling.
/// </summary>
int GetMaximumVisibleColumns();
} }
} }

5
src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingConsole.cs

@ -352,5 +352,10 @@ namespace ICSharpCode.Scripting
{ {
textEditor.ScrollToEnd(); textEditor.ScrollToEnd();
} }
public int GetMaximumVisibleColumns()
{
return textEditor.GetMaximumVisibleColumns();
}
} }
} }

50
src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingConsoleTextEditor.cs

@ -2,10 +2,12 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System; using System;
using System.Drawing; using System.Globalization;
using System.Windows; using System.Windows;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading; using System.Windows.Threading;
using ICSharpCode.AvalonEdit; using ICSharpCode.AvalonEdit;
using ICSharpCode.AvalonEdit.CodeCompletion; using ICSharpCode.AvalonEdit.CodeCompletion;
using ICSharpCode.AvalonEdit.Document; using ICSharpCode.AvalonEdit.Document;
@ -16,9 +18,9 @@ namespace ICSharpCode.Scripting
public class ScriptingConsoleTextEditor : IScriptingConsoleTextEditor public class ScriptingConsoleTextEditor : IScriptingConsoleTextEditor
{ {
TextEditor textEditor; TextEditor textEditor;
Color customLineColour = Color.LightGray;
BeginReadOnlySectionProvider readOnlyRegion; BeginReadOnlySectionProvider readOnlyRegion;
CompletionWindow completionWindow; CompletionWindow completionWindow;
double? characterWidth;
public ScriptingConsoleTextEditor(TextEditor textEditor) public ScriptingConsoleTextEditor(TextEditor textEditor)
{ {
@ -42,10 +44,6 @@ namespace ICSharpCode.Scripting
textEditor.PreviewKeyDown -= OnTextEditorPreviewKeyDown; textEditor.PreviewKeyDown -= OnTextEditorPreviewKeyDown;
} }
public Color CustomLineColour {
get { return customLineColour; }
}
public void Write(string text) public void Write(string text)
{ {
TextLocation location = GetCurrentCursorLocation(); TextLocation location = GetCurrentCursorLocation();
@ -152,5 +150,45 @@ namespace ICSharpCode.Scripting
{ {
textEditor.ScrollToEnd(); textEditor.ScrollToEnd();
} }
public int GetMaximumVisibleColumns()
{
return (int)((textEditor.ViewportWidth + CharacterWidth - 1) / CharacterWidth);
}
double CharacterWidth {
get {
if (!characterWidth.HasValue) {
GetCharacterWidth();
}
return characterWidth.Value;
}
}
void GetCharacterWidth()
{
FormattedText formattedText = CreateFormattedTextForSingleCharacter();
characterWidth = formattedText.Width;
}
FormattedText CreateFormattedTextForSingleCharacter()
{
return new FormattedText(
"W",
CultureInfo.InvariantCulture,
textEditor.FlowDirection,
CreateTextEditorTypeFace(),
textEditor.FontSize,
textEditor.Foreground);
}
Typeface CreateTextEditorTypeFace()
{
return new Typeface(
textEditor.FontFamily,
textEditor.FontStyle,
textEditor.FontWeight,
textEditor.FontStretch);
}
} }
} }

11
src/AddIns/BackendBindings/Scripting/Project/Src/ThreadSafeScriptingConsole.cs

@ -13,6 +13,7 @@ namespace ICSharpCode.Scripting
delegate string ThreadSafeReadLineInvoker(int autoIndentSize); delegate string ThreadSafeReadLineInvoker(int autoIndentSize);
delegate string ThreadSafeReadFirstUnreadLineInvoker(); delegate string ThreadSafeReadFirstUnreadLineInvoker();
delegate int ThreadSafeGetMaximumVisibleColumnsInvoker();
public ThreadSafeScriptingConsole(IScriptingConsole nonThreadSafeScriptingConsole, IControlDispatcher dispatcher) public ThreadSafeScriptingConsole(IScriptingConsole nonThreadSafeScriptingConsole, IControlDispatcher dispatcher)
: this(nonThreadSafeScriptingConsole, new ThreadSafeScriptingConsoleEvents(), dispatcher) : this(nonThreadSafeScriptingConsole, new ThreadSafeScriptingConsoleEvents(), dispatcher)
@ -133,5 +134,15 @@ namespace ICSharpCode.Scripting
{ {
return nonThreadSafeScriptingConsole.ReadFirstUnreadLine(); return nonThreadSafeScriptingConsole.ReadFirstUnreadLine();
} }
public int GetMaximumVisibleColumns()
{
if (dispatcher.CheckAccess()) {
return nonThreadSafeScriptingConsole.GetMaximumVisibleColumns();
} else {
ThreadSafeGetMaximumVisibleColumnsInvoker action = GetMaximumVisibleColumns;
return (int)dispatcher.Invoke(action);
}
}
} }
} }

23
src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleTests.cs

@ -0,0 +1,23 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using NUnit.Framework;
namespace ICSharpCode.Scripting.Tests.Console
{
[TestFixture]
public class ScriptingConsoleTests : ScriptingConsoleTestsBase
{
[Test]
public void GetMaximumVisibleColumns_TextEditorMaximumVisibleColumnsnIsTen_ReturnsTen()
{
CreateConsole();
FakeConsoleTextEditor.MaximumVisibleColumns = 10;
int columns = TestableScriptingConsole.GetMaximumVisibleColumns();
Assert.AreEqual(10, columns);
}
}
}

39
src/AddIns/BackendBindings/Scripting/Test/Console/ThreadSafeScriptingConsoleTests.cs

@ -371,5 +371,44 @@ namespace ICSharpCode.Scripting.Tests.Console
Assert.IsFalse(threadSafeConsole.ScrollToEndWhenTextWritten); Assert.IsFalse(threadSafeConsole.ScrollToEndWhenTextWritten);
} }
[Test]
public void GetMaximumVisibleColumns_NonThreadSafeConsoleMaximumVisibleColumnsIsTen_ReturnsTen()
{
CreateThreadSafeScriptingConsole();
nonThreadSafeScriptingConsole.MaximumVisibleColumns = 10;
int columns = threadSafeConsole.GetMaximumVisibleColumns();
Assert.AreEqual(10, columns);
}
[Test]
public void GetMaximumVisibleColumns_DispatcherCheckAccessReturnsFalse_MethodIsInvoked()
{
CreateThreadSafeScriptingConsole();
dispatcher.CheckAccessReturnValue = false;
dispatcher.MethodInvoked = null;
dispatcher.InvokeReturnValue = 10;
int columns = threadSafeConsole.GetMaximumVisibleColumns();
Assert.IsNotNull(dispatcher.MethodInvoked);
}
[Test]
public void GetMaximumVisibleColumns_DispatcherCheckAccessReturnsFalse_DispatcherReturnValueIsReturned()
{
CreateThreadSafeScriptingConsole();
dispatcher.CheckAccessReturnValue = false;
dispatcher.MethodInvoked = null;
dispatcher.InvokeReturnValue = 10;
int columns = threadSafeConsole.GetMaximumVisibleColumns();
Assert.AreEqual(10, columns);
}
} }
} }

1
src/AddIns/BackendBindings/Scripting/Test/ICSharpCode.Scripting.Tests.csproj

@ -85,6 +85,7 @@
<Compile Include="Console\ScriptingConsoleReadTests.cs" /> <Compile Include="Console\ScriptingConsoleReadTests.cs" />
<Compile Include="Console\ScriptingConsoleSendLineTests.cs" /> <Compile Include="Console\ScriptingConsoleSendLineTests.cs" />
<Compile Include="Console\ScriptingConsoleSendTextTests.cs" /> <Compile Include="Console\ScriptingConsoleSendTextTests.cs" />
<Compile Include="Console\ScriptingConsoleTests.cs" />
<Compile Include="Console\ScriptingConsoleTestsBase.cs" /> <Compile Include="Console\ScriptingConsoleTestsBase.cs" />
<Compile Include="Console\ScriptingConsoleTextEditorTests.cs" /> <Compile Include="Console\ScriptingConsoleTextEditorTests.cs" />
<Compile Include="Console\ScriptingConsoleUnreadLinesTests.cs" /> <Compile Include="Console\ScriptingConsoleUnreadLinesTests.cs" />

8
src/AddIns/BackendBindings/Scripting/Test/Utils/FakeConsoleTextEditor.cs

@ -197,11 +197,17 @@ namespace ICSharpCode.Scripting.Tests.Utils
} }
public bool IsScrollToEndCalled; public bool IsScrollToEndCalled;
public bool ScrollToEndWhenPromptWritten { get; set; }
public void ScrollToEnd() public void ScrollToEnd()
{ {
IsScrollToEndCalled = true; IsScrollToEndCalled = true;
} }
public int MaximumVisibleColumns;
public int GetMaximumVisibleColumns()
{
return MaximumVisibleColumns;
}
} }
} }

6
src/AddIns/BackendBindings/Scripting/Test/Utils/FakeScriptingConsole.cs

@ -23,6 +23,8 @@ namespace ICSharpCode.Scripting.Tests.Utils
public string TextToReturnFromReadFirstUnreadLine; public string TextToReturnFromReadFirstUnreadLine;
public bool IsReadLineCalled; public bool IsReadLineCalled;
public bool IsDisposeCalled; public bool IsDisposeCalled;
public int MaximumVisibleColumns;
public bool ScrollToEndWhenTextWritten { get; set; } public bool ScrollToEndWhenTextWritten { get; set; }
public void SendLine(string text) public void SendLine(string text)
@ -77,9 +79,9 @@ namespace ICSharpCode.Scripting.Tests.Utils
IsDisposeCalled = true; IsDisposeCalled = true;
} }
public void ScrollToEnd() public int GetMaximumVisibleColumns()
{ {
return MaximumVisibleColumns;
} }
} }
} }

1
src/AddIns/Misc/PackageManagement/Project/PackageManagement.csproj

@ -142,6 +142,7 @@
<Compile Include="Src\PackagesViewModel.cs" /> <Compile Include="Src\PackagesViewModel.cs" />
<Compile Include="Src\Scripting\ErrorRecordFactory.cs" /> <Compile Include="Src\Scripting\ErrorRecordFactory.cs" />
<Compile Include="Src\Scripting\IErrorRecordFactory.cs" /> <Compile Include="Src\Scripting\IErrorRecordFactory.cs" />
<Compile Include="Src\Scripting\PowerShellHostRawUserInterface.cs" />
<Compile Include="Src\UpdatedPackagesViewModel.cs" /> <Compile Include="Src\UpdatedPackagesViewModel.cs" />
<Compile Include="Src\PackageViewModel.cs" /> <Compile Include="Src\PackageViewModel.cs" />
<Compile Include="Src\PackageViewModelFactory.cs" /> <Compile Include="Src\PackageViewModelFactory.cs" />

6
src/AddIns/Misc/PackageManagement/Project/Src/Scripting/PackageManagementConsoleView.xaml

@ -26,7 +26,7 @@
<UserControl.DataContext> <UserControl.DataContext>
<Binding Path="PackageManagementConsoleViewModel" Source="{StaticResource ViewModelLocator}"/> <Binding Path="PackageManagementConsoleViewModel" Source="{StaticResource ViewModelLocator}"/>
</UserControl.DataContext> </UserControl.DataContext>
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
@ -68,9 +68,9 @@
</Button> </Button>
</ToolBar> </ToolBar>
<ContentPresenter <ContentControl
Grid.Row="1" Grid.Row="1"
Margin="4, 0" Margin="4, 0"
Content="{Binding TextEditor}"/> Content="{Binding Path=TextEditor}"/>
</Grid> </Grid>
</UserControl> </UserControl>

112
src/AddIns/Misc/PackageManagement/Project/Src/Scripting/PowerShellHostRawUserInterface.cs

@ -0,0 +1,112 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Management.Automation.Host;
using ICSharpCode.Scripting;
namespace ICSharpCode.PackageManagement.Scripting
{
public class PowerShellHostRawUserInterface : PSHostRawUserInterface
{
IScriptingConsole scriptingConsole;
public const int MinimumColumns = 80;
public PowerShellHostRawUserInterface(IScriptingConsole scriptingConsole)
{
this.scriptingConsole = scriptingConsole;
}
public override string WindowTitle { get; set; }
public override Size WindowSize {
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}
public override Size BufferSize {
get {
int columns = GetColumns();
return new Size(columns, 0);
}
set { throw new NotImplementedException(); }
}
int GetColumns()
{
int width = scriptingConsole.GetMaximumVisibleColumns();
if (width > MinimumColumns) {
return width;
}
return MinimumColumns;
}
public override Coordinates WindowPosition {
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}
public override void SetBufferContents(Rectangle rectangle, BufferCell fill)
{
throw new NotImplementedException();
}
public override void SetBufferContents(Coordinates origin, BufferCell[,] contents)
{
throw new NotImplementedException();
}
public override void ScrollBufferContents(Rectangle source, Coordinates destination, Rectangle clip, BufferCell fill)
{
throw new NotImplementedException();
}
public override KeyInfo ReadKey(ReadKeyOptions options)
{
throw new NotImplementedException();
}
public override Size MaxWindowSize {
get { throw new NotImplementedException(); }
}
public override Size MaxPhysicalWindowSize {
get { throw new NotImplementedException(); }
}
public override bool KeyAvailable {
get { throw new NotImplementedException(); }
}
public override BufferCell[,] GetBufferContents(Rectangle rectangle)
{
throw new NotImplementedException();
}
public override ConsoleColor ForegroundColor {
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}
public override void FlushInputBuffer()
{
throw new NotImplementedException();
}
public override int CursorSize {
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}
public override Coordinates CursorPosition {
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}
public override ConsoleColor BackgroundColor {
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}
}
}

4
src/AddIns/Misc/PackageManagement/Project/Src/Scripting/PowerShellHostUserInterface.cs

@ -15,10 +15,12 @@ namespace ICSharpCode.PackageManagement.Scripting
public class PowerShellHostUserInterface : PSHostUserInterface public class PowerShellHostUserInterface : PSHostUserInterface
{ {
IScriptingConsole scriptingConsole; IScriptingConsole scriptingConsole;
PowerShellHostRawUserInterface rawUI;
public PowerShellHostUserInterface(IScriptingConsole scriptingConsole) public PowerShellHostUserInterface(IScriptingConsole scriptingConsole)
{ {
this.scriptingConsole = scriptingConsole; this.scriptingConsole = scriptingConsole;
rawUI = new PowerShellHostRawUserInterface(scriptingConsole);
} }
public override void WriteWarningLine(string message) public override void WriteWarningLine(string message)
@ -71,7 +73,7 @@ namespace ICSharpCode.PackageManagement.Scripting
} }
public override PSHostRawUserInterface RawUI { public override PSHostRawUserInterface RawUI {
get { return null; } get { return rawUI; }
} }
public override PSCredential PromptForCredential(string caption, string message, string userName, string targetName, PSCredentialTypes allowedCredentialTypes, System.Management.Automation.PSCredentialUIOptions options) public override PSCredential PromptForCredential(string caption, string message, string userName, string targetName, PSCredentialTypes allowedCredentialTypes, System.Management.Automation.PSCredentialUIOptions options)

32
src/AddIns/Misc/PackageManagement/Test/Src/Scripting/PowerShellHostUserInterfaceTests.cs

@ -158,5 +158,37 @@ namespace PackageManagement.Tests.Scripting
Assert.AreEqual(-1, result); Assert.AreEqual(-1, result);
} }
[Test]
public void RawUIBufferSize_ScriptingConsoleHas90MaximumVisibleColumns_ReturnsSizeWithWidthOf90()
{
CreateHostUserInterface();
scriptingConsole.MaximumVisibleColumns = 90;
Size actualSize = hostUI.RawUI.BufferSize;
Size expectedSize = new Size() {
Width = 90,
Height = 0
};
Assert.AreEqual(expectedSize, actualSize);
}
[Test]
public void RawUIBufferSize_ScriptingConsoleHas79MaxVisibleColumns_ReturnsSizeWithMinimumWidthOf80()
{
CreateHostUserInterface();
scriptingConsole.MaximumVisibleColumns = 79;
Size actualSize = hostUI.RawUI.BufferSize;
Size expectedSize = new Size() {
Width = 80,
Height = 0
};
Assert.AreEqual(expectedSize, actualSize);
}
} }
} }

Loading…
Cancel
Save