Permalink
Browse files

commit saves my changes

  • Loading branch information...
1 parent 329c377 commit 62b2fa6414d3f216baf7cc28ea45b93deb773227 Stephan committed Jun 12, 2012
@@ -11,5 +11,7 @@ public interface IConsole
ConsoleKeyInfo Readkey();
ConsoleColor ForegroundColor { get; set; }
void ResetColor();
+ int GetCursorPositionTop();
+ int GetCursorPositionLeft();
}
}
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.Linq;
using System.Text;
@@ -81,13 +82,59 @@ public string GetNextCommand()
return cmd;
}
+ public Dictionary<int, char> GetCommandAfterHistory()
+ {
+ bool comandEnd = false;
+ var buffer = string.Empty;
+ var dict = new Dictionary<int, char>();
+ while (!comandEnd)
+ {
+ var keyInfo = _console.Readkey();
+ if (keyInfo.Key == ConsoleKey.Enter || keyInfo.KeyChar == '$')
+ {
+ ////buffer = _console.Read(); An dieser Stelle sollten
+ //buffer = Buffer.BufferText;
+ comandEnd = true;
+ }
+ else if (Matches.ContainsKey(keyInfo.Key))
+ {
+ Action action = Matches[keyInfo.Key];
+ action.Invoke();
+ dict = GetCommandAfterHistory();
+ }
+ else if (keyInfo.Key != ConsoleKey.LeftArrow && keyInfo.Key != ConsoleKey.RightArrow)
+ {
+ dict.Add(_console.GetCursorPositionLeft(),keyInfo.KeyChar);
+ }
+ }
+ return dict;
+ }
+
+ public string MergeBufferEdit(TextBuffer buffer,Dictionary<int, char> dict )
+ {
+ var ca = buffer.BufferText.ToCharArray();
+ foreach (var v in dict)
+ {
+ if(v.Key > ca.Length-1)
+ {
+ var diff = v.Key - ca.Length - 1;
+ }else
+ {
+ ca[v.Key] = v.Value;
+ }
+ }
+
+ return ca.ToString();
+ }
+
public string GetCommand()
{
bool comandEnd = false;
+
int currentIndexOfLine = 0;
var buffer = string.Empty;
- Buffer = new TextBuffer() {BufferText = string.Empty, FromHistory = false};
+ Buffer = new TextBuffer {BufferText = string.Empty, FromHistory = false};
while (!comandEnd)
{
var keyInfo = _console.Readkey();
@@ -100,8 +147,11 @@ public string GetCommand()
{
Action action = Matches[keyInfo.Key];
action.Invoke();
+
+ //Buffer.BufferText = GetCommandAfterHistory();
+ //Buffer.BufferText = MergeBufferEdit(Buffer, GetCommandAfterHistory());
}
- else
+ else if (keyInfo.Key != ConsoleKey.LeftArrow && keyInfo.Key != ConsoleKey.RightArrow)
{
Buffer.BufferText += keyInfo.KeyChar;
Buffer.FromHistory = false;
@@ -111,7 +161,7 @@ public string GetCommand()
if (!Buffer.FromHistory && buffer != string.Empty)
SaveCommand(buffer);
- // down reversen und append to up
+ // _down reversen and append to _up
_down.Reverse();
_up.AddRange(_down);
_down.Clear();
@@ -16,12 +16,12 @@ public void Write(char[] line)
{
Clear();
Console.Write(line);
+ Console.SetCursorPosition(line.Length, Console.CursorTop);
}
public void Clear()
{
int curTop = Console.CursorTop;
- int curLeft = Console.CursorLeft;
int height = 1;
int x = 0;
int y = Console.CursorTop;
@@ -61,5 +61,14 @@ public void ResetColor()
Console.ResetColor();
}
+ public int GetCursorPositionTop()
+ {
+ throw new NotImplementedException();
+ }
+
+ public int GetCursorPositionLeft()
+ {
+ throw new NotImplementedException();
+ }
}
}
@@ -36,6 +36,7 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
+ <Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
@@ -61,5 +61,15 @@ public ConsoleKeyInfo Readkey()
public void ResetColor()
{
}
+
+ public int GetCursorPositionTop()
+ {
+ throw new NotImplementedException();
+ }
+
+ public int GetCursorPositionLeft()
+ {
+ throw new NotImplementedException();
+ }
}
}
@@ -0,0 +1,49 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using ShellMe.CommandLine.CommandHandling;
+
+namespace TestCommands
+{
+ class TestCommands1 : BaseCommand
+ {
+ public override string Name
+ {
+ get { return "Test1"; }
+ }
+
+ public bool Log { get; set; }
+
+ public override void Run()
+ {
+ Console.WriteLine(string.Format("Run Test1 arg = {0}",Log));
+ }
+ }
+
+ class TestCommands2 : BaseCommand
+ {
+ public override string Name
+ {
+ get { return "Test2"; }
+ }
+
+ public override void Run()
+ {
+ Console.WriteLine("Run Test2");
+ }
+ }
+
+ class TestCommands3 : BaseCommand
+ {
+ public override string Name
+ {
+ get { return "Test3"; }
+ }
+
+ public override void Run()
+ {
+ Console.WriteLine("Run Test3");
+ }
+ }
+}
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{A895361A-AEBD-4344-89EB-427F566153AF}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>TestCommands</RootNamespace>
+ <AssemblyName>TestCommands</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <TargetFrameworkProfile>Client</TargetFrameworkProfile>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+ <PlatformTarget>x86</PlatformTarget>
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+ <PlatformTarget>x86</PlatformTarget>
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup>
+ <StartupObject />
+ </PropertyGroup>
+ <ItemGroup>
+ <Compile Include="TestCommands.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\ShellMe.CommandLine\ShellMe.CommandLine.csproj">
+ <Project>{4F0508C3-BC48-442F-8E5A-F932DF34C87B}</Project>
+ <Name>ShellMe.CommandLine</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <PropertyGroup>
+ <PostBuildEvent>copy $(TargetPath) $(SolutionDir)ShellMe.Console\$(OutDir)</PostBuildEvent>
+ </PropertyGroup>
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>

0 comments on commit 62b2fa6

Please sign in to comment.