Skip to content

Commit f70c71a

Browse files
committed
Initial commit
0 parents  commit f70c71a

21 files changed

+1183
-0
lines changed

.gitignore

+405
Large diffs are not rendered by default.

R7.Webmate.Core/Class1.cs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//
2+
// Class1.cs
3+
//
4+
// Author:
5+
// Roman M. Yagodin <[email protected]>
6+
//
7+
// Copyright (c) 2019 Roman M. Yagodin
8+
//
9+
// This program is free software: you can redistribute it and/or modify
10+
// it under the terms of the GNU Lesser General Public License as published by
11+
// the Free Software Foundation, either version 3 of the License, or
12+
// (at your option) any later version.
13+
//
14+
// This program is distributed in the hope that it will be useful,
15+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
// GNU Lesser General Public License for more details.
18+
//
19+
// You should have received a copy of the GNU Lesser General Public License
20+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
22+
using System;
23+
24+
namespace R7.Webmate.Core
25+
{
26+
public class Class1
27+
{
28+
}
29+
}
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ProjectExtensions>
8+
<MonoDevelop>
9+
<Properties>
10+
<Policies>
11+
<StandardHeader IncludeInNewFiles="True" Text="&#xA; ${FileName}&#xA; &#xA; Author:&#xA; ${AuthorName} &lt;${AuthorEmail}&gt;&#xA; &#xA; Copyright (c) ${Year} ${CopyrightHolder}&#xA;&#xA; This program is free software: you can redistribute it and/or modify&#xA; it under the terms of the GNU Lesser General Public License as published by&#xA; the Free Software Foundation, either version 3 of the License, or&#xA; (at your option) any later version.&#xA;&#xA; This program is distributed in the hope that it will be useful,&#xA; but WITHOUT ANY WARRANTY; without even the implied warranty of&#xA; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the&#xA; GNU Lesser General Public License for more details.&#xA;&#xA; You should have received a copy of the GNU Lesser General Public License&#xA; along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;." />
12+
</Policies>
13+
</Properties>
14+
</MonoDevelop>
15+
</ProjectExtensions>
16+
</Project>

R7.Webmate.Xwt/Icons/FAIconHelper.cs

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//
2+
// FAImageHelper.cs
3+
//
4+
// Author:
5+
// Roman M. Yagodin <[email protected]>
6+
//
7+
// Copyright (c) 2019 Roman M. Yagodin
8+
//
9+
// This program is free software: you can redistribute it and/or modify
10+
// it under the terms of the GNU General Public License as published by
11+
// the Free Software Foundation, either version 3 of the License, or
12+
// (at your option) any later version.
13+
//
14+
// This program is distributed in the hope that it will be useful,
15+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
// GNU General Public License for more details.
18+
//
19+
// You should have received a copy of the GNU General Public License
20+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
22+
using System;
23+
using Xwt;
24+
using Xwt.Drawing;
25+
26+
namespace R7.Webmate.Xwt.Icons
27+
{
28+
public static class FAIconHelper
29+
{
30+
public static Image GetIcon (FAIconStyle style, string name)
31+
{
32+
// TODO: Cache loaded images
33+
return Image.FromFile ($"./icons/{style.ToString ().ToLowerInvariant ()}/{name}.svg");
34+
}
35+
36+
public static Image GetIcon (string name)
37+
{
38+
return GetIcon (FAIconStyle.Solid, name);
39+
}
40+
}
41+
}

R7.Webmate.Xwt/Icons/FAIconStyle.cs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// IconStyle.cs
3+
//
4+
// Author:
5+
// Roman M. Yagodin <[email protected]>
6+
//
7+
// Copyright (c) 2019 Roman M. Yagodin
8+
//
9+
// This program is free software: you can redistribute it and/or modify
10+
// it under the terms of the GNU General Public License as published by
11+
// the Free Software Foundation, either version 3 of the License, or
12+
// (at your option) any later version.
13+
//
14+
// This program is distributed in the hope that it will be useful,
15+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
// GNU General Public License for more details.
18+
//
19+
// You should have received a copy of the GNU General Public License
20+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
22+
using System;
23+
24+
namespace R7.Webmate.Xwt.Icons
25+
{
26+
public enum FAIconStyle
27+
{
28+
Solid,
29+
Regular,
30+
Brands
31+
}
32+
}

R7.Webmate.Xwt/MainWindow.cs

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//
2+
// MainWindow.cs
3+
//
4+
// Author:
5+
// Roman M. Yagodin <[email protected]>
6+
//
7+
// Copyright (c) 2019 Roman M. Yagodin
8+
//
9+
// This program is free software: you can redistribute it and/or modify
10+
// it under the terms of the GNU General Public License as published by
11+
// the Free Software Foundation, either version 3 of the License, or
12+
// (at your option) any later version.
13+
//
14+
// This program is distributed in the hope that it will be useful,
15+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
// GNU General Public License for more details.
18+
//
19+
// You should have received a copy of the GNU General Public License
20+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
22+
using NGettext;
23+
using Xwt;
24+
using R7.Webmate.Xwt.Icons;
25+
26+
namespace R7.Webmate.Xwt
27+
{
28+
public class MainWindow: Window
29+
{
30+
protected ICatalog T = TextCatalogKeeper.GetDefault ();
31+
32+
public MainWindow ()
33+
{
34+
Title = T.GetString ("R7.Webmate.Xwt - ") + OSHelper.GetXwtToolkit ().ToString ();
35+
Width = 500;
36+
Height = 400;
37+
38+
var notebook = new Notebook ();
39+
notebook.TabOrientation = NotebookTabOrientation.Bottom;
40+
notebook.Add (new TextCleanerWidget (), T.GetString ("Text Cleaner"));
41+
42+
var vbox = new VBox ();
43+
vbox.PackStart (notebook, true, true);
44+
45+
Content = vbox;
46+
Content.Show ();
47+
}
48+
}
49+
}

R7.Webmate.Xwt/Modules/Text/Text.psm1

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/usr/bin/pwsh
2+
3+
function Invoke-TextToText
4+
{
5+
[CmdletBinding()]
6+
param (
7+
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
8+
[string] $Text
9+
)
10+
process {
11+
$t = $_
12+
13+
# normalize endlines
14+
$t = $t -replace "\r\n", "\n"
15+
$t = $t -replace "\r", "\n"
16+
17+
# remove excess empty lines (more than \n\n)
18+
#$t = $t -replace "\n{3,}", "\n\n"
19+
20+
# replace tabs with spaces
21+
$t = $t -replace "\t", " "
22+
23+
# replace excess composite puntuation like !!!! => !!!
24+
#$t = $t -replace "([\.!?]){3,}", "$1$1$1"
25+
26+
# add spaces after punctuation
27+
#$t = $t -replace "[\.,;:\)\]\}\?!]+\s?", "$0 "
28+
29+
# remove spaces before "closing" punctuation
30+
#$t = $t -replace "\s+([\.,;:\)\]\}\?!])", "$1"
31+
32+
# remove extra punctuation before closing parenthesis
33+
$t = $t -replace "\.\)\.", ".)"
34+
$t = $t -replace "!\)!", "!)"
35+
$t = $t -replace "\?\)\?", "?)"
36+
37+
# remove duplicate whitespace
38+
$t = $t -replace "\s+", " "
39+
40+
# remove hyphens
41+
$t = $t -replace "¬", ""
42+
43+
# replace figure quotes in text output
44+
$t = $t -replace "«", '"'
45+
$t = $t -replace "»", '"'
46+
47+
# fix some common typos
48+
$t = $t -replace "г\.г\.", "гг."
49+
$t = $t -replace "с[\\/]х", "с.-х."
50+
$t = $t -replace "с\.х\.", "с.-х."
51+
52+
$t = $t.Trim()
53+
54+
Write-Output $t
55+
}
56+
}
57+
58+
function Invoke-TextToHtml
59+
{
60+
[CmdletBinding()]
61+
param (
62+
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
63+
[string] $Text
64+
)
65+
process {
66+
$t = $_
67+
68+
# enclose all text in the para
69+
$t = "<p>" + $t + "</p>"
70+
71+
# replace endlines with paras
72+
$t = $t -replace "\r\n", "</p><p>"
73+
$t = $t -replace "\n", "</p><p>"
74+
75+
# remove spaces before and after para tags
76+
$t = $t -replace "<p> ", "<p>"
77+
$t = $t -replace " </p>", "</p>"
78+
79+
# remove duplicate whitespace
80+
$t = $t -replace "\s+", " "
81+
82+
# remove empty paras
83+
$t = $t -replace "<p></p>", ""
84+
#$t = $t -replace "<p>\u00A0</p>", ""
85+
$t = $t -replace "<p>&#160;</p>", ""
86+
$t = $t -replace "<p>&nbsp;</p>", ""
87+
88+
# ...
89+
90+
Write-Output $t
91+
}
92+
}

R7.Webmate.Xwt/OSHelper.cs

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//
2+
// OSHelper.cs
3+
//
4+
// Author:
5+
// Roman M. Yagodin <[email protected]>
6+
//
7+
// Copyright (c) 2019 Roman M. Yagodin
8+
//
9+
// This program is free software: you can redistribute it and/or modify
10+
// it under the terms of the GNU General Public License as published by
11+
// the Free Software Foundation, either version 3 of the License, or
12+
// (at your option) any later version.
13+
//
14+
// This program is distributed in the hope that it will be useful,
15+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
// GNU General Public License for more details.
18+
//
19+
// You should have received a copy of the GNU General Public License
20+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
22+
using System.Runtime.InteropServices;
23+
using Xwt;
24+
25+
namespace R7.Webmate.Xwt
26+
{
27+
public static class OSHelper
28+
{
29+
public static bool IsWindows () => RuntimeInformation.IsOSPlatform (OSPlatform.Windows);
30+
31+
public static bool IsLinux () => RuntimeInformation.IsOSPlatform (OSPlatform.Linux);
32+
33+
public static bool IsOSX () => RuntimeInformation.IsOSPlatform (OSPlatform.OSX);
34+
35+
public static ToolkitType GetXwtToolkit ()
36+
{
37+
if (IsWindows ()) {
38+
return ToolkitType.Wpf;
39+
}
40+
41+
return ToolkitType.Gtk3;
42+
}
43+
}
44+
}

R7.Webmate.Xwt/PowerShellRunner.cs

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//
2+
// PowerShellRunner.cs
3+
//
4+
// Author:
5+
// Roman M. Yagodin <[email protected]>
6+
//
7+
// Copyright (c) 2019 Roman M. Yagodin
8+
//
9+
// This program is free software: you can redistribute it and/or modify
10+
// it under the terms of the GNU General Public License as published by
11+
// the Free Software Foundation, either version 3 of the License, or
12+
// (at your option) any later version.
13+
//
14+
// This program is distributed in the hope that it will be useful,
15+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
// GNU General Public License for more details.
18+
//
19+
// You should have received a copy of the GNU General Public License
20+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
22+
using System;
23+
using System.Management.Automation;
24+
using System.Collections.ObjectModel;
25+
26+
namespace R7.Webmate.Xwt
27+
{
28+
public class PowerShellRunner
29+
{
30+
public string TestScript (string text)
31+
{
32+
using (PowerShell psInstance = PowerShell.Create ()) {
33+
psInstance.AddScript (
34+
"param($Text); Write-Output $Text;"
35+
);
36+
37+
psInstance.AddParameter ("Text", text);
38+
Collection<PSObject> psOutput = psInstance.Invoke ();
39+
40+
foreach (PSObject outItem in psOutput) {
41+
Console.WriteLine (outItem.BaseObject.ToString ());
42+
}
43+
44+
return psInstance.Streams.Error.Count.ToString ();
45+
}
46+
47+
//return "No PS instance!";
48+
}
49+
50+
public string RunScript (string script, string text)
51+
{
52+
using (PowerShell psInstance = PowerShell.Create ()) {
53+
psInstance.AddScript (
54+
"param($Text)\n"
55+
+ "cd Scripts\n"
56+
+ "Import-Module ./TextToHtml.ps1\n"
57+
+ "Invoke-TextToText -Text $Text\n"
58+
);
59+
60+
psInstance.AddParameter ("Text", text);
61+
62+
Collection<PSObject> psOutput = psInstance.Invoke ();
63+
if (psInstance.Streams.Error.Count == 0) {
64+
foreach (PSObject outItem in psOutput) {
65+
if (outItem != null) {
66+
return outItem.BaseObject.GetType ().ToString ();
67+
}
68+
}
69+
}
70+
else {
71+
return psInstance.Streams.Error.Count.ToString ();
72+
}
73+
74+
75+
}
76+
return null;
77+
}
78+
}
79+
}

0 commit comments

Comments
 (0)