Skip to content

Commit

Permalink
shuffling some stuff around, added a very in-depth doc on xterm parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
doubleyewdee committed Nov 15, 2018
1 parent 4e84e82 commit 9d59e9c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Dev notes
- VT codes doc: https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences
- xterm: http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
- Sample for ConPTY: https://github.com/Microsoft/console/tree/master/samples/ConPTY/EchoCon
- Win32 APIs: WinBase.h, ProcessEnv.h, consoleapi.h
- Calculating size of a textbox: https://stackoverflow.com/questions/9264398/how-to-calculate-wpf-textblock-width-for-its-known-font-size-and-characters
Expand Down
2 changes: 1 addition & 1 deletion src/ConsoleBuffer/Buffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

public sealed class Buffer : INotifyPropertyChanged
{
private readonly AnsiParser parser = new AnsiParser();
private readonly SequenceParser parser = new SequenceParser();
private readonly List<Line> lines = new List<Line>();
private readonly object renderLock = new object();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,15 @@ enum ParserCommand
CR,
}

sealed class AnsiParser
// Notes on the parser:
// - I elected to hand-roll this instead of generating a parser. This is primarily for performance purposes.
// - The names I've chosen to given to various "areas" of parsing are made up and not based on good research on my
// part. The areas themselves may be silly/erroneous. Please call me out on my bullshit as desired.
// - The parser is not greedy. I have seen parsers which work to varying levels of greed, we will stop on the first
// invalid character for whatever sequence we are in (and not emit that character, nor any preceding). So for
// example the sequence '\e[32[33m hello' will emit an unmodified '33m hello' string as we gave up at the invalid
// '[' character.
sealed class SequenceParser
{
enum SequenceType
{
Expand All @@ -53,12 +61,13 @@ enum SequenceType
/// </summary>
None,
}

private SequenceType sequenceType = SequenceType.None;
private bool inSequence = false;

public ParserCommand CurrentCommand { get; private set; }

public AnsiParser()
public SequenceParser()
{
}

Expand Down

0 comments on commit 9d59e9c

Please sign in to comment.