Skip to content

Commit

Permalink
WIP commit to prepare for moving, probably fixed some stuff!
Browse files Browse the repository at this point in the history
  • Loading branch information
doubleyewdee committed Nov 13, 2018
1 parent ab4d472 commit d40a438
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 137 deletions.
2 changes: 1 addition & 1 deletion ConsoleBuffer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ VisualStudioVersion = 15.0.28010.2036
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleBuffer", "src\ConsoleBuffer\ConsoleBuffer.csproj", "{A16D11B0-4785-434F-8514-ABCC16DDFBFD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "condo", "src\condo\condo.csproj", "{D890EB09-11B9-41A8-B9A7-C1D159312A32}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "condo.wpf", "src\condo.wpf\condo.wpf.csproj", "{D890EB09-11B9-41A8-B9A7-C1D159312A32}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
21 changes: 17 additions & 4 deletions src/ConsoleBuffer/Buffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public sealed class Buffer : INotifyPropertyChanged

private short cursorX;
private short cursorY;
private int currentChar;
public (short X, short Y) CursorPosition => (this.cursorX, this.cursorY);

private short bufferTopVisibleLine
Expand Down Expand Up @@ -46,8 +47,9 @@ public void Append(byte[] bytes, int length)
{
for (var i = 0;i < length; ++i)
{
var ch = (char)bytes[i];
if (ch == '\n')
if (!this.AppendChar(bytes[i])) continue;

if (this.currentChar == '\n')
{
Logger.Verbose($"newline (current: {this.lines[this.currentLine]})");
if (this.currentLine == this.lines.Count - 1)
Expand All @@ -57,18 +59,29 @@ public void Append(byte[] bytes, int length)

this.cursorY = (short)Math.Min(this.Height - 1, this.cursorY + 1);
}
else if (ch == '\r')
else if (this.currentChar == '\r')
{
Logger.Verbose($"carriage return");
this.cursorX = 0;
}

this.lines[this.currentLine].Set(this.cursorX, new Character { Glyph = ch });
this.lines[this.currentLine].Set(this.cursorX, new Character { Glyph = this.currentChar });
this.cursorX = (short)Math.Min(this.Width - 1, this.cursorX + 1);
}
}
}

/// <summary>
/// Append a single byte to the current character.
/// </summary>
/// <returns>true if the current character represents a completed Unicode character</returns>
private bool AppendChar(byte b)
{
// TODO: actual utf-8 parsing.
this.currentChar = b;
return true;
}

/// <summary>
/// Render character-by-character onto the specified target.
/// </summary>
Expand Down
14 changes: 6 additions & 8 deletions src/ConsoleBuffer/Character.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleBuffer
namespace ConsoleBuffer
{
// XXX: Gonna end up with a lot of these and they're really freakin' big.
// could consider a morphable type with different sizes to avoid the (currently) 12 bytes-per-character issue.
// on a 'normal' 80x25 terminal the current buffer alone is just >23kB. A 160 character wide buffer with a 32k
// line scrollback is nearly 60MB. Per buffer. Not an issue now but something we should care about and fix in
// the future.
public struct Character
{
public struct ColorInfo
Expand All @@ -19,6 +17,6 @@ public struct ColorInfo

public ColorInfo Foreground { get; set; }
public ColorInfo Background { get; set; }
public char Glyph { get; set; } // XXX: char won't cut it for emoji/etc, gonna have to re-do this later!
public int Glyph { get; set; } // XXX: a single int isn't quite sufficient to represent emoji with ZWJ. fix later.
}
}
11 changes: 0 additions & 11 deletions src/condo/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;

Expand All @@ -19,11 +13,6 @@ public App()
{
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;

// XXX: this is some garbage. tasks are a pain.
#if DEBUG
new Timer((_) => GC.Collect(2, GCCollectionMode.Forced, true, true), null, TimeSpan.Zero, TimeSpan.FromMilliseconds(50));
#endif
}

private void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
Expand Down
7 changes: 2 additions & 5 deletions src/condo/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
namespace condo
{
using System;
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;

Expand All @@ -26,6 +22,7 @@ public MainWindow()
this.Loaded += this.OnLoaded;

this.console = TerminalManager.Instance.GetOrCreate(0, "ping -t localhost");
System.Diagnostics.Debugger.Launch();
this.console.PropertyChanged += this.UpdateContents;
}

Expand Down Expand Up @@ -67,7 +64,7 @@ private void Redraw()
{
for (var y = 0; y < this.console.Width; ++y)
{
sb.Append(this.characters[x, y].Glyph);
sb.Append((char)this.characters[x, y].Glyph);
}
sb.Append('\n');
}
Expand Down
2 changes: 0 additions & 2 deletions src/condo/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;

Expand Down
1 change: 0 additions & 1 deletion src/condo/TerminalManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
{
using ConsoleBuffer;
using System.Collections.Generic;
using System.Threading.Tasks;

/// <summary>
/// Manages creating/destroying terminals through queued requests.
Expand Down
105 changes: 0 additions & 105 deletions src/condo/condo.csproj

This file was deleted.

0 comments on commit d40a438

Please sign in to comment.