diff --git a/README.md b/README.md index ec15fc9..c0c615a 100644 --- a/README.md +++ b/README.md @@ -524,6 +524,33 @@ gobs-cli toggle 'Mic/Aux' 'Gain' gobs-cli status 'Mic/Aux' 'Gain' ``` +### ProjectorCmd + +- list-monitors: List available monitors. + +```console +gobs-cli projector list-monitors +``` + +- open: Open a fullscreen projector for a source on a specific monitor. + - flags: + + *optional* + - --monitor-index: Index of the monitor to open the projector on. + - defaults to 0 + + *optional* + - args: + - defaults to current scene + +```console +gobs-cli project open + +gobs-cli projector open --monitor-index=1 "test_scene" + +gobs-cli projector open --monitor-index=1 "test_group" +``` + [userconfigdir]: https://pkg.go.dev/os#UserConfigDir [obs-keyids]: https://github.com/obsproject/obs-studio/blob/master/libobs/obs-hotkeys.h \ No newline at end of file diff --git a/main.go b/main.go index 12794f4..8d488bb 100644 --- a/main.go +++ b/main.go @@ -45,6 +45,7 @@ type CLI struct { Virtualcam VirtualCamCmd `help:"Manage virtual camera." cmd:"" aliases:"vc"` Hotkey HotkeyCmd `help:"Manage hotkeys." cmd:"" aliases:"hk"` Filter FilterCmd `help:"Manage filters." cmd:"" aliases:"f"` + Projector ProjectorCmd `help:"Manage projectors." cmd:"" aliases:"prj"` } type context struct { diff --git a/projector.go b/projector.go new file mode 100644 index 0000000..49d7bc3 --- /dev/null +++ b/projector.go @@ -0,0 +1,66 @@ +package main + +import ( + "fmt" + + "github.com/andreykaipov/goobs/api/requests/ui" + "github.com/aquasecurity/table" +) + +// ProjectorCmd provides a command to manage projectors in OBS. +type ProjectorCmd struct { + ListMonitors ProjectorListMonitorsCmd `cmd:"" help:"List available monitors." aliases:"ls-m"` + Open ProjectorOpenCmd `cmd:"" help:"Open a fullscreen projector for a source on a specific monitor." aliases:"o"` +} + +// ProjectorListMonitorsCmd provides a command to list all monitors available for projectors. +type ProjectorListMonitorsCmd struct{} // size = 0x0 + +// Run executes the command to list all monitors available for projectors. +func (cmd *ProjectorListMonitorsCmd) Run(ctx *context) error { + monitors, err := ctx.Client.Ui.GetMonitorList() + if err != nil { + return err + } + + if len(monitors.Monitors) == 0 { + ctx.Out.Write([]byte("No monitors found for projectors.\n")) + return nil + } + + t := table.New(ctx.Out) + t.SetPadding(3) + t.SetAlignment(table.AlignCenter, table.AlignLeft) + t.SetHeaders("Monitor ID", "Monitor Name") + + for _, monitor := range monitors.Monitors { + t.AddRow(fmt.Sprintf("%d", monitor.MonitorIndex), monitor.MonitorName) + } + + t.Render() + return nil +} + +// ProjectorOpenCmd provides a command to open a fullscreen projector for a specific source. +type ProjectorOpenCmd struct { + MonitorIndex int `flag:"" help:"Index of the monitor to open the projector on." default:"0"` + SourceName string ` help:"Name of the source to project." default:"" arg:""` +} + +// Run executes the command to show details of a specific projector. +func (cmd *ProjectorOpenCmd) Run(ctx *context) error { + if cmd.SourceName == "" { + currentScene, err := ctx.Client.Scenes.GetCurrentProgramScene() + if err != nil { + return fmt.Errorf("failed to get current program scene: %w", err) + } + cmd.SourceName = currentScene.SceneName + } + + ctx.Client.Ui.OpenSourceProjector(ui.NewOpenSourceProjectorParams(). + WithSourceName(cmd.SourceName). + WithMonitorIndex(cmd.MonitorIndex)) + + fmt.Fprintf(ctx.Out, "Opened projector for source '%s' on monitor index %d.\n", cmd.SourceName, cmd.MonitorIndex) + return nil +}