Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Up Down Arrow #7

Merged
merged 5 commits into from
Jan 16, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Additional logic for up-down arrows indexing
Also fixes tab completion for paths.
  • Loading branch information
v-alexjo authored and andyleejordan committed Jan 16, 2016
commit 8b12a689810902952def75a476768329e679796c
123 changes: 67 additions & 56 deletions src/Microsoft.PowerShell.Linux.Host/readline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,16 +339,22 @@ private void OnEscape()
/// </summary>
private void OnDownArrow() {

if (historyResult == null)
{
return;
}

if (historyIndex == historyResult.Count)
{
OnEscape();
}
}

historyIndex++;

try
{
BufferFromString(historyResult[historyIndex].Members["CommandLine"].Value.ToString()); this.Render();
BufferFromString(historyResult[historyIndex].Members["CommandLine"].Value.ToString());
this.Render();
}

catch
Expand All @@ -362,62 +368,67 @@ private void OnDownArrow() {
/// </summary>
private void OnUpArrow()
{
if ((previousKeyPress.Key != ConsoleKey.DownArrow && previousKeyPress.Key != ConsoleKey.UpArrow) || previousKeyPress.Key == ConsoleKey.Enter)
{
//first time getting the history
using (Pipeline pipeline = this.runspace.CreatePipeline("Get-History"))
{
historyResult = pipeline.Invoke();
}

try
{
historyIndex = historyResult.Count -1;
BufferFromString(historyResult[historyIndex].Members["CommandLine"].Value.ToString());
this.Render();
historyIndex--;
}

catch
{
return;
}

}

else
{
if (historyIndex > historyResult.Count) //we hit the blank prompt using the down arrow
{
historyIndex = historyResult.Count -1;
}

if ( historyIndex < 0 )
{
try{
if ((previousKeyPress.Key != ConsoleKey.DownArrow && previousKeyPress.Key != ConsoleKey.UpArrow) || previousKeyPress.Key == ConsoleKey.Enter)
{
//first time getting the history
using (Pipeline pipeline = this.runspace.CreatePipeline("Get-History"))
{
historyResult = pipeline.Invoke();
}

try
{
historyIndex = historyResult.Count -1;
BufferFromString(historyResult[historyIndex].Members["CommandLine"].Value.ToString());
this.Render();
historyIndex--;
}

catch
{
return;
}

}

else
{
if (historyIndex > historyResult.Count) //we hit the blank prompt using the down arrow
{
historyIndex = historyResult.Count -1;
}

if ( historyIndex < 0 )
{
historyIndex = 0;
}

try
{
BufferFromString(historyResult[historyIndex].Members["CommandLine"].Value.ToString());
this.Render();

if ( historyIndex == 0 )
{
return;
}

else
{
historyIndex--;
}
}

catch
{
return;
}
}
}

try
{
BufferFromString(historyResult[historyIndex].Members["CommandLine"].Value.ToString());
this.Render();

if ( historyIndex == 0 )
{
return;
}

else
{
historyIndex--;
}
}

catch
{
return;
}
}
}

catch { return;}
}

/// <summary>
Expand Down