Skip to content

Commit 7e9dd39

Browse files
author
FriedrichWeinmann
committed
Added library
1 parent 4c44643 commit 7e9dd39

7 files changed

Lines changed: 331 additions & 3 deletions

File tree

.gitignore

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@
55
.vscode/*
66
*.psproj
77

8+
# Ignore staging info from Visual Studio
9+
library/PSModuleDevelopment/.vs/PSModuleDevelopment/v15/.suo
10+
library/PSModuleDevelopment/PSModuleDevelopment/bin/*
11+
library/PSModuleDevelopment/PSModuleDevelopment/obj/*
12+
813
# ignore library
9-
PSModuleDevelopment/bin/PSModuleDevelopment.dll
10-
PSModuleDevelopment/bin/PSModuleDevelopment.xml
11-
PSModuleDevelopment/bin/PSModuleDevelopment.pdb
14+
# PSModuleDevelopment/bin/PSModuleDevelopment.dll
15+
# PSModuleDevelopment/bin/PSModuleDevelopment.xml
16+
# PSModuleDevelopment/bin/PSModuleDevelopment.pdb
1217

1318
# ignore PowerShell Studio MetaData
1419
PSModuleDevelopment/PSModuleDevelopment.psproj
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.26228.4
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PSModuleDevelopment", "PSModuleDevelopment\PSModuleDevelopment.csproj", "{E4DF9863-EBAD-4DF5-9BAC-F446B4E458F2}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{E4DF9863-EBAD-4DF5-9BAC-F446B4E458F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{E4DF9863-EBAD-4DF5-9BAC-F446B4E458F2}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{E4DF9863-EBAD-4DF5-9BAC-F446B4E458F2}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{E4DF9863-EBAD-4DF5-9BAC-F446B4E458F2}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{E4DF9863-EBAD-4DF5-9BAC-F446B4E458F2}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>PSModuleDevelopment</RootNamespace>
11+
<AssemblyName>PSModuleDevelopment</AssemblyName>
12+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<DebugSymbols>true</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<Optimize>false</Optimize>
19+
<OutputPath>bin\Debug\</OutputPath>
20+
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<ErrorReport>prompt</ErrorReport>
22+
<WarningLevel>4</WarningLevel>
23+
</PropertyGroup>
24+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25+
<DebugType>pdbonly</DebugType>
26+
<Optimize>true</Optimize>
27+
<OutputPath>bin\Release\</OutputPath>
28+
<DefineConstants>TRACE</DefineConstants>
29+
<ErrorReport>prompt</ErrorReport>
30+
<WarningLevel>4</WarningLevel>
31+
</PropertyGroup>
32+
<ItemGroup>
33+
<Reference Include="System" />
34+
<Reference Include="System.Core" />
35+
<Reference Include="System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
36+
<SpecificVersion>False</SpecificVersion>
37+
<HintPath>C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Management.Automation\v4.0_3.0.0.0__31bf3856ad364e35\System.Management.Automation.dll</HintPath>
38+
<Private>False</Private>
39+
</Reference>
40+
<Reference Include="System.Xml.Linq" />
41+
<Reference Include="System.Data.DataSetExtensions" />
42+
<Reference Include="Microsoft.CSharp" />
43+
<Reference Include="System.Data" />
44+
<Reference Include="System.Net.Http" />
45+
<Reference Include="System.Xml" />
46+
</ItemGroup>
47+
<ItemGroup>
48+
<Compile Include="Properties\AssemblyInfo.cs" />
49+
<Compile Include="Utility\TextAlignment.cs" />
50+
<Compile Include="Utility\TextHeader.cs" />
51+
<Compile Include="Utility\UtilityHost.cs" />
52+
</ItemGroup>
53+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
54+
</Project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("PSModuleDevelopment")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("PSModuleDevelopment")]
13+
[assembly: AssemblyCopyright("Copyright © 2017")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("e4df9863-ebad-4df5-9bac-f446b4e458f2")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace PSModuleDevelopment.Utility
8+
{
9+
/// <summary>
10+
/// What a text can be aligned to
11+
/// </summary>
12+
public enum TextAlignment
13+
{
14+
/// <summary>
15+
/// The text should be left-aligned
16+
/// </summary>
17+
Left,
18+
19+
/// <summary>
20+
/// The text should be centered
21+
/// </summary>
22+
Center,
23+
24+
/// <summary>
25+
/// The text should be right aligned
26+
/// </summary>
27+
Right
28+
}
29+
}
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace PSModuleDevelopment.Utility
8+
{
9+
/// <summary>
10+
/// Object containing information
11+
/// </summary>
12+
public class TextHeader
13+
{
14+
/// <summary>
15+
/// The text of the header
16+
/// </summary>
17+
public string Text { get; set; }
18+
19+
/// <summary>
20+
/// The number of lines the header text has
21+
/// </summary>
22+
public int LinesOfText
23+
{
24+
get
25+
{
26+
return Text.Split('\n').Length;
27+
}
28+
}
29+
30+
/// <summary>
31+
/// The maximum width any line of text has.
32+
/// </summary>
33+
public int WidthOfText
34+
{
35+
get
36+
{
37+
int result = 0;
38+
foreach (string line in Text.Split('\n'))
39+
if (line.Length > result)
40+
result = line.Length;
41+
return result;
42+
}
43+
}
44+
45+
/// <summary>
46+
/// The symbol of the left top corner
47+
/// </summary>
48+
public string CornerLT = "#";
49+
/// <summary>
50+
/// The symbol of the right top corner
51+
/// </summary>
52+
public string CornerRT = "#";
53+
/// <summary>
54+
/// The symbol of the left bottom corner
55+
/// </summary>
56+
public string CornerLB = "#";
57+
/// <summary>
58+
/// The symbol of the right bottom corner
59+
/// </summary>
60+
public string CornerRB = "#";
61+
/// <summary>
62+
/// The symbol of the right border
63+
/// </summary>
64+
public string BorderRight = "#";
65+
/// <summary>
66+
/// The symbol of the left border
67+
/// </summary>
68+
public string BorderLeft = "#";
69+
/// <summary>
70+
/// The symbol of the top border
71+
/// </summary>
72+
public string BorderTop = "-";
73+
/// <summary>
74+
/// The symbol of the bottom border
75+
/// </summary>
76+
public string BorderBottom = "-";
77+
78+
/// <summary>
79+
/// Whether the header should be as wide as the window running the code
80+
/// </summary>
81+
public bool MaxWidth = true;
82+
83+
/// <summary>
84+
/// How wide should the header be, if it isn't set to max. Anything shorter than the text width will be ignored
85+
/// </summary>
86+
public int Width = -1;
87+
88+
/// <summary>
89+
/// How the text should be aligned within the header
90+
/// </summary>
91+
public TextAlignment TextAlignment = TextAlignment.Center;
92+
93+
/// <summary>
94+
/// Whether the text should be padded on the side it is aligned to
95+
/// </summary>
96+
public int Padding;
97+
98+
public TextHeader(string Text)
99+
{
100+
this.Text = Text;
101+
}
102+
103+
public override string ToString()
104+
{
105+
StringBuilder result = new StringBuilder();
106+
107+
// Process Width
108+
int effectivePadding = 0;
109+
if (TextAlignment != TextAlignment.Center)
110+
effectivePadding = Padding;
111+
112+
int width = Width;
113+
if (MaxWidth)
114+
width = UtilityHost.RawUI.WindowSize.Width;
115+
if ((WidthOfText + effectivePadding + 2 + BorderLeft.Length + BorderRight.Length) > width)
116+
width = WidthOfText + effectivePadding + 2 + BorderLeft.Length + BorderRight.Length;
117+
int effectiveContentWidth = width - 2 - BorderLeft.Length - BorderRight.Length;
118+
119+
// Process Top Line
120+
result = result.Append(CornerLT);
121+
for (int n = 0; n < (effectiveContentWidth + 2); n++)
122+
result = result.Append(BorderTop);
123+
result = result.Append(CornerRT + "\n");
124+
125+
// Process Content
126+
foreach (string line in Text.Split('\n'))
127+
{
128+
result = result.Append(BorderLeft + " ");
129+
int spaceLeft = 0;
130+
int spaceRight = 0;
131+
if (TextAlignment == TextAlignment.Left)
132+
{
133+
spaceLeft += Padding;
134+
spaceRight = effectiveContentWidth - line.Length - spaceLeft;
135+
}
136+
else if (TextAlignment == TextAlignment.Right)
137+
{
138+
spaceRight += Padding;
139+
spaceLeft = effectiveContentWidth - line.Length - spaceRight;
140+
}
141+
else
142+
{
143+
spaceLeft = (effectiveContentWidth - line.Length) / 2;
144+
spaceRight = effectiveContentWidth - line.Length - spaceLeft;
145+
}
146+
147+
result = result.Append(' ', spaceLeft);
148+
result = result.Append(line);
149+
result = result.Append(' ', spaceRight);
150+
result = result.Append(" " + BorderRight + "\n");
151+
}
152+
153+
// Process Bottom Line
154+
result = result.Append(CornerLB);
155+
for (int n = 0; n < (effectiveContentWidth + 2); n++)
156+
result = result.Append(BorderBottom);
157+
result = result.Append(CornerRB);
158+
159+
return result.ToString();
160+
}
161+
}
162+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Management.Automation.Host;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace PSModuleDevelopment.Utility
9+
{
10+
/// <summary>
11+
/// Host class, containing statics in support of the utility namespace
12+
/// </summary>
13+
public static class UtilityHost
14+
{
15+
/// <summary>
16+
/// Gives access to the host UI, in order to access window information
17+
/// </summary>
18+
public static PSHostRawUserInterface RawUI;
19+
}
20+
}

0 commit comments

Comments
 (0)