Viddy as a importable package
anvial opened this issue · comments
Hi,
First of all, thx for the excellent watcher alternative.
Are any plans to make the viddy importable go package? To use it as a watch mode implementation in other projects.
@anvial Thank you. Interesting issue.
But I don't have any idea to how abstract viddy as package.
What is the input and output.
Do you have any use case of the viddy package?
Let's take any command that we wish to watch: any-command
Usually, we do the following: watch (or viddy) -n 1s any-command --some-flags
But what if we wish to integrate watcher functionality inside any-command
: any-command --watch 1s
To implement this, we need to import NewViddy()
from the Viddy package.
It will be nice to provide NewPreconfiguedViddy()
with incapsulation of config generation not to bring 'viper' and other dependencies into the origin project.
Make sense?
I see.
So the package users can construct viddy by like NewViddy("any-command", "args")
.
And interact with viddy by the method of the object.
Is this correct?
I'm refactoring viddy now.
I would like to do that with considering that usage.
Yes, almost
I see it as an implementation inside --watch
flag behavior of any-command
.
So, for Viddy any-command
is also a part of args
Smth like this:
import (
"github.com/sachaos/viddy"
)
func RunAnyCommand() error {
...
if watchFlag != 0 {
anyCommandArgs, watchValue := anyCommandArgsWithoutWatch(os.Args)
// Prepare Viddy args
viddyArgs := append([]string{"--no-title", "--differences", "--interval", watchValue}, anyCommandArgs...)
// Define tview styles and launch preconfigured Viddy watcher
app := viddy.NewPreconfiguredViddy(viddyArgs)
if err := app.Run(); err != nil {
return err
}
} else {
...
}
return nil
}
Hi, @sachaos
I hope you're doing well.
Any updates on this issue?
If any help is needed, just ping me.
@anvial Hi.
I'm refactoring viddy now.
Please wait for a while. 🙏
no worries, thank you for your work!
I'll be in touch if needed.
This sounds very useful for many projects.
I am wondering if the TUI would need to change or is it generic enough to cope ?
Is this the branch ?
https://github.com/sachaos/viddy/commits/feature/refactoring-viddy
Ah it looks like it was forked and done here: juju/viddy@master...anvial:viddy:master
@anvial great work !!
I guess one day it will get merged ?
I've prepared a draft PR: #77
waiting for feedback and discussion because to have the same flexibility in Viddy config that there is now in main.go
, we need to do more methods public (like viddy.NewConfig
and 'conf.Theme').