Pash-Project / Pash

An Open Source reimplementation of Windows PowerShell, for Mono.
https://groups.google.com/group/pash-project
BSD 3-Clause "New" or "Revised" License
516 stars 54 forks source link

How to clear screen with pash? #382

Closed ArsenShnurkov closed 9 years ago

ArsenShnurkov commented 9 years ago
PASH /> cls
Command 'Clear-Host' not found.
  +CategoryInfo: ObjectNotFound, Reason: ParentContainsErrorRecordException
  +FullyQualifiedErrorId: CommandNotFoundException
PASH />  

what i need to configure to make this work?

sburnicki commented 9 years ago

This feature is currently missing, although it shouldn't be hard to implement it...

ArsenShnurkov commented 9 years ago

I will tell you about one similar bug - https://bugs.gentoo.org/show_bug.cgi?id=375717 It was easy to implement too, but it was open for 4 years.

Users come, try some tutorials (like get-help command) and go away...

sburnicki commented 9 years ago

Sorry to disappoint you. As README states, the project is still in alpha state and is currently more useful to get easy Powershell things running on other platforms than starting to learn Powershell/Pash. Implementing an open source version of Powershell is a big project, and we are currently not many active contributors. Hopefully the day will come when Pash's usability reaches a Powershell-like level, but there is still lots of work to do, and we're just finished with implementing the basic concepts.

sburnicki commented 9 years ago

Oh and regarding the other "bug" you mentioned: I think nobody cared, because Pash was not very useful back then.

ArsenShnurkov commented 9 years ago

Nothing changed from that time in public perception. I know that you are lead developer of the project and this may hurt you, but my intent is different. I want to say that a few steps for simplifying adoption can significantly increase the community size.

sburnicki commented 9 years ago

I'm aware of this, and this is okay for me. I never claimed Pash would have reached a state where it's publicly usable and a useful replacement for another shell. It's not "finished", yet. Also, I needed to take care of the fundamentals first. Because otherwise, things that now are easy to implement (and that I will hopefully have time for in the next months) would have been impossible to realize properly at all. And it's just some weeks since I finished the last thing I recognize as one of the fundamental concepts (providers).

Why would I start with implementing a Get-Help command when neither command discovery, nor output, nor cmdlet execution, nor other things would work properly?

Beside this, Pash is already useful for developing cross-platform scripts and tools (like specific cmdlets), which might not be something important for most users, but for me. And as I'm lead developer, I will first get things to work that I need ;-)

ArsenShnurkov commented 9 years ago

Why would I start with implementing a Get-Help command

You don't. You should spread your understanding with programming tutorials to allow others to implement these cmdlets.

Look at mrward and his nuget plugin for monodevelop. For each my question he have a readymade blog record with answer. I love this approach very much :)

ArsenShnurkov commented 9 years ago

I copied some samples, but don't know will this be enough or not, and how to deploy all that

using System.ComponentModel;
using System.Collections.ObjectModel;
using System.Management.Automation;
using System.Management.Automation.Runspaces;

// Declare the class as a cmdlet and specify and 
// appropriate verb and noun for the cmdlet name.
[Cmdlet("Clear", "Host")]
public class ClearHostCommand : Cmdlet
{
    // write out an ESC-sequence
    protected override void EndProcessing()
    {
        var s = string.Format("{0}[2J", Char.ConvertFromUtf32(27));
        WriteObject(s);
    }
}

[RunInstaller(true)]
public class BasicConsoleCommands : CustomPSSnapIn
{
    private Collection<CmdletConfigurationEntry> cmdlets = new Collection<CmdletConfigurationEntry>();
    private Collection<ProviderConfigurationEntry> providers = new Collection<ProviderConfigurationEntry>();
    private Collection<TypeConfigurationEntry> types = new Collection<TypeConfigurationEntry>();
    private Collection<FormatConfigurationEntry> formats = new Collection<FormatConfigurationEntry>();
    public override Collection<CmdletConfigurationEntry> Cmdlets { get { return cmdlets; } }
    public override Collection<ProviderConfigurationEntry> Providers { get { return providers; } }
    public override Collection<TypeConfigurationEntry> Types { get { return types; } }
    public override Collection<FormatConfigurationEntry> Formats { get { return formats; } }
    public BasicConsoleCommands() : base()
    {
        cmdlets.Add(new CmdletConfigurationEntry(“Clear-Host”, typeof(ClearHostCommand), null));
    }
    public override string Name { get { return “BasicConsoleCommands”; } }
    public override string Description
    {
         get { return “Some commands to start work with”; }
    }
    public override string Vendor { get { return “Pash”; } }
}
sburnicki commented 9 years ago

It's good that you like the blog approach. Find my blog post regarding modules here: http://blog.empalis-systems.com/module-support-pash/

It's not a concrete tutorial, since modules are designed to be Powershell compatible. So the article explains what is already compatible, and what's not working, yet. It also links examples to binary modules, script modules, and other related information.

To get concrete with the code you posted: You don't need the second class, code with the concrete cmdlet classes, as ClearHostCommand in your example. Then you need to compile the class as a DLL library which can then be imported using the Import-Module command.

sburnicki commented 9 years ago

Oh, by the way: I'm afraid the implementation as you posted it won't show the desired affect, as the cursor position doesn't get reset. Maybe using the console subsystem's clear function is the better approach here.

Because this function is so easy, we should also implement it just as a default function: function Clear-Host { [console]::Clear() }

ArsenShnurkov commented 9 years ago

I read an MSDN article about binary modules, and understood your last paragpaph from comment https://github.com/Pash-Project/Pash/issues/382#issuecomment-113953212. What I don't understood: it was written in the blog that there is no autoloading of modules.

I need following use case: 1) user installs pash package (# emerge pash) 2) user launches pash ($ pash) 3) user is able to execute cls command

I think that I can achieve it right now with Snap-Ins and it can not be achieved with modules, right? And for snapin I need that second class.

sburnicki commented 9 years ago

Snap-Ins are more like the outdated module system from Powershell < 2.0. There is no support for auto-loading snapins. And in fact, it doesn't make much sense to create snapins now, as they have no advantages compared to modules.

Since Clear-Host (cls is an alias for this command) is a standard command, this will get integrated directly into Pash. Since this isn't much work, I will push a commit for this tomorrow. Then your use case will work as described.

Autoloading modules is needed in order to use the 3 steps you described with custom commands. Now, without autloading, you would need to load the module explicitly first.

ArsenShnurkov commented 9 years ago

you would need to load the module explicitly first.

ok, i will think about packaging with expicit loading (using gentoo patches for source code)

but i want autoloading too - https://github.com/Pash-Project/Pash/issues/387 :)

sburnicki commented 9 years ago

For personal use, you can integrate an Import-Module command in your pash profile. Check the $Profile variable for the path to your personal profile file.

As mentioned, default cmdlets will be integrated in Pash directly anyway ;-) And yes, auto-laoding is on the TODO list. There is unfortunately more stuff on this list then I have time for.