contour-terminal / contour

Modern C++ Terminal Emulator
http://contour-terminal.org/
Apache License 2.0
2.46k stars 107 forks source link

Spawn New terminal in current working directory, and enhancements for compound Actions #758

Open SuperfastTimeTraveler opened 2 years ago

SuperfastTimeTraveler commented 2 years ago

Abstract

Ctrl-Shift-N, i.e., the NewTerminal Action doesn't open a new terminal in the present working directory. In general, there is no way so that a user can define their own Actions. I am thinking something like xterm's translations in .Xresources, for new key bindings.

Motivation

Specification

Example of translations for UXTerm in .Xresources is as follows:

UXTerm.vt100.translations: #override \n\
  Ctrl <Key> minus:        smaller-vt-font() \n\
  Ctrl <Key> plus:         larger-vt-font() \n\
  Ctrl <Key> 0:            set-vt-font(d) \n\
  Shift <KeyPress> Insert: insert-selection(CLIPBOARD) \n\
  Ctrl Shift <Key>V:       insert-selection(CLIPBOARD) \n\
  Ctrl Shift <Key>C:       copy-selection(CLIPBOARD) \n\
  Ctrl Shift <Key>N:       spawn-new-terminal(-class UXTerm -title uxterm -u8 -ti vt340) \n\
  Ctrl Alt <Key>S:         secure() \n\
  Shift <Btn1Up>:          exec-formatted("xdg-open '%t'", PRIMARY) select-start() select-end()

Is something like this possible for Contour as well, using Actions?

christianparpart commented 2 years ago

Hey, many thanks for your interest in Contour. So if NewTerminal doesn't spawn in $PWD right now (talking right out of my head here, IIRC it's simply reading that info from the config, right), then this can be trivially implemented. :+1: Thanks for that idea.

For the second part, I might need to give it some thought and reread, because I think I might not fully understand that just yet.

"Compound Actions" to me reads like being able to run multiple actions on a single shortcut, say Ctrl+N. That is already possible and even part of the example config that's being auto-generated IIRC. Simply have two input mapping lines using the same key binds but different actions. They're all invoked sequentially in order.

If that's not what you meant, I am sorry for that (I'm not native English speaker :) ), I'll try to reread later with some more time :)

uspasojevic96 commented 2 years ago

@christianparpart iirc I worked on CWD spawn of new terminal, how did it get broken again?

SuperfastTimeTraveler commented 2 years ago

@christianparpart Sorry, I had been vague in the second part, as I am not a native English speaker either 😅. What I meant by that is whether it is possible to develop something like xterm's string(string) method, so that we can key-bind it for doing multiple commands, on say, spawning a new terminal.

Some real life example maybe:

In other words, something like this would lead to a crazy amount of customizability, IMO.

Also, @uspasojevic96, can you direct me to the file/the method in which this functionality was implemented, so that I might also look at it too?

uspasojevic96 commented 2 years ago

This is the PR in question https://github.com/contour-terminal/contour/pull/498

SuperfastTimeTraveler commented 2 years ago

Thanks @uspasojevic96. Also, totally unrelated, is it possible to do something like contour +NewTerminal +RunCommand(...) (like, say, nvim --startuptime startup.log +qa), from the command line itself?

Also, I was thinking of building a completion script for contour zsh completion. Someone can then generate completion scripts for each shell, maybe, say, using contour completion zsh >| _contour in .zfunc. Let me know if I should make one.

Utkarsh-khambra commented 2 years ago

You can do something like contour nvim --startuptime startup.log +qa. But if your command runs for time smaller than early-exit-threshold you get error on terminal that command exited too early. Maybe we can add flag to ignore that error.

Utkarsh-khambra commented 2 years ago

There is no RunCommand action in contour currently.

christianparpart commented 2 years ago

Also, I was thinking of building a completion script for contour zsh completion

Oh that would be awesome!

early-exit-threshold 0

... should be disabling that. Seems like it's even that quickly exiting that we're running into a race condition. That I can fix along with the current GUI refactor, I think. :)

christianparpart commented 2 years ago

@christianparpart iirc I worked on CWD spawn of new terminal, how did it get broken again?

@Utkarsh-khambra let's see if we can make it testable, so it won't accidentally break then. :)

EDIT: if not programmatically from the inside, it can 100% be (made) testable on the CI using some script-fu.

Yaraslaut commented 1 year ago

At the moment contour on NewTerminal action spawns it using pwd

Utkarsh-khambra commented 1 year ago

Only on Windows contour doesn't spawn NewTerminal in CWD , see.

uspasojevic96 commented 1 year ago

Sounds about right, I did it for macOS