Skip to content
This repository has been archived by the owner on Jan 3, 2022. It is now read-only.

Commit

Permalink
Added support for setting input device instances for applications
Browse files Browse the repository at this point in the history
  • Loading branch information
tsutomi committed May 19, 2012
1 parent 2f951a2 commit 87cf5c0
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/dshell-nunit.vs2010/Deveel.Console/StringInputDevice.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.IO;

namespace Deveel.Console {
public sealed class StringInputDevice : InputDevice {
private StringReader baseReader;

public StringInputDevice() {
}

public StringInputDevice(string s) {
baseReader = new StringReader(s);
}

public void SetInput(string s) {
if (baseReader != null) {
baseReader.Dispose();
baseReader = null;
}

baseReader = new StringReader(s);
}

public override int Read(char[] buffer, int index, int count) {
if (baseReader == null)
return 0;

return baseReader.Read(buffer, index, count);
}

protected override void Dispose(bool disposing) {
if (disposing) {
if (baseReader != null)
baseReader.Dispose();
baseReader = null;
}

base.Dispose(disposing);
}
}
}
1 change: 1 addition & 0 deletions src/dshell-nunit.vs2010/dshell-nunit.vs2010.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Deveel.Console\StringInputDevice.cs" />
<Compile Include="Deveel.Console\StringWriteEventArgs.cs" />
<Compile Include="Deveel.Console\TestOutputDevice.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
2 changes: 2 additions & 0 deletions src/dshell/Deveel.Console/IApplicationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public interface IApplicationContext : IExecutionContext {
bool IsRunning { get; }


void SetInputDevice(InputDevice device);

void SetOutDevice(OutputDevice device);

void SetErrorDevice(OutputDevice device);
Expand Down
7 changes: 7 additions & 0 deletions src/dshell/Deveel.Console/ShellApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ public void SetPrompt(string text) {
(input as ConsoleInputDevice).Prompt = prompt;
}

public void SetInputDevice(InputDevice device) {
if (device == null)
throw new ArgumentNullException("device");

input = device;
}

public void SetOutDevice(OutputDevice device) {
if (device == null)
throw new ArgumentNullException("device");
Expand Down

0 comments on commit 87cf5c0

Please sign in to comment.