Skip to content

Commit

Permalink
Add APIs and skeleton ITerminalRenderer
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya Biryukov committed May 30, 2018
1 parent 6cb23f2 commit 7f1ef57
Show file tree
Hide file tree
Showing 16 changed files with 464 additions and 27 deletions.
1 change: 1 addition & 0 deletions Microsoft.VisualStudio.Terminal.Embeddable/ITerminal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Microsoft.VisualStudio.Terminal
{
/// <summary>
/// Handle to a specific terminal instance.
/// A terminal also implements ITerminalWindow interface
/// </summary>
[ComImport, Guid("E195D61C-2821-49F1-BE0E-B2CD82F1F856")]
public interface ITerminal
Expand Down
64 changes: 64 additions & 0 deletions Microsoft.VisualStudio.Terminal.Embeddable/ITerminalRenderer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using System.IO;
using System.Runtime.InteropServices;

namespace Microsoft.VisualStudio.Terminal
{
/// <summary>
/// Terminal renderer
/// </summary>
[ComImport, Guid("150B7535-03F9-41C0-9515-17ECB8199FFE")]

public interface ITerminalRenderer : ITerminalWindow
{
/// <summary>
/// Gets or sets the stream of terminal IO.
/// The terminal will read from the stream to render the output and will write to it
/// when there is user input.
/// If reading returns 0 byte, the terminal is closed.
/// The terminal assumes the data in the stream has UTF-8 encoding.
/// Only sequential access is needed.
/// If there is no stream set (the value is null),
/// the terminal renderer doesn't show any output and ignores user input.
/// </summary>
Stream Stream { get; set; }

/// <summary>
/// A value indicating whether the render dimensions are fixed (true)
/// or follow the windows size (false, the default).
/// </summary>
bool IsFixedDimensions { get; set; }

/// <summary>
/// Gets current rows
/// </summary>
int Rows { get; }

/// <summary>
/// Gets current cols
/// </summary>
int Cols { get; }

/// <summary>
/// Gets number of rows that can fit terminal window.
/// Setting more rows than this value can cause extra scroll bar to appear.
/// </summary>
int WindowRows { get; }

/// <summary>
/// Gets number of cols that can fit terminal window.
/// Setting more cols that this value can cause extral scroll bar to appear.
/// </summary>
int WindowCols { get; }

/// <summary>
/// An event that is fired when the terminal window is resized and either WindowRows or WindowCols have changed.
/// </summary>
event EventHandler WindowResized;

/// <summary>
/// Resizes the terminal renderer, changing its Rows and Cols dimensions.
/// </summary>
void Resize(int rows, int cols);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Threading.Tasks;

namespace Microsoft.VisualStudio.Terminal
{
[ComImport, Guid("250301DA-0BEA-4C4E-B199-C363C7C164B2")]
public interface ITerminalRendererService
{
/// <summary>
/// Create a new terminal renderer instance with the given name.
/// </summary>
/// <param name="name">The name that will be displayed as the tool window title.</param>
/// <returns>An instance of ITerminalRenderer</returns>
Task<object> CreateTerminalRendererAsync(string name);
}
}
37 changes: 37 additions & 0 deletions Microsoft.VisualStudio.Terminal.Embeddable/ITerminalWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Runtime.InteropServices;
using System.Threading.Tasks;

namespace Microsoft.VisualStudio.Terminal
{
/// <summary>
/// Terminal window
/// </summary>
[ComImport, Guid("4B833FE7-385E-4C2A-B207-1732213035FE")]
public interface ITerminalWindow
{
/// <summary>
/// Shows the terminal window.
/// </summary>
/// <returns>A <see cref="Task"/> that completes once the tool window has been shown.</returns>
Task ShowAsync();

/// <summary>
/// Hides the terminal window.
/// </summary>
/// <returns>A <see cref="Task"/> that completes once the tool window has been hidden.</returns>
Task HideAsync();

/// <summary>
/// Closes the terminal window and destroys the underlying terminal instance.
/// It is considered an error to call any methods on this object after close has been called.
/// </summary>
/// <returns>A <see cref="Task"/> that completes once the tool window has been closed.</returns>
Task CloseAsync();

/// <summary>
/// An event that is fired when the terminal closes.
/// </summary>
event EventHandler Closed;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Microsoft.VisualStudio.Terminal
{
internal interface IRendererScriptingObject
{
string GetTheme();
string GetFontFamily();
int GetFontSize();
void InitPty(int cols, int rows, string directory);
void ClosePty();
void CopyStringToClipboard(string stringToCopy);
string GetClipboard();
void TermData(string data);
void ResizePty(int cols, int rows);
string GetLinkRegex();
void HandleLocalLink(string uri);
bool ValidateLocalLink(string link);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Windows;

namespace Microsoft.VisualStudio.Terminal
{
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
[ComVisible(true)]
public class RendererScriptingObject : IRendererScriptingObject
{
private readonly TermWindowPackage package;

internal RendererScriptingObject(TermWindowPackage package)
{
this.package = package;
}

public string GetTheme()
{
return TerminalThemer.GetTheme();
}

public string GetFontFamily()
{
return this.package.OptionFontFamily;
}

public int GetFontSize()
{
return this.package.OptionFontSize;
}

public void ClosePty()
{
// Close pty
}

public void CopyStringToClipboard(string stringToCopy)
{
Clipboard.SetText(stringToCopy ?? "");
}

public string GetClipboard()
{
return Clipboard.GetText();
}

public string GetLinkRegex()
{
return TerminalRegex.LocalLinkRegex.ToString();
}

public void HandleLocalLink(string uri)
{
TerminalRegex.HandleLocalLink(uri);
}

public void InitPty(int cols, int rows, string directory)
{
string configuredShellPath;
if (this.package.OptionTerminal == DefaultTerminal.Other)
{
configuredShellPath = this.package.OptionShellPath;
}
else
{
configuredShellPath = this.package.OptionTerminal.ToString();
}

// this.ptyService.InvokeAsync("initTerm", this.shellPath ?? configuredShellPath, cols, rows, directory, ((object)this.args) ?? this.package.OptionStartupArgument, env).FileAndForget("WhackWhackTerminal/InitPty");
}

public void ResizePty(int cols, int rows)
{
// this.ptyService.InvokeAsync("resizeTerm", cols, rows).FileAndForget("WhackWhackTerminal/ResizePty");
}

public void TermData(string data)
{
// this.ptyService.InvokeAsync("termData", data).FileAndForget("WhackWhackTerminal/TermData");
}

public bool ValidateLocalLink(string link)
{
return TerminalRegex.ValidateLocalLink(link);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.TypeScript.MSBuild.2.8.3\build\Microsoft.TypeScript.MSBuild.props" Condition="Exists('..\packages\Microsoft.TypeScript.MSBuild.2.8.3\build\Microsoft.TypeScript.MSBuild.props')" />
<Import Project="..\packages\Microsoft.VSSDK.BuildTools.15.5.100\build\Microsoft.VSSDK.BuildTools.props" Condition="Exists('..\packages\Microsoft.VSSDK.BuildTools.15.5.100\build\Microsoft.VSSDK.BuildTools.props')" />
<Import Project="..\packages\Microsoft.TypeScript.MSBuild.2.7.1\build\Microsoft.TypeScript.MSBuild.props" Condition="Exists('..\packages\Microsoft.TypeScript.MSBuild.2.7.1\build\Microsoft.TypeScript.MSBuild.props')" />
<PropertyGroup>
<MinimumVisualStudioVersion>15.0</MinimumVisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
Expand Down Expand Up @@ -84,12 +84,18 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="BrowserBridge\BetterBrowser.cs" />
<Compile Include="BrowserBridge\IRendererScriptingObject.cs" />
<Compile Include="BrowserBridge\ITerminalScriptingObject.cs" />
<Compile Include="BrowserBridge\TerminalRegex.cs" />
<Compile Include="BrowserBridge\RendererScriptingObject.cs" />
<Compile Include="BrowserBridge\TerminalScriptingObject.cs" />
<Compile Include="BrowserBridge\TerminalEvent.cs" />
<Compile Include="BrowserBridge\TerminalThemer.cs" />
<Compile Include="RendererToolWindow.cs" />
<Compile Include="ServiceToolWindow.cs" />
<Compile Include="RendererToolWindowControl.xaml.cs">
<DependentUpon>RendererToolWindowControl.xaml</DependentUpon>
</Compile>
<Compile Include="ServiceToolWindowControl.xaml.cs">
<DependentUpon>ServiceToolWindowControl.xaml</DependentUpon>
</Compile>
Expand All @@ -111,6 +117,7 @@
</Compile>
<Compile Include="TermWindowPackage.cs" />
<Compile Include="ToolWindowContext.cs" />
<Compile Include="VsService\TerminalRenderer.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="BrandWhackWhackTerminal_256x.png">
Expand Down Expand Up @@ -153,6 +160,10 @@
</VSCTCompile>
</ItemGroup>
<ItemGroup>
<Page Include="RendererToolWindowControl.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="ServiceToolWindowControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -370,12 +381,11 @@
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.VSSDK.BuildTools.15.5.100\build\Microsoft.VSSDK.BuildTools.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.VSSDK.BuildTools.15.5.100\build\Microsoft.VSSDK.BuildTools.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.VSSDK.BuildTools.15.5.100\build\Microsoft.VSSDK.BuildTools.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.VSSDK.BuildTools.15.5.100\build\Microsoft.VSSDK.BuildTools.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.TypeScript.MSBuild.2.7.1\build\Microsoft.TypeScript.MSBuild.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.TypeScript.MSBuild.2.7.1\build\Microsoft.TypeScript.MSBuild.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.TypeScript.MSBuild.2.7.1\build\Microsoft.TypeScript.MSBuild.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.TypeScript.MSBuild.2.7.1\build\Microsoft.TypeScript.MSBuild.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.VisualStudio.SDK.EmbedInteropTypes.15.0.16\build\Microsoft.VisualStudio.SDK.EmbedInteropTypes.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.VisualStudio.SDK.EmbedInteropTypes.15.0.16\build\Microsoft.VisualStudio.SDK.EmbedInteropTypes.targets'))" />
<Error Condition="!Exists('..\packages\Nerdbank.GitVersioning.2.1.23\build\Nerdbank.GitVersioning.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Nerdbank.GitVersioning.2.1.23\build\Nerdbank.GitVersioning.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.TypeScript.MSBuild.2.8.3\build\Microsoft.TypeScript.MSBuild.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.TypeScript.MSBuild.2.8.3\build\Microsoft.TypeScript.MSBuild.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.TypeScript.MSBuild.2.8.3\build\Microsoft.TypeScript.MSBuild.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.TypeScript.MSBuild.2.8.3\build\Microsoft.TypeScript.MSBuild.targets'))" />
</Target>
<Import Project="..\packages\Microsoft.TypeScript.MSBuild.2.7.1\build\Microsoft.TypeScript.MSBuild.targets" Condition="Exists('..\packages\Microsoft.TypeScript.MSBuild.2.7.1\build\Microsoft.TypeScript.MSBuild.targets')" />
<Import Project="..\packages\Microsoft.VSSDK.BuildTools.15.5.100\build\Microsoft.VSSDK.BuildTools.targets" Condition="Exists('..\packages\Microsoft.VSSDK.BuildTools.15.5.100\build\Microsoft.VSSDK.BuildTools.targets')" />
<Target Name="AddTsToContent" AfterTargets="CompileTypeScript" Condition="'$(BuildingProject)' != 'false'">
<ItemGroup>
Expand Down Expand Up @@ -405,6 +415,7 @@
</Target>
<Import Project="..\packages\Microsoft.VisualStudio.SDK.EmbedInteropTypes.15.0.16\build\Microsoft.VisualStudio.SDK.EmbedInteropTypes.targets" Condition="Exists('..\packages\Microsoft.VisualStudio.SDK.EmbedInteropTypes.15.0.16\build\Microsoft.VisualStudio.SDK.EmbedInteropTypes.targets')" />
<Import Project="..\packages\Nerdbank.GitVersioning.2.1.23\build\Nerdbank.GitVersioning.targets" Condition="Exists('..\packages\Nerdbank.GitVersioning.2.1.23\build\Nerdbank.GitVersioning.targets')" />
<Import Project="..\packages\Microsoft.TypeScript.MSBuild.2.8.3\build\Microsoft.TypeScript.MSBuild.targets" Condition="Exists('..\packages\Microsoft.TypeScript.MSBuild.2.8.3\build\Microsoft.TypeScript.MSBuild.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
23 changes: 23 additions & 0 deletions Microsoft.VisualStudio.Terminal/RendererToolWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio.Shell;

namespace Microsoft.VisualStudio.Terminal
{
/// <summary>
/// This class implements the tool window exposed by this package and hosts a user control.
/// </summary>
[Guid(ToolWindowGuid)]
public class RendererToolWindow : ToolWindowPane
{
public const string ToolWindowGuid = "7f989465-4c63-4820-aa1c-c320682d2c73";

/// <summary>
/// Initializes a new instance of the <see cref="RendererToolWindow"/> class.
/// </summary>
public RendererToolWindow(TermWindowPackage package) : base(null)
{
this.Content = new RendererToolWindowControl(package);
}
}
}
15 changes: 15 additions & 0 deletions Microsoft.VisualStudio.Terminal/RendererToolWindowControl.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Microsoft.VisualStudio.Terminal"
xmlns:platformui="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.15.0"
x:Class="Microsoft.VisualStudio.Terminal.RendererToolWindowControl"
Background="{DynamicResource VsBrush.Window}"
Foreground="{DynamicResource VsBrush.WindowText}"
x:Name="MyToolWindow">
<Grid x:Name="mainGrid">
<local:BetterBrowser x:Name="terminalView" />
</Grid>
</UserControl>
Loading

0 comments on commit 7f1ef57

Please sign in to comment.