termonad icon indicating copy to clipboard operation
termonad copied to clipboard

take arguments on the command line

Open cdepillabout opened this issue 6 years ago • 8 comments

It would be nice to accept arguments to termonad on the command line. Where possible, the current Termonad options should be able to be specified on the command line as flags:

http://hackage.haskell.org/package/termonad-1.0.0.0/docs/Termonad-Config.html

However, not all options will be able to be easily specified on the command line. That's okay. You'll also need to make sure that options specified on the command line override those specified in the Termonad configuration file (termonad.hs).

You'll have to make the command line option parser extensible by Termonad extensions. Currently the only extension is the color extension:

http://hackage.haskell.org/package/termonad-1.0.0.0/docs/Termonad-Config-Colour.html

Since termonad uses dyre to recompile the configuration file, you'll have to figure out how command line flags interact with this process. Ideally something like the following would be possible:

  • Run termonad with a bunch of different command line flags.
  • termonad parses the ones it understands, and ignores the ones it doesn't understand.
  • termonad looks for a special command line flag like --conf-file that has the location of the termonad.hs configuration file.
  • termonad uses this new configuration file location to load the configuration and recompile.
  • termonad launches the new termonad binary, passing it ALL of the original command line flags.
  • The new termonad binary is able to use all the command line flags.

When implementing this, please use a common command line parser like optparse-applicative.

cdepillabout avatar Nov 14 '18 03:11 cdepillabout

As long as you've used optparse-applicative, this shouldn't actually be too difficult to figure out. It is also a good way to get familiar with all of Termonad's options, since you'll have to make sure to parse them on the command line.

Although, this might be tricky to figure out how to make the parser extensible by extensions, as well as the interactions with dyre. If you try to tackle this but end up needing help, please feel free to ask on this issue.

cdepillabout avatar Nov 14 '18 03:11 cdepillabout

Hi there - I've started working on this. I've noticed that dyre will only allow you to specify a different directory for its config search. it expects the name of the file to match your executable i.e. termonad and termonad.hs. Do you think that's enough?

In my testing so far the new binary seems to receive and process the original flags as expected.

I haven't really looked at extensions yet. My first thought is that I should be able to write a parser in one of them and use its hook to process them there.

aware70 avatar Dec 27 '18 22:12 aware70

Hi, thanks for working on this!

I've noticed that dyre will only allow you to specify a different directory for its config search. it expects the name of the file to match your executable i.e. termonad and termonad.hs. Do you think that's enough?

Yeah, that sounds good for now. I guess eventually we should send a PR to dyre to add an option to change the name of the configuration file, but that is out of scope for this issue.

In my testing so far the new binary seems to receive and process the original flags as expected.

Okay great, looking forward to the PR!

I haven't really looked at extensions yet. My first thought is that I should be able to write a parser in one of them and use its hook to process them there.

Yeah, maybe adding a new hook that is able to process the command line arguments would be the easiest thing to do here.

Although I really haven't thought about this too much recently, so there could be an easier way.

cdepillabout avatar Dec 28 '18 00:12 cdepillabout

@aware70 Are you still working on this? If you don't mind, I'd like to help you with this issue.

ghost avatar Sep 18 '19 00:09 ghost

@lattfein As far as I know, this is not being worked on, so please feel free to go ahead and start working on this.

cdepillabout avatar Sep 18 '19 00:09 cdepillabout

On Debian systems, a terminal emulator that wants to provide the virtual package x-terminal-emulator must understand the -e and -T options: https://www.debian.org/doc/debian-policy/ch-customized-programs.html#packages-providing-a-terminal-emulator

BTW: I learned about termonad now because it entered the Debian archive.

thkoch2001 avatar Nov 03 '20 20:11 thkoch2001

@thkoch2001 Thanks for the heads up!

I'd be happy to take a PR adding support for -e and -T. From the linked webpage:

To be an x-terminal-emulator, a program must:

  • Be able to emulate a DEC VT100 terminal, or a compatible terminal.

  • Support the command-line option -e command, which creates a new terminal window 6 and runs the specified command. may be multiple arguments, which form the argument list to the executed program. In other words, the behavior is as though the arguments were passed directly to execvp, bypassing the shell. (xterm’s behavior of falling back on using the shell if -e had a single argument and exec failed is permissible but not required.)

  • Support the command-line option -T title, which creates a new terminal window with the window title title.

cdepillabout avatar Nov 04 '20 00:11 cdepillabout

It would also be nice to have an option like --ignore-conf-file that ignores the ~/.config/termonad/termonad.hs and ~/.config/termonad/termonad.yaml configuration files and just launches termonad with the default config.

cdepillabout avatar Jan 04 '21 03:01 cdepillabout

+1

refaelsh avatar Oct 30 '22 21:10 refaelsh

This is implemented in #234.

However, I didn't add an option for ignoring the config file as suggested in https://github.com/cdepillabout/termonad/issues/81#issuecomment-753733687. If someone wants this, I'd be happy to merge in a PR adding this.

cdepillabout avatar Oct 04 '23 03:10 cdepillabout