jeremyramin / terminal-plus

A terminal package for Atom, complete with themes and more.
https://atom.io/packages/terminal-plus
MIT License
480 stars 254 forks source link

Could be nice to add direct calling to the REPLs #34

Open Z-Clive opened 9 years ago

Z-Clive commented 9 years ago

First of all, it's really nice to have a terminal running down on the screen. However, it would be really convenient if I can directly open the REPLs (python, ruby, etc.), like SublimeRepl, and not have to type the instruction into the terminal itself.

jeremyramin commented 9 years ago

This can be done in one of two ways in the Terminal-Plus settings:

  1. Change Shell Override to the REPL of your choice. or
  2. Change Auto Run Command to the REPL of your choice, assuming the REPL exists in your PATH directories.
jeremyramin commented 9 years ago

Did this work for you? If so, please close the issue.

Z-Clive commented 9 years ago

@jeremyramin Sorry if I wasn't clear, I actually meant to open each with their unique hotkey or something.

For example, alt+p opens python, alt+r opens ruby, alt+c opens normal console etc..

So I'm wondering if there is a way to assign the open console/terminal commands to different key sequences, and pass args to that command so that opens the indicated repl.

jeremyramin commented 9 years ago

@zmLGBBM Ohh okay. Sorry, I did misunderstand. That feature does not currently exist and would have to be added. I could see this being implemented in several ways:

  1. Add a configuration file for custom buttons in the toolbar that run custom commands. (This would let you program the REPLs you want and let you put commands you use frequently in the top bar.)
  2. Add a configuration file for custom Atom commands such as terminal-plus:python that would run the commands you specify (python in this case). You would have to add 'alt+p' : 'terminal-plus:python' to your keymap.

I think these could be done but I would have to give them a try and see what limitations I would run into.

Z-Clive commented 9 years ago

@jeremyramin Great! I think some of the sublime repl plug-in's features are really cool, but don't know if they can be implemented in atom.

Thanks for the package btw!

jeremyramin commented 9 years ago

@zmLGBBM I'll take a look at sublime repl before I get around to adding this to get a better idea of what you are looking for.

No problem, I'm glad you like it.

Z-Clive commented 9 years ago

@jeremyramin I've tried the Shell Overwrite setting but it does not work.

To reproduce this:

  1. Go to Terminal-Plus settings and type C:\Windows\System32\cmd.exe in Shell Overwrite.
  2. Try to open terminal by click the little + button in the bottom left corner.
  3. Open Developer tools, and here's the error it reported:
Unable to start terminal process. Win32 error code: 267 Error: Unable to start terminal process. Win32 error code: 267
    at Error (native)
    at Server.<anonymous> (C:\Users\Clive\.atom\packages\terminal-plus\node_modules\pty.js\lib\pty_win.js:65:9)
    at emitOne (events.js:77:13)
    at Server.emit (events.js:169:7)
    at Pipe.onconnection (net.js:1404:8)

And it seems not avail to clear the overwrite setting, it would still produce such error. The only way to solve this is to re-install Terminal-Plus.

jeremyramin commented 9 years ago

That is not good. This could be a result of the recent update to winpty. I will have to try this out and figure out what is wrong.

jeremyramin commented 9 years ago

I too experienced this issue on my first launch and then it went away. I'm not sure how to get it back, but I hope this does not happen for everyone...

Z-Clive commented 9 years ago

@jeremyramin Well, it kinda work now. Really strange problem.

jeremyramin commented 9 years ago

@zmLGBBM Have you seen it again or only that time?

Z-Clive commented 9 years ago

@jeremyramin I think I find out what caused this bug. It's because invalid (to os, but not atom) folder were opened.

To reproduce this:

  1. Open a fresh atom, with no file or folder opened
  2. Open Settings panel
  3. Make sure the title of the window says: "atom://config - atom"
  4. Try to open Terminal-plus
  5. Boom, you got a bug ;)
jeremyramin commented 9 years ago

@zmLGBBM Oh you're right, that is probably it. I'll have to filter out this path when setting the present working directory. I believe this puts Linux and Mac users at the root of their system since it is an invalid path. For Windows, it causes that 267 error. Thank you!

Z-Clive commented 9 years ago

@jeremyramin No problem, happy to help with this amazing package!

jeremyramin commented 9 years ago

v0.10.0 should fix the 267 error code.

Zeioth commented 9 years ago

I don't know if this can be done but be able to write commands directly could be the solution. This way you would be able to create toolbar buttons or keyboard shortcuts for anything. For example:

terminal-plus:insert-text->command to run

This is my particular case. I want to compile a C# project from a toolbar button running the command mcs:

  {
    type: "button"
    iconset: "ion"
    icon: "bug"
    callback: ["terminal-plus:insert-text->mcs myproject.csproj"]
    tooltip: "Build C# project"
    show: "C#"
  }
jeremyramin commented 9 years ago

@Zeioth I will probably have something along those lines with a CSON file. I'm still deciding the best way to implement this. What I have so far:

compileProject:
  trigger: "terminal-plus:compile-project"
  command: "mcs myproject.csproj"
  button:
    icon: "sync"
    tooltip: "Build C# project"
    order: 0
  languages: ["C#"]

The button would be an optional field. This would let people define an atom-command and/or a button for their custom commands.

I see that you have a iconset field. Iconsets would mean I would have to include the major icon sets with my project. I do not have a stance on that, but that seems like I would have to package a number of iconsets. I will probably just use GitHub's Octicons since they are built into Atom.

I also see you have a show field. Would that mean the button would only show if the current textEditor language is C#? I did not think of that but it is a good idea. There could be an optional languages field. The only problem I see with this is the possible lag this would introduce with having to go through all of the defined buttons to see which ones need to be placed. Keep in mind, this would run every time the active pane item changes.

Zeioth commented 9 years ago

The code I pasted is from flex-tool-bar package. This package is a configuration tool for tool-bar and is already prepared to use some predefined iconsets, so you don't have to worry about it.

jeremyramin commented 9 years ago

Oh okay. Then in your case you would just leave the button and languages option out and define the custom atom-command. Then in the flex-tool-bar package you could just use the command you defined in Terminal-Plus (i.e. terminal-plus:compile-project).

Zeioth commented 9 years ago

Yes that is. I think this is the only way atom allows to do it. That sucks because this way you have to implement every command in Terminal-Plus. It would be cool to be able to do something like.

terminal-plus:run-command -> string

Where string is the command you want to run.

jeremyramin commented 9 years ago

Unfortunately you are right. Atom does not allow for me to specify input for the package commands. Though I already have an idea for writing this that would not be too bad as far as implementing the every command goes. I will not know if this is even possible until I get a chance to write it out.

Z-Clive commented 9 years ago

@jeremyramin @Zeioth Well, since atom would not let you to specify input for commands, why not just have a config file in the root of the project you're working on, and when you run terminal-plus: run-command it will read that config file and give you a list of things that can be done, just like how Visual Studio Code does with tasks.

I think that should be better since now you don't have to define global commands for every only project-wide commands that might lead to a very long and not related commands showed in specific project. Now when people tell terminal-plus to run tasks, it will get the config file and list possible tasks for user to choose.

Example of terminal-plus.config:

compileProject:
  trigger: "terminal-plus:run-command"
  command: "mcs ./myproject.csproj"
  description:
    icon: "task"
    name: "Build MyProject"
    order: 0
jeremyramin commented 9 years ago

@zmLGBBM So basically implement one command that displays the possible defined tasks for a project? I guess that could work but that would draw away from your request for letting you define alt+p as let's say exec python.

Either way, you make a valid point that every project has a different file to compile and therefore a different command to run. I could see there being a global config file and a project config file. I wish I could offer the idea to the rest of the user group and find out what they think. I'd like some more input on this.

Z-Clive commented 9 years ago

@jeremyramin Well, that should, but can be solve with this too. It's a great idea to have a terminal-plus.global.cson in the user config directory that holds all global tasks that a user would like to run, and a terminal-plus.project.cson in the root of each project.

Like in global.cson:

pythonRepl:             // this is how to run python repl directly
  trigger: "terminal-plus:run-command"
  command: "/path/to/python"
  shell: true              // that means this would offer a terminal plus shell
  key-map: "alt+p"   // it would be nice to have a hotkey defined, but not necessory
  description:
    icon: "python"
    name: "Run Python"
    order: 0

And now in project.cson:

compileProject:
  trigger: "terminal-plus:run-command"
  command: "mcs ./myproject.csproj"
  shell: false                   // this will only give the output of such command but not a shell
  description:
    icon: "task"
    name: "Build MyProject"
    order: 0

This two settings things works well with Sublime users, since it gives user the chance to have different settings in each of the projects. But it would be nicer to have a opinion about how atom users think of it.

PS: The best way to implement this kind of functionality is definitely not in terminal-plus. I do think one package should be focused on what is it offer. You might want to implement this terminal-plus: run-command command and start a new package, something like a Tasks Manager, to let user call that command within it (from trigger section). And that trigger section would not have to be the terminal-plus command, it can be any command that atom supports.