diff --git a/src/Microsoft.PowerShell.Linux.Host/PSL_profile.ps1 b/src/Microsoft.PowerShell.Linux.Host/PSL_profile.ps1
index 3bb4ea9a6ef..92001007ecc 100644
--- a/src/Microsoft.PowerShell.Linux.Host/PSL_profile.ps1
+++ b/src/Microsoft.PowerShell.Linux.Host/PSL_profile.ps1
@@ -1,15 +1,14 @@
-(get-psprovider 'FileSystem').Home = $env:HOME
-
-function prompt
-{
- "PSL " + $(get-location) + "> "
+function prompt {
+ "PSL " + $(get-location) + "> "
}
-& {
- for ($i = 0; $i -lt 26; $i++)
- {
- $funcname = ([System.Char]($i+65)) + ':'
- $str = "function global:$funcname { set-location $funcname } "
- invoke-expression $str
- }
-}
+@"
+
+Welcome to Project Magrathea!
+
+This is the Core PowerShell On Linux /OS X console
+==================================================
+- Type 'get-help' for help
+- Type 'exit' to exit
+
+"@
diff --git a/src/Microsoft.PowerShell.Linux.Host/host.cs b/src/Microsoft.PowerShell.Linux.Host/host.cs
index 22937835daf..d04177d4a6a 100644
--- a/src/Microsoft.PowerShell.Linux.Host/host.cs
+++ b/src/Microsoft.PowerShell.Linux.Host/host.cs
@@ -6,9 +6,9 @@ namespace Microsoft.PowerShell.Linux.Host
using System.Management.Automation.Runspaces;
///
- /// This is a sample implementation of the PSHost abstract class for
- /// console applications. Not all members are implemented. Those that
- /// are not implemented throw a NotImplementedException exception or
+ /// This is a sample implementation of the PSHost abstract class for
+ /// console applications. Not all members are implemented. Those that
+ /// are not implemented throw a NotImplementedException exception or
/// return nothing.
///
internal class MyHost : PSHost, IHostSupportsInteractiveSession
@@ -53,8 +53,8 @@ public MyHost(Listener Listener)
///
- /// Gets the culture information to use. This implementation
- /// returns a snapshot of the culture information of the thread
+ /// Gets the culture information to use. This implementation
+ /// returns a snapshot of the culture information of the thread
/// that created this object.
///
public override CultureInfo CurrentCulture
@@ -63,8 +63,8 @@ public override CultureInfo CurrentCulture
}
///
- /// Gets the UI culture information to use. This implementation
- /// returns a snapshot of the UI culture information of the thread
+ /// Gets the UI culture information to use. This implementation
+ /// returns a snapshot of the UI culture information of the thread
/// that created this object.
///
public override CultureInfo CurrentUICulture
@@ -73,7 +73,7 @@ public override CultureInfo CurrentUICulture
}
///
- /// Gets an identifier for this host. This implementation always
+ /// Gets an identifier for this host. This implementation always
/// returns the GUID allocated at instantiation time.
///
public override Guid InstanceId
@@ -82,7 +82,7 @@ public override Guid InstanceId
}
///
- /// Gets a string that contains the name of this host implementation.
+ /// Gets a string that contains the name of this host implementation.
/// Keep in mind that this string may be used by script writers to
/// identify when your host is being used.
///
@@ -102,7 +102,7 @@ public override PSHostUserInterface UI
}
///
- /// Gets the version object for this application. Typically this
+ /// Gets the version object for this application. Typically this
/// should match the version resource in the application.
///
public override Version Version
@@ -113,7 +113,7 @@ public override Version Version
#region IHostSupportsInteractiveSession Properties
///
- /// Gets a value indicating whether a request
+ /// Gets a value indicating whether a request
/// to open a PSSession has been made.
///
public bool IsRunspacePushed
@@ -132,9 +132,9 @@ public Runspace Runspace
#endregion IHostSupportsInteractiveSession Properties
///
- /// This API Instructs the host to interrupt the currently running
- /// pipeline and start a new nested input loop. In this example this
- /// functionality is not needed so the method throws a
+ /// This API Instructs the host to interrupt the currently running
+ /// pipeline and start a new nested input loop. In this example this
+ /// functionality is not needed so the method throws a
/// NotImplementedException exception.
///
public override void EnterNestedPrompt()
@@ -144,8 +144,8 @@ public override void EnterNestedPrompt()
}
///
- /// This API instructs the host to exit the currently running input loop.
- /// In this example this functionality is not needed so the method
+ /// This API instructs the host to exit the currently running input loop.
+ /// In this example this functionality is not needed so the method
/// throws a NotImplementedException exception.
///
public override void ExitNestedPrompt()
@@ -155,26 +155,26 @@ public override void ExitNestedPrompt()
}
///
- /// This API is called before an external application process is
- /// started. Typically it is used to save state so that the parent
- /// can restore state that has been modified by a child process (after
- /// the child exits). In this example this functionality is not
+ /// This API is called before an external application process is
+ /// started. Typically it is used to save state so that the parent
+ /// can restore state that has been modified by a child process (after
+ /// the child exits). In this example this functionality is not
/// needed so the method returns nothing.
///
public override void NotifyBeginApplication()
{
- return;
+ return;
}
///
/// This API is called after an external application process finishes.
/// Typically it is used to restore state that a child process has
- /// altered. In this example, this functionality is not needed so
+ /// altered. In this example, this functionality is not needed so
/// the method returns nothing.
///
public override void NotifyEndApplication()
{
- return;
+ return;
}
///
@@ -182,7 +182,7 @@ public override void NotifyEndApplication()
/// been requested. Pass the exit code that the host
/// application should use when exiting the process.
///
- /// The exit code that the
+ /// The exit code that the
/// host application should use.
public override void SetShouldExit(int exitCode)
{
diff --git a/src/Microsoft.PowerShell.Linux.Host/main.cs b/src/Microsoft.PowerShell.Linux.Host/main.cs
index 77a56ac777b..4ca6e5f56b2 100644
--- a/src/Microsoft.PowerShell.Linux.Host/main.cs
+++ b/src/Microsoft.PowerShell.Linux.Host/main.cs
@@ -79,16 +79,6 @@ public static void Main(string[] args)
// only run if there was no script file passed in
if (initialScript == null)
{
- // Display the welcome message.
- Console.WriteLine();
- Console.WriteLine("PowerShell for Linux interactive console");
- Console.WriteLine("========================================");
- Console.WriteLine();
- Console.WriteLine("Current status:");
- Console.WriteLine("- Type 'exit' to exit");
- Console.WriteLine("- Utility and Management cmdlet modules are loadable");
- Console.WriteLine();
-
listener.Run();
}
}
@@ -133,7 +123,7 @@ internal class Listener
private object instanceLock = new object();
///
- /// Gets or sets a value indicating whether the host application
+ /// Gets or sets a value indicating whether the host application
/// should exit.
///
public bool ShouldExit
@@ -143,7 +133,7 @@ public bool ShouldExit
}
///
- /// Gets or sets a value indicating whether the host application
+ /// Gets or sets a value indicating whether the host application
/// should exit.
///
public int ExitCode
@@ -154,8 +144,8 @@ public int ExitCode
public Listener(string initialScript)
{
- // Create the host and runspace instances for this interpreter.
- // Note that this application does not support console files so
+ // Create the host and runspace instances for this interpreter.
+ // Note that this application does not support console files so
// only the default snap-ins will be available.
this.myHost = new MyHost(this);
InitialSessionState iss = InitialSessionState.CreateDefault2();
@@ -176,8 +166,7 @@ public Listener(string initialScript)
PSCommand[] profileCommands = HostUtilities.GetProfileCommands("PSL");
foreach (PSCommand command in profileCommands)
{
- this.currentPowerShell.Commands = command;
- this.currentPowerShell.Invoke();
+ RunCommand(command);
}
}
finally
@@ -226,13 +215,39 @@ public string Prompt(Runspace rs)
}
///
- /// A helper class that builds and executes a pipeline that writes
- /// to the default output path. Any exceptions that are thrown are
- /// just passed to the caller. Since all output goes to the default
+ /// Runs individual commands
+ ///
+ /// command to run
+ internal void RunCommand(PSCommand command)
+ {
+ if (command == null)
+ {
+ return;
+ }
+
+ command.AddCommand("out-default");
+ command.Commands[0].MergeMyResults(PipelineResultTypes.Error, PipelineResultTypes.Output);
+
+ this.currentPowerShell.Commands = command;
+
+ try
+ {
+ this.currentPowerShell.Invoke();
+ }
+ catch (RuntimeException e)
+ {
+ this.ReportException(e);
+ }
+ }
+
+ ///
+ /// A helper class that builds and executes a pipeline that writes
+ /// to the default output path. Any exceptions that are thrown are
+ /// just passed to the caller. Since all output goes to the default
/// outter, this method does not return anything.
///
/// The script to run.
- /// Any input arguments to pass to the script.
+ /// Any input arguments to pass to the script.
/// If null then nothing is passed in.
private void executeHelper(string cmd, object input)
{
@@ -250,8 +265,8 @@ private void executeHelper(string cmd, object input)
this.currentPowerShell = PowerShell.Create();
}
- // Add a script and command to the pipeline and then run the pipeline. Place
- // the results in the currentPowerShell variable so that the pipeline can be
+ // Add a script and command to the pipeline and then run the pipeline. Place
+ // the results in the currentPowerShell variable so that the pipeline can be
// stopped.
try
{
@@ -259,8 +274,8 @@ private void executeHelper(string cmd, object input)
this.currentPowerShell.AddScript(cmd);
- // Add the default outputter to the end of the pipe and then call the
- // MergeMyResults method to merge the output and error streams from the
+ // Add the default outputter to the end of the pipe and then call the
+ // MergeMyResults method to merge the output and error streams from the
// pipeline. This will result in the output being written using the PSHost
// and PSHostUserInterface classes instead of returning objects to the host
// application.
@@ -282,8 +297,8 @@ private void executeHelper(string cmd, object input)
}
finally
{
- // Dispose the PowerShell object and set currentPowerShell to null.
- // It is locked because currentPowerShell may be accessed by the
+ // Dispose the PowerShell object and set currentPowerShell to null.
+ // It is locked because currentPowerShell may be accessed by the
// ctrl-C handler.
lock (this.instanceLock)
{
@@ -294,11 +309,11 @@ private void executeHelper(string cmd, object input)
}
///
- /// To display an exception using the display formatter,
+ /// To display an exception using the display formatter,
/// run a second pipeline passing in the error record.
/// The runtime will bind this to the $input variable,
/// which is why $input is being piped to the Out-String
- /// cmdlet. The WriteErrorLine method is called to make sure
+ /// cmdlet. The WriteErrorLine method is called to make sure
/// the error gets displayed in the correct error color.
///
/// The exception to display.
@@ -347,7 +362,7 @@ private void ReportException(Exception e)
}
finally
{
- // Dispose of the pipeline and set it to null, locking it because
+ // Dispose of the pipeline and set it to null, locking it because
// currentPowerShell may be accessed by the ctrl-C handler.
lock (this.instanceLock)
{
@@ -360,7 +375,7 @@ private void ReportException(Exception e)
///
/// Basic script execution routine. Any runtime exceptions are
- /// caught and passed back to the Windows PowerShell engine to
+ /// caught and passed back to the Windows PowerShell engine to
/// display.
///
/// Script to run.
@@ -382,9 +397,9 @@ private void Execute(string cmd)
/// pipeline Stop() method to stop execution. If any exceptions occur
/// they are printed to the console but otherwise ignored.
///
- /// See sender property documentation of
+ /// See sender property documentation of
/// ConsoleCancelEventHandler.
- /// See e property documentation of
+ /// See e property documentation of
/// ConsoleCancelEventHandler.
private void HandleControlC(object sender, ConsoleCancelEventArgs e)
{
diff --git a/src/Microsoft.PowerShell.Linux.Host/rawui.cs b/src/Microsoft.PowerShell.Linux.Host/rawui.cs
index 00ab5817b33..219f7bf7a4e 100644
--- a/src/Microsoft.PowerShell.Linux.Host/rawui.cs
+++ b/src/Microsoft.PowerShell.Linux.Host/rawui.cs
@@ -25,9 +25,9 @@ public override ConsoleColor BackgroundColor
get { return Console.BackgroundColor; }
set { Console.BackgroundColor = value; }
}
-
+
///
- /// Gets or sets the size of the host buffer. In this example the
+ /// Gets or sets the size of the host buffer. In this example the
/// buffer size is adapted from the Console buffer size members.
///
public override Size BufferSize
@@ -37,10 +37,10 @@ public override Size BufferSize
//get { return new Size(Console.BufferWidth, Console.BufferHeight); }
//set { Console.SetBufferSize(value.Width, value.Height); }
}
-
+
///
- /// Gets or sets the cursor position. In this example this
- /// functionality is not needed so the property throws a
+ /// Gets or sets the cursor position. In this example this
+ /// functionality is not needed so the property throws a
/// NotImplementException exception.
///
public override Coordinates CursorPosition
@@ -50,10 +50,10 @@ public override Coordinates CursorPosition
set { throw new NotImplementedException(
"The method or operation is not implemented."); }
}
-
+
///
- /// Gets or sets the size of the displayed cursor. In this example
- /// the cursor size is taken directly from the Console.CursorSize
+ /// Gets or sets the size of the displayed cursor. In this example
+ /// the cursor size is taken directly from the Console.CursorSize
/// property.
///
public override int CursorSize
@@ -63,7 +63,7 @@ public override int CursorSize
//get { return Console.CursorSize; }
//set { Console.CursorSize = value; }
}
-
+
///
/// Gets or sets the foreground color of the displayed text.
/// This maps to the corresponding Console.ForgroundColor property.
@@ -73,9 +73,9 @@ public override ConsoleColor ForegroundColor
get { return Console.ForegroundColor; }
set { Console.ForegroundColor = value; }
}
-
+
///
- /// Gets a value indicating whether the user has pressed a key. This maps
+ /// Gets a value indicating whether the user has pressed a key. This maps
/// to the corresponding Console.KeyAvailable property.
///
public override bool KeyAvailable
@@ -83,12 +83,12 @@ public override bool KeyAvailable
get { return false; }
// get { return Console.KeyAvailable; }
}
-
+
///
- /// Gets the dimensions of the largest window that could be
- /// rendered in the current display, if the buffer was at the least
- /// that large. This example uses the Console.LargestWindowWidth and
- /// Console.LargestWindowHeight properties to determine the returned
+ /// Gets the dimensions of the largest window that could be
+ /// rendered in the current display, if the buffer was at the least
+ /// that large. This example uses the Console.LargestWindowWidth and
+ /// Console.LargestWindowHeight properties to determine the returned
/// value of this property.
///
public override Size MaxPhysicalWindowSize
@@ -96,11 +96,11 @@ public override Size MaxPhysicalWindowSize
// get { return new Size(Console.LargestWindowWidth, Console.LargestWindowHeight); }
get { return new Size(1024,768); }
}
-
+
///
- /// Gets the dimentions of the largest window size that can be
- /// displayed. This example uses the Console.LargestWindowWidth and
- /// console.LargestWindowHeight properties to determine the returned
+ /// Gets the dimentions of the largest window size that can be
+ /// displayed. This example uses the Console.LargestWindowWidth and
+ /// console.LargestWindowHeight properties to determine the returned
/// value of this property.
///
public override Size MaxWindowSize
@@ -108,10 +108,10 @@ public override Size MaxWindowSize
// get { return new Size(Console.LargestWindowWidth, Console.LargestWindowHeight); }
get { return new Size(1024,768); }
}
-
+
///
- /// Gets or sets the position of the displayed window. This example
- /// uses the Console window position APIs to determine the returned
+ /// Gets or sets the position of the displayed window. This example
+ /// uses the Console window position APIs to determine the returned
/// value of this property.
///
public override Coordinates WindowPosition
@@ -121,10 +121,10 @@ public override Coordinates WindowPosition
get { return new Coordinates(0,0); }
set { }
}
-
+
///
- /// Gets or sets the size of the displayed window. This example
- /// uses the corresponding Console window size APIs to determine the
+ /// Gets or sets the size of the displayed window. This example
+ /// uses the corresponding Console window size APIs to determine the
/// returned value of this property.
///
public override Size WindowSize
@@ -134,9 +134,9 @@ public override Size WindowSize
get { return new Size(1024,768); }
set { }
}
-
+
///
- /// Gets or sets the title of the displayed window. The example
+ /// Gets or sets the title of the displayed window. The example
/// maps the Console.Title property to the value of this property.
///
public override string WindowTitle
@@ -146,18 +146,18 @@ public override string WindowTitle
get { return "window title"; }
set { }
}
-
+
///
- /// This API resets the input buffer. In this example this
+ /// This API resets the input buffer. In this example this
/// functionality is not needed so the method returns nothing.
///
public override void FlushInputBuffer()
{
}
-
+
///
- /// This API returns a rectangular region of the screen buffer. In
- /// this example this functionality is not needed so the method throws
+ /// This API returns a rectangular region of the screen buffer. In
+ /// this example this functionality is not needed so the method throws
/// a NotImplementException exception.
///
/// Defines the size of the rectangle.
@@ -165,58 +165,58 @@ public override void FlushInputBuffer()
public override BufferCell[,] GetBufferContents(Rectangle rectangle)
{
throw new NotImplementedException(
- "The method or operation is not implemented.");
+ "The method or operation is not implemented.");
}
-
+
///
- /// This API reads a pressed, released, or pressed and released keystroke
- /// from the keyboard device, blocking processing until a keystroke is
- /// typed that matches the specified keystroke options. In this example
+ /// This API reads a pressed, released, or pressed and released keystroke
+ /// from the keyboard device, blocking processing until a keystroke is
+ /// typed that matches the specified keystroke options. In this example
/// this functionality is not needed so the method throws a
/// NotImplementException exception.
///
- /// Options, such as IncludeKeyDown, used when
+ /// Options, such as IncludeKeyDown, used when
/// reading the keyboard.
/// Throws a NotImplementedException exception.
public override KeyInfo ReadKey(ReadKeyOptions options)
{
throw new NotImplementedException(
- "The method or operation is not implemented.");
+ "The method or operation is not implemented.");
}
-
+
///
- /// This API crops a region of the screen buffer. In this example
+ /// This API crops a region of the screen buffer. In this example
/// this functionality is not needed so the method throws a
/// NotImplementException exception.
///
/// The region of the screen to be scrolled.
- /// The region of the screen to receive the
+ /// The region of the screen to receive the
/// source region contents.
/// The region of the screen to include in the operation.
/// The character and attributes to be used to fill all cell.
public override void ScrollBufferContents(Rectangle source, Coordinates destination, Rectangle clip, BufferCell fill)
{
throw new NotImplementedException(
- "The method or operation is not implemented.");
+ "The method or operation is not implemented.");
}
-
+
///
- /// This method copies an array of buffer cells into the screen buffer
- /// at a specified location. In this example this functionality is
+ /// This method copies an array of buffer cells into the screen buffer
+ /// at a specified location. In this example this functionality is
/// not needed so the method throws a NotImplementedException exception.
///
/// The parameter is not used.
/// The parameter is not used.
- public override void SetBufferContents(Coordinates origin,
- BufferCell[,] contents)
+ public override void SetBufferContents(Coordinates origin,
+ BufferCell[,] contents)
{
throw new NotImplementedException(
- "The method or operation is not implemented.");
+ "The method or operation is not implemented.");
}
-
+
///
- /// This method copies a given character, foreground color, and background
- /// color to a region of the screen buffer. In this example this
+ /// This method copies a given character, foreground color, and background
+ /// color to a region of the screen buffer. In this example this
/// functionality is not needed so the method throws a
/// NotImplementException exception.///
/// Defines the area to be filled.
@@ -224,7 +224,7 @@ public override void SetBufferContents(Coordinates origin,
public override void SetBufferContents(Rectangle rectangle, BufferCell fill)
{
throw new NotImplementedException(
- "The method or operation is not implemented.");
+ "The method or operation is not implemented.");
}
}
}
diff --git a/src/Microsoft.PowerShell.Linux.Host/readline.cs b/src/Microsoft.PowerShell.Linux.Host/readline.cs
index b6f62f6da5e..a451e827c81 100644
--- a/src/Microsoft.PowerShell.Linux.Host/readline.cs
+++ b/src/Microsoft.PowerShell.Linux.Host/readline.cs
@@ -100,8 +100,8 @@ internal class ConsoleReadLine
public ConsoleReadLine()
{
this.tokenColors = new ConsoleColor[]
- {
- this.defaultColor, // Unknown
+ {
+ this.defaultColor, // Unknown
ConsoleColor.Yellow, // Command
ConsoleColor.Green, // CommandParameter
ConsoleColor.Cyan, // CommandArgument
@@ -121,7 +121,7 @@ public ConsoleReadLine()
this.defaultColor, // NewLine
this.defaultColor, // LineContinuation
this.defaultColor, // Position
- };
+ };
}
///
@@ -148,7 +148,7 @@ public string Read(Runspace runspace)
case ConsoleKey.Enter:
previousKeyPress = key;
return this.OnEnter();
- case ConsoleKey.RightArrow:
+ case ConsoleKey.RightArrow:
this.OnRight(key.Modifiers);
break;
case ConsoleKey.LeftArrow:
@@ -173,8 +173,8 @@ public string Read(Runspace runspace)
this.OnDownArrow();
break;
- // TODO: case ConsoleKey.LeftWindows: not available in linux
- // TODO: case ConsoleKey.RightWindows: not available in linux
+ // TODO: case ConsoleKey.LeftWindows: not available in linux
+ // TODO: case ConsoleKey.RightWindows: not available in linux
default:
@@ -193,7 +193,7 @@ public string Read(Runspace runspace)
this.Render();
break;
}
- previousKeyPress = key;
+ previousKeyPress = key;
}
}
@@ -270,7 +270,7 @@ private void OnTab()
//handle file path slashes
if (tabResult.Contains(".\\"))
{
- tabResult = tabResult.Replace(".\\", "");
+ tabResult = tabResult.Replace(".\\", "");
}
if (this.buffer.ToString().Contains(" "))
@@ -297,8 +297,8 @@ private void OnTab()
}
- BufferFromString(tabResult);
- this.Render();
+ BufferFromString(tabResult);
+ this.Render();
}
} //end of OnTab()
@@ -339,6 +339,11 @@ private void OnEscape()
///
private void OnDownArrow() {
+ if (historyResult == null)
+ {
+ return;
+ }
+
if (historyIndex == historyResult.Count)
{
OnEscape();
@@ -348,7 +353,8 @@ private void OnDownArrow() {
try
{
- BufferFromString(historyResult[historyIndex].Members["CommandLine"].Value.ToString()); this.Render();
+ BufferFromString(historyResult[historyIndex].Members["CommandLine"].Value.ToString());
+ this.Render();
}
catch
@@ -362,62 +368,67 @@ private void OnDownArrow() {
///
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
+ try{
+ if ((previousKeyPress.Key != ConsoleKey.DownArrow && previousKeyPress.Key != ConsoleKey.UpArrow) || previousKeyPress.Key == ConsoleKey.Enter)
{
- return;
- }
+ //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--;
+ }
- else
- {
- if (historyIndex > historyResult.Count) //we hit the blank prompt using the down arrow
- {
- historyIndex = historyResult.Count -1;
- }
+ catch
+ {
+ return;
+ }
- if ( historyIndex < 0 )
- {
- historyIndex = 0;
}
- try
+ else
{
- BufferFromString(historyResult[historyIndex].Members["CommandLine"].Value.ToString());
- this.Render();
+ if (historyIndex > historyResult.Count) //we hit the blank prompt using the down arrow
+ {
+ historyIndex = historyResult.Count -1;
+ }
- if ( historyIndex == 0 )
+ if ( historyIndex < 0 )
{
- return;
+ historyIndex = 0;
}
- else
+ try
{
- historyIndex--;
+ BufferFromString(historyResult[historyIndex].Members["CommandLine"].Value.ToString());
+ this.Render();
+
+ if ( historyIndex == 0 )
+ {
+ return;
+ }
+
+ else
+ {
+ historyIndex--;
+ }
}
- }
- catch
- {
- return;
+ catch
+ {
+ return;
+ }
}
}
+
+ catch { return;}
}
///
diff --git a/src/Microsoft.PowerShell.Linux.Host/ui.cs b/src/Microsoft.PowerShell.Linux.Host/ui.cs
index d8d45f194cf..ed6817e1bd4 100644
--- a/src/Microsoft.PowerShell.Linux.Host/ui.cs
+++ b/src/Microsoft.PowerShell.Linux.Host/ui.cs
@@ -9,11 +9,11 @@ namespace Microsoft.PowerShell.Linux.Host
using System.Text;
///
- /// A sample implementation of the PSHostUserInterface abstract class for
- /// console applications. Not all members are implemented. Those that are
- /// not implemented throw a NotImplementedException exception or return
- /// nothing. Members that are implemented include those that map easily to
- /// Console APIs and a basic implementation of the prompt API provided.
+ /// A sample implementation of the PSHostUserInterface abstract class for
+ /// console applications. Not all members are implemented. Those that are
+ /// not implemented throw a NotImplementedException exception or return
+ /// nothing. Members that are implemented include those that map easily to
+ /// Console APIs and a basic implementation of the prompt API provided.
///
internal class MyHostUserInterface : PSHostUserInterface, IHostUISupportsMultipleChoiceSelection
{
@@ -32,20 +32,20 @@ public override PSHostRawUserInterface RawUI
}
///
- /// Prompts the user for input.
+ /// Prompts the user for input.
/// The caption or title of the prompt.
/// The text of the prompt.
- /// A collection of FieldDescription objects
+ /// A collection of FieldDescription objects
/// that describe each field of the prompt.
- /// A dictionary object that contains the results of the user
+ /// A dictionary object that contains the results of the user
/// prompts.
public override Dictionary Prompt(
- string caption,
+ string caption,
string message,
Collection descriptions)
{
this.Write(
- ConsoleColor.White,
+ ConsoleColor.White,
ConsoleColor.Black,
caption + System.Environment.NewLine + message + " ");
Dictionary results =
@@ -68,31 +68,31 @@ public override Dictionary Prompt(
///
- /// Provides a set of choices that enable the user to choose a
- /// single option from a set of options.
+ /// Provides a set of choices that enable the user to choose a
+ /// single option from a set of options.
///
/// Text that proceeds (a title) the choices.
/// A message that describes the choice.
- /// A collection of ChoiceDescription objects that
+ /// A collection of ChoiceDescription objects that
/// describ each choice.
- /// The index of the label in the Choices
+ /// The index of the label in the Choices
/// parameter collection. To indicate no default choice, set to -1.
- /// The index of the Choices parameter collection element that
+ /// The index of the Choices parameter collection element that
/// corresponds to the option that is selected by the user.
public override int PromptForChoice(
- string caption,
+ string caption,
string message,
- Collection choices,
+ Collection choices,
int defaultChoice)
{
// Write the caption and message strings in Blue.
this.WriteLine(
- ConsoleColor.Blue,
+ ConsoleColor.Blue,
ConsoleColor.Black,
caption + System.Environment.NewLine + message + System.Environment.NewLine);
// Convert the choice collection into something that is
- // easier to work with. See the BuildHotkeysAndPlainLabels
+ // easier to work with. See the BuildHotkeysAndPlainLabels
// method for details.
string[,] promptData = BuildHotkeysAndPlainLabels(choices);
@@ -101,14 +101,14 @@ public override int PromptForChoice(
for (int element = 0; element < choices.Count; element++)
{
sb.Append(String.Format(
- CultureInfo.CurrentCulture,
+ CultureInfo.CurrentCulture,
"|{0}> {1} ",
- promptData[0, element],
+ promptData[0, element],
promptData[1, element]));
}
sb.Append(String.Format(
- CultureInfo.CurrentCulture,
+ CultureInfo.CurrentCulture,
"[Default is ({0}]",
promptData[0, defaultChoice]));
@@ -142,31 +142,31 @@ public override int PromptForChoice(
#region IHostUISupportsMultipleChoiceSelection Members
///
- /// Provides a set of choices that enable the user to choose a one or
- /// more options from a set of options.
+ /// Provides a set of choices that enable the user to choose a one or
+ /// more options from a set of options.
///
/// Text that proceeds (a title) the choices.
/// A message that describes the choice.
- /// A collection of ChoiceDescription objects that
+ /// A collection of ChoiceDescription objects that
/// describ each choice.
- /// The index of the label in the Choices
+ /// The index of the label in the Choices
/// parameter collection. To indicate no default choice, set to -1.
- /// The index of the Choices parameter collection element that
+ /// The index of the Choices parameter collection element that
/// corresponds to the option that is selected by the user.
public Collection PromptForChoice(
- string caption,
+ string caption,
string message,
- Collection choices,
+ Collection choices,
IEnumerable defaultChoices)
{
// Write the caption and message strings in Blue.
this.WriteLine(
- ConsoleColor.Blue,
+ ConsoleColor.Blue,
ConsoleColor.Black,
caption + System.Environment.NewLine + message + System.Environment.NewLine);
// Convert the choice collection into something that is
- // easier to work with. See the BuildHotkeysAndPlainLabels
+ // easier to work with. See the BuildHotkeysAndPlainLabels
// method for details.
string[,] promptData = BuildHotkeysAndPlainLabels(choices);
@@ -175,9 +175,9 @@ public Collection PromptForChoice(
for (int element = 0; element < choices.Count; element++)
{
sb.Append(String.Format(
- CultureInfo.CurrentCulture,
+ CultureInfo.CurrentCulture,
"|{0}> {1} ",
- promptData[0, element],
+ promptData[0, element],
promptData[1, element]));
}
@@ -197,7 +197,7 @@ public Collection PromptForChoice(
foreach (int defaultChoice in defaultChoices)
{
sb.AppendFormat(
- CultureInfo.CurrentCulture,
+ CultureInfo.CurrentCulture,
"\"{0}\",",
promptData[0, defaultChoice]);
}
@@ -208,8 +208,8 @@ public Collection PromptForChoice(
}
this.WriteLine(
- ConsoleColor.Cyan,
- ConsoleColor.Black,
+ ConsoleColor.Cyan,
+ ConsoleColor.Black,
sb.ToString());
// Read prompts until a match is made, the default is
// chosen, or the loop is interrupted with ctrl-C.
@@ -246,22 +246,22 @@ public Collection PromptForChoice(
#endregion
///
- /// Prompts the user for credentials with a specified prompt window
- /// caption, prompt message, user name, and target name. In this
- /// example this functionality is not needed so the method throws a
+ /// Prompts the user for credentials with a specified prompt window
+ /// caption, prompt message, user name, and target name. In this
+ /// example this functionality is not needed so the method throws a
/// NotImplementException exception.
///
/// The caption for the message window.
/// The text of the message.
- /// The user name whose credential is to be
+ /// The user name whose credential is to be
/// prompted for.
- /// The name of the target for which the
+ /// The name of the target for which the
/// credential is collected.
/// Throws a NotImplementedException exception.
public override PSCredential PromptForCredential(
- string caption,
- string message,
- string userName,
+ string caption,
+ string message,
+ string userName,
string targetName)
{
throw new NotImplementedException(
@@ -269,29 +269,29 @@ public override PSCredential PromptForCredential(
}
///
- /// Prompts the user for credentials by using a specified prompt window
- /// caption, prompt message, user name and target name, credential
- /// types allowed to be returned, and UI behavior options. In this
- /// example this functionality is not needed so the method throws a
+ /// Prompts the user for credentials by using a specified prompt window
+ /// caption, prompt message, user name and target name, credential
+ /// types allowed to be returned, and UI behavior options. In this
+ /// example this functionality is not needed so the method throws a
/// NotImplementException exception.
///
/// The caption for the message window.
/// The text of the message.
- /// The user name whose credential is to be
+ /// The user name whose credential is to be
/// prompted for.
- /// The name of the target for which the
+ /// The name of the target for which the
/// credential is collected.
- /// A PSCredentialTypes constant
+ /// A PSCredentialTypes constant
/// that identifies the type of credentials that can be returned.
- /// A PSCredentialUIOptions constant that
+ /// A PSCredentialUIOptions constant that
/// identifies the UI behavior when it gathers the credentials.
/// Throws a NotImplementedException exception.
public override PSCredential PromptForCredential(
- string caption,
- string message,
- string userName,
- string targetName,
- PSCredentialTypes allowedCredentialTypes,
+ string caption,
+ string message,
+ string userName,
+ string targetName,
+ PSCredentialTypes allowedCredentialTypes,
PSCredentialUIOptions options)
{
throw new NotImplementedException(
@@ -299,7 +299,7 @@ public override PSCredential PromptForCredential(
}
///
- /// Reads characters that are entered by the user until a newline
+ /// Reads characters that are entered by the user until a newline
/// (carriage return) is encountered.
///
/// The characters that are entered by the user.
@@ -309,9 +309,9 @@ public override string ReadLine()
}
///
- /// Reads characters entered by the user until a newline (carriage return)
- /// is encountered and returns the characters as a secure string. In this
- /// example this functionality is not needed so the method throws a
+ /// Reads characters entered by the user until a newline (carriage return)
+ /// is encountered and returns the characters as a secure string. In this
+ /// example this functionality is not needed so the method throws a
/// NotImplementException exception.
///
/// Throws a NotImplemented exception.
@@ -326,19 +326,19 @@ public override System.Security.SecureString ReadLineAsSecureString()
/// The characters to be written.
public override void Write(string value)
{
- Console.Write(value);
+ Console.Write(value);
}
///
- /// Writes characters to the output display of the host with possible
- /// foreground and background colors.
+ /// Writes characters to the output display of the host with possible
+ /// foreground and background colors.
///
/// The color of the characters.
/// The backgound color to use.
/// The characters to be written.
public override void Write(
ConsoleColor foregroundColor,
- ConsoleColor backgroundColor,
+ ConsoleColor backgroundColor,
string value)
{
Console.ForegroundColor = foregroundColor;
@@ -350,15 +350,15 @@ public override void Write(
///
- /// Writes a line of characters to the output display of the host
- /// with foreground and background colors and appends a newline (carriage return).
+ /// Writes a line of characters to the output display of the host
+ /// with foreground and background colors and appends a newline (carriage return).
///
/// The forground color of the display.
/// The background color of the display.
/// The line to be written.
public override void WriteLine(
ConsoleColor foregroundColor,
- ConsoleColor backgroundColor,
+ ConsoleColor backgroundColor,
string value)
{
Console.ForegroundColor = foregroundColor;
@@ -374,7 +374,7 @@ public override void WriteLine(
public override void WriteDebugLine(string message)
{
this.WriteLine(
- ConsoleColor.Yellow,
+ ConsoleColor.Yellow,
ConsoleColor.Black,
String.Format(CultureInfo.CurrentCulture, "DEBUG: {0}", message));
}
@@ -387,14 +387,14 @@ public override void WriteDebugLine(string message)
public override void WriteErrorLine(string value)
{
this.WriteLine(
- ConsoleColor.Red,
- ConsoleColor.Black,
+ ConsoleColor.Red,
+ ConsoleColor.Black,
value);
}
///
- /// Writes a newline character (carriage return)
- /// to the output display of the host.
+ /// Writes a newline character (carriage return)
+ /// to the output display of the host.
///
public override void WriteLine()
{
@@ -402,8 +402,8 @@ public override void WriteLine()
}
///
- /// Writes a line of characters to the output display of the host
- /// and appends a newline character(carriage return).
+ /// Writes a line of characters to the output display of the host
+ /// and appends a newline character(carriage return).
///
/// The line to be written.
public override void WriteLine(string value)
@@ -416,27 +416,27 @@ public override void WriteLine(string value)
///
/// Unique identifier of the source of the record.
/// A ProgressReport object.
- public override void WriteProgress(long sourceId, ProgressRecord record)
- {
-
- if (record == null)
+ public override void WriteProgress(long sourceId, ProgressRecord record)
+ {
+
+ if (record == null)
{
throw PSTraceSource.NewArgumentNullException("record");
}
- string percentComplete = " [";
+ string percentComplete = " [";
- for (int i =0; i < record.PercentComplete; i++){
- percentComplete = percentComplete + "0";
- }
+ for (int i =0; i < record.PercentComplete; i++){
+ percentComplete = percentComplete + "0";
+ }
- percentComplete = percentComplete + "]";
- Console.Write ("\r{0} {1} {2} ", record.Activity, record.StatusDescription, percentComplete, "\r");
+ percentComplete = percentComplete + "]";
+ Console.Write ("\r{0} {1} {2} ", record.Activity, record.StatusDescription, percentComplete, "\r");
- if (record.PercentComplete == 100){
- Console.WriteLine(); //create a new line for the prompt
- }
- }
+ if (record.PercentComplete == 100){
+ Console.WriteLine(); //create a new line for the prompt
+ }
+ }
///
/// Writes a verbose message to the output display of the host.
@@ -445,7 +445,7 @@ public override void WriteProgress(long sourceId, ProgressRecord record)
public override void WriteVerboseLine(string message)
{
this.WriteLine(
- ConsoleColor.Green,
+ ConsoleColor.Green,
ConsoleColor.Black,
String.Format(CultureInfo.CurrentCulture, "VERBOSE: {0}", message));
}
@@ -457,7 +457,7 @@ public override void WriteVerboseLine(string message)
public override void WriteWarningLine(string message)
{
this.WriteLine(
- ConsoleColor.Yellow,
+ ConsoleColor.Yellow,
ConsoleColor.Black,
String.Format(CultureInfo.CurrentCulture, "WARNING: {0}", message));
}