Skip to content

Commit 2ac8d96

Browse files
committed
RC1 v2.0.4
1 parent 2ea425a commit 2ac8d96

File tree

17 files changed

+85
-43
lines changed

17 files changed

+85
-43
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ PS > out-winprint -verbose
1818
VERBOSE: Out-WinPrint 2.0.3.0 - Copyright Kindel Systems, LLC - https://tig.github.io/winprint
1919
```
2020

21-
Print `Program.cs` using the default sheet definition and default printer:
21+
Print a Powershell profile using the default sheet definition and default printer:
2222

2323
```powershell
24-
get-content Program.cs | out-winprint
24+
Get-Content $profile.CurrentUserAllHosts | winprint -Language powershell
2525
```
2626

2727
```powershell
2828
PS > cat Program.cs | wp -PrinterName PDF -Orientation Portrait -Verbose -Title Program.cs
29-
VERBOSE: Out-WinPrint 2.0.3.0 - Copyright Kindel Systems, LLC - https://tig.github.io/winprint
29+
VERBOSE: Out-WinPrint 2.0.4.0 - Copyright Kindel Systems, LLC - https://tig.github.io/winprint
3030
VERBOSE: Printer: PDF
3131
VERBOSE: Paper Size: Letter
3232
VERBOSE: Orientation: Portrait

docs/index.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ VERBOSE: Out-WinPrint 2.0.3.0 - Copyright Kindel Systems, LLC - https://tig.gith
1313
```
1414

1515
```powershell
16-
get-content Program.cs | wp
16+
out-winprint Program.cs
17+
```
18+
19+
```powershell
20+
cat $profile.CurrentUserAllHosts | wp -Language powershell
1721
```
1822

1923
```powershell
@@ -22,7 +26,7 @@ ls .\* -include ('*.c', '*.h') | foreach { cat $_.FullName | out-winprint -p "La
2226

2327
## Features
2428

25-
* Print source code with syntax highlighting and line numbering for over 200 programming langauges and file formats.
29+
* Print source code with syntax highlighting and line numbering for over 200 programming languages and file formats.
2630
* Print HTML files.
2731
* Print "multiple-pages-up" on one piece of paper (saves trees!)
2832
* Complete control over page formatting options, including headers and footers, margins, fonts, page orientation, etc...
@@ -41,7 +45,17 @@ See [User's Guide](users-guide.md) for more details.
4145

4246
See [About](about.md) for the history prior to *winprint 2.0*.
4347

44-
* 12-Apr-2020 - 2.0.0.6100 (Beta1) - Updated PowerShell cmdlet to run as a standalone app (e.g. wp foo.cs or out-winprint foo.cs.
48+
* 30-Apr-2020 - 2.0.4 (RC1) - Totally new rendering engine
49+
* Replaced the nodejs `Prism.js`-based syntax highlighter with the Python `Pigyments`-based system. This:
50+
* Long lines now wrap correctly. Issue #12
51+
* Significantly increased file load/rendering speed. Issue #13.
52+
* Space and tabs now render accurately. Issue #14
53+
* Improved syntax highlighting in almost every way. More reliable, better language support, more sophisticated lexers.
54+
* Provided a simple way to select styles (e.g. `"style": "pastie"` in `.config` file).
55+
* Enabled printing of ANSI Escape sequence encoded files (because `winprint` uses Pygments `terminal` formatter as input).
56+
* Removed dependency on nodejs. Issue #17
57+
* Dozens of small bug fixes and improvements.
58+
* 12-Apr-2020 - 2.0.0.6100 (Beta3) - Updated PowerShell cmdlet to run as a standalone app (e.g. wp foo.cs or out-winprint foo.cs.
4559
* Added ability to choose fonts from GUI
4660
* fixed print preview status bugs
4761
* Code refactoring; because why leave good enough alone?

docs/install.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Installation Instructions
22

3-
***winprint*** 2.0 is in beta. It works well (on my machine), and I've had a dozen or so users verify it works well for them; see [Issues](https://github.com/tig/winprint/issues).*
3+
***winprint*** 2.0 is almost not beta. It works well (on my machine), and I've had a dozen or so users verify it works well for them; see [Issues](https://github.com/tig/winprint/issues).*
44

55
*Please report any problems or feature requests [here](https://github.com/tig/winprint/issues).*
66

docs/users-guide.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Features
44

5-
* Print source code with syntax highlighting and line numbering for over 200 programming langauges and file formats.
5+
* Print source code with syntax highlighting and line numbering for over 200 programming languages and file formats.
66
* Print HTML files.
77
* Print "multiple-pages-up" on one piece of paper (saves trees!)
88
* Complete control over page formatting options, including headers and footers, margins, fonts, page orientation, etc...
@@ -39,7 +39,7 @@ See what version is installed:
3939

4040
```powershell
4141
PS > out-winprint -verbose
42-
VERBOSE: Out-WinPrint 2.0.0.3912 - Copyright Kindel Systems, LLC - https://tig.github.io/winprint
42+
VERBOSE: Out-WinPrint 2.0.4.1 - Copyright Kindel Systems, LLC - https://tig.github.io/winprint
4343
PS >
4444
```
4545

@@ -55,6 +55,10 @@ Or, more tersely:
5555
cat program.cs | wp
5656
```
5757

58+
```powershell
59+
cat $profile.CurrentUserAllHosts | wp -Language powershell
60+
```
61+
5862
Or, using more features:
5963

6064
```powershell
@@ -387,13 +391,15 @@ The **winprint** GUI can be used to change many Sheet Definition settings. All s
387391

388392
**winprint** supports three types of files. Support for each is provided by a **winprint** Content Type Engine (CTE):
389393

390-
1. **`text/plain`** - This CTE knows only how to print raw `text/plain` files. The format of the printed text can be changed (e.g. to turn off line numbers or use a differnt font). Lines that are too long for a page are wrapped at character boundaries. `\r` (formfeed) characters can be made to cause following text to print on the next page (this is off by default). Settings for the `text/plain` can be changed by editing the `textFileSettings` section of a Sheet Definition in the `WinPrint.config.json` file.
394+
1. **`AnsiCte`** - This is the default CTE used for most file types. `AnsiCte` can format `text/plain` files as well as files with embedded `ANSI Escape Sequences`. `AnsiCte` provides **winprint**'s syntax highlighting (pretty printing) with support for over 200 programming languages. Over a dozen styles (colors, bold, italic, etc...) are supported (change the `style` entry in the `WinPrint.config.json` file). All styles supported by [Pygments](https://pygments.org/) are supported.
395+
396+
2. **`TextCte`** - This CTE knows only how to print raw `text/plain` files. The format of the printed text can be changed (e.g. to turn off line numbers or use a different font). Lines that are too long for a page are wrapped at character boundaries. `\r` (formfeed) characters can be made to cause following text to print on the next page (this is off by default). Settings for the `text/plain` can be changed by editing the `textFileSettings` section of a Sheet Definition in the `WinPrint.config.json` file. `TextCte` is not enabled by default and may be removed from future versions as `AnsiCte` does almost everything `TextCte` does (with the exeption of form-feeds).
391397

392-
2. **`text/html`** - This CTE can render html files. Any CSS specified inline in the HTML file will be honored. External CSS files must be local. For HTML without CSS, the default CSS used can be overridden by providing a file named `winprint.css` in the `%appdata%\Kindel Systems\winprint` folder. `text/html` does not support line numbers.
398+
3. **`text/html`** - This CTE can render html files. Any CSS specified inline in the HTML file will be honored. External CSS files must be local. For HTML without CSS, the default CSS used can be overridden by providing a file named `winprint.css` in the `%appdata%\Kindel Systems\winprint` folder. `text/html` does not support line numbers.
393399

394-
3. **`text/code`** - The text/code CTE supports syntax highlighting (pretty printing), with optional line numbering, of over 200 programming languages. The style of the printing can be changed by providing a file named `winprint-prism.css` in the `%appdata%\Kindel Systems\winprint` folder. The styles defined in this format should match those defined for [PrismJS](https://prismjs.com). Any PrismJS style sheet will work with **winprint**. For example, to use the Coy theme copy `prism-coy.css` into the `%appdata%\Kindel Systems\winprint` and rename it `prism-winprint.css`.
400+
When using **winprint** from the command line, the `-ContentTypeEngine` parameter can be used specify a CTE to use.
395401

396-
The extension of the file being printed (e.g. `.cs`) determines which Content Type rendering engine will be used. **winprint** has a built-in library of hundreds of file extension to content type/language mappings.
402+
The extension of the file being printed (e.g. `.cs`) determines which Content Type rendering engine will be used. **winprint** has a built-in library of hundreds of file extension to content type/language mappings. When using **winprint** from the command line, the `-Langauge` parameter can be used to override this behavior.
397403

398404
To associate a file extension with a particular Content Type Engine modify the `files.associations` section of `WinPrint.config.json` appropriately. For example to associate files with a `.htm` extension with the `text/html` Content Type Engine add a line as shown below (the `WinPrint.config.json` generated when **winprint** runs the first time already provides this example, as an example):
399405

@@ -421,8 +427,6 @@ To associate a file extension with a language supported by `text/code` modify th
421427
}
422428
```
423429

424-
To determine the name to use (e.g. `json`) see the [PrismJS](https://prismjs.com/#supported-languages) list of languages.
425-
426430
A new language can be defined by aliasing it to an existing language by modifying the `languages` section of `WinPrint.config.json`.
427431

428432
For example to enable the [Icon Programming Language](https://en.wikipedia.org/wiki/Icon_%28programming_language%29) which is a very C-like language the `files.associations` and `languages` sections would look like the following:

src/WinPrint.Console/OutWinPrint.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Management.Automation.Internal;
1313
using System.Management.Automation.Runspaces;
1414
using System.Reflection;
15+
using System.Text;
1516
using System.Text.Json;
1617
using System.Threading;
1718
using System.Threading.Tasks;
@@ -532,6 +533,7 @@ await Task.Run(() => ServiceLocator.Current.UpdateService.GetLatestVersionAsync(
532533
// See: https://stackoverflow.com/questions/60712580/invoking-cmdlet-from-a-c-based-pscmdlet-providing-input-and-capturing-output
533534
var textToPrint = SessionState.InvokeCommand.InvokeScript(@"$input | Out-String", true, PipelineResultTypes.None, _psObjects, null)[0].ToString();
534535

536+
_print.SheetViewModel.Encoding = Encoding.UTF8;
535537
await _print.SheetViewModel.LoadStringAsync(textToPrint, (string)contentTypeEngine).ConfigureAwait(true);
536538
}
537539
}
@@ -799,13 +801,13 @@ public object GetDynamicParameters() {
799801
}));
800802

801803
// -Language
802-
runtimeDict.Add("Language", new RuntimeDefinedParameter("Language", typeof(String), new Collection<Attribute>() {
803-
new ParameterAttribute() {
804-
HelpMessage = "Optional language to use for syntax highlighting.",
805-
ParameterSetName = "Print"
806-
},
807-
new ValidateSetAttribute(ModelLocator.Current.Associations.Languages.Select(l => l.Id).ToArray())
808-
}));
804+
//runtimeDict.Add("Language", new RuntimeDefinedParameter("Language", typeof(String), new Collection<Attribute>() {
805+
// new ParameterAttribute() {
806+
// HelpMessage = "Optional language to use for syntax highlighting.",
807+
// ParameterSetName = "Print"
808+
// },
809+
// new ValidateSetAttribute(ModelLocator.Current.Associations.Languages.Select(l => l.Id).ToArray())
810+
//}));
809811

810812
return runtimeDict;
811813
}

src/WinPrint.Console/WinPrint.Console.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<AssemblyName>winprint</AssemblyName>
1010
<StartupObject></StartupObject>
1111

12-
<Version>2.0.3.95</Version>
12+
<Version>2.0.4.100</Version>
1313
<Company>Kindel Systems</Company>
1414
<Product>winprint</Product>
1515
<Authors>Charlie Kindel</Authors>
@@ -60,4 +60,8 @@
6060
</EmbeddedResource>
6161
</ItemGroup>
6262

63+
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
64+
<Exec Command="copy $(SolutionDir)..\tools\pygmentize.exe $(TargetDir)" />
65+
</Target>
66+
6367
</Project>

src/WinPrint.Core/ContentTypeEngines/HtmlCte.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public override async Task<int> RenderAsync(System.Drawing.Printing.PrinterResol
8080

8181
string css;
8282
try {
83-
// TODO: Make sure wiprint.css is in the same dir as .config file once setup is impl
83+
// TODO: Make sure winprint.css is in the same dir as .config file once setup is impl
8484
using var cssStream = new StreamReader("winprint.css");
8585
css = await cssStream.ReadToEndAsync();
8686
cssStream.Close();

src/WinPrint.Core/Models/Settings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public static Settings CreateDefaultSettings() {
223223
var defaultHFFontSize = 10F;
224224
var defaultHFFontStyle = FontStyle.Bold;
225225

226-
var defaultHeaderText = "{DateRevised:D}|{FileName}|Type: {FileType}";
226+
var defaultHeaderText = "{DateRevised:D}|{FileName}|Type: {Language}";
227227
var defualtFooterText = "Printed with love by WinPrint||Page {Page} of {NumPages}";
228228

229229
var settings = new Settings {

src/WinPrint.Core/Resources/FileTypeMapping.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1689,7 +1689,8 @@
16891689
"extensions": [
16901690
".mak",
16911691
".d",
1692-
".mk"
1692+
".mk",
1693+
".am"
16931694
]
16941695
},
16951696
{

src/WinPrint.Core/Services/PygmentsConverterService.cs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Diagnostics;
44
using System.IO;
55
using System.Linq;
6+
using System.Reflection;
67
using System.Text;
78
using System.Threading.Tasks;
89
using IronPython.Hosting;
@@ -37,7 +38,7 @@ public async Task<string> ConvertAsync(string document, string style, string lan
3738

3839
string file = Path.GetTempFileName();
3940
_proc = new Process();
40-
_proc.StartInfo.FileName = @"pygmentize.exe";
41+
_proc.StartInfo.FileName = @$"{Path.GetDirectoryName(Assembly.GetAssembly(typeof(PygmentsConverterService)).Location)}\pygmentize.exe";
4142
_proc.StartInfo.Arguments = $"-P outencoding=utf-8 -f 16m -O style={(string.IsNullOrEmpty(style) ? "default" : style)} -l {language} -o {file}.an {file}";
4243
_proc.StartInfo.RedirectStandardInput = true;
4344
_proc.StartInfo.RedirectStandardOutput = true;
@@ -54,24 +55,21 @@ public async Task<string> ConvertAsync(string document, string style, string lan
5455
await File.WriteAllTextAsync(file, document, Encoding.UTF8).ConfigureAwait(true);
5556
Log.Debug("Starting {pyg} {args}", _proc.StartInfo.FileName, _proc.StartInfo.Arguments);
5657
_proc.Start();
57-
}
58-
catch (Exception e) {
59-
// TODO: Better error message (output of stderr?)
60-
Log.Information("Failed to pygmentize: {Message}", e.Message);
61-
document = $"{ _proc.StartInfo.FileName} { _proc.StartInfo.Arguments} failed:\n{e.Message}:\n";
62-
}
63-
finally {
58+
6459
Log.Debug("Waiting for pygments to exit");
6560
await Task.WhenAny(_eventHandled.Task, Task.Delay(10000)).ConfigureAwait(true);
6661

6762
if (_proc.ExitCode != 0) {
6863
var stdErr = _proc.StandardError.ReadToEnd();
69-
Log.Information("Failed to pygmentize: {Message}", stdErr);
64+
if (stdErr.StartsWith("Usage:")) {
65+
stdErr = "Invalid command line.";
66+
}
67+
document = $"Pygments encountered an error: {stdErr}";
68+
Log.Information("{document}", document);
7069
// TODO: This should really throw an exception
71-
document = $"Failed to pygmentize: {stdErr}";
70+
throw new InvalidOperationException(document);
7271
}
7372
else {
74-
7573
if (!string.IsNullOrEmpty($"{file}.an") && File.Exists($"{file}.an")) {
7674
Log.Debug("Reading {file}", $"{file}.an");
7775
document = await File.ReadAllTextAsync($"{file}.an", Encoding.UTF8).ConfigureAwait(true);
@@ -80,8 +78,22 @@ public async Task<string> ConvertAsync(string document, string style, string lan
8078
if (document[^1] == '\n')
8179
document = document.Remove(document.Length - 1, 1);
8280
}
81+
else {
82+
// TODO: This should really throw an exception
83+
var stdErr = _proc.StandardError.ReadToEnd();
84+
document = $"Pygments failed to create converter file: {stdErr}";
85+
Log.Information("{document}", document);
86+
throw new InvalidOperationException(document);
87+
}
8388
}
84-
89+
}
90+
catch (System.ComponentModel.Win32Exception e) {
91+
// TODO: Better error message (output of stderr?)
92+
document = $"Could not format document:\n{ _proc.StartInfo.FileName} { _proc.StartInfo.Arguments} failed:\n{e.Message}";
93+
Log.Error(e, "{document}", document);
94+
throw new InvalidOperationException(document);
95+
}
96+
finally {
8597
// Clean up
8698
if (!string.IsNullOrEmpty(file) && File.Exists(file)) {
8799
File.Delete(file);

0 commit comments

Comments
 (0)