mirror of
https://github.com/onyx-and-iris/gobs-cli.git
synced 2026-04-18 07:03:37 +00:00
style tables and add out/err highlights
improve projector open error message if an invalid monitor index is passed. it now prints the monitor name and suggests `gobs-cli prj ls-m` improve error message for sceneitem commands if a scene item in a group is queried without the --group flag.
This commit is contained in:
@@ -4,7 +4,8 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/andreykaipov/goobs/api/requests/config"
|
||||
"github.com/aquasecurity/table"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/charmbracelet/lipgloss/table"
|
||||
)
|
||||
|
||||
// SceneCollectionCmd provides commands to manage scene collections in OBS Studio.
|
||||
@@ -19,21 +20,37 @@ type SceneCollectionCmd struct {
|
||||
type SceneCollectionListCmd struct{} // size = 0x0
|
||||
|
||||
// Run executes the command to list all scene collections.
|
||||
// nolint: misspell
|
||||
func (cmd *SceneCollectionListCmd) Run(ctx *context) error {
|
||||
collections, err := ctx.Client.Config.GetSceneCollectionList()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get scene collection list: %w", err)
|
||||
}
|
||||
|
||||
t := table.New(ctx.Out)
|
||||
t.SetPadding(3)
|
||||
t.SetAlignment(table.AlignLeft)
|
||||
t.SetHeaders("Scene Collection Name")
|
||||
t := table.New().Border(lipgloss.RoundedBorder()).
|
||||
BorderStyle(lipgloss.NewStyle().Foreground(ctx.Style.border)).
|
||||
Headers("Scene Collection Name").
|
||||
StyleFunc(func(row, col int) lipgloss.Style {
|
||||
style := lipgloss.NewStyle().Padding(0, 3)
|
||||
switch col {
|
||||
case 0:
|
||||
style = style.Align(lipgloss.Left)
|
||||
}
|
||||
switch {
|
||||
case row == table.HeaderRow:
|
||||
style = style.Bold(true).Align(lipgloss.Center)
|
||||
case row%2 == 0:
|
||||
style = style.Foreground(ctx.Style.evenRows)
|
||||
default:
|
||||
style = style.Foreground(ctx.Style.oddRows)
|
||||
}
|
||||
return style
|
||||
})
|
||||
|
||||
for _, collection := range collections.SceneCollections {
|
||||
t.AddRow(collection)
|
||||
t.Row(collection)
|
||||
}
|
||||
t.Render()
|
||||
fmt.Fprintln(ctx.Out, t.Render())
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -65,17 +82,17 @@ func (cmd *SceneCollectionSwitchCmd) Run(ctx *context) error {
|
||||
current := collections.CurrentSceneCollectionName
|
||||
|
||||
if current == cmd.Name {
|
||||
return fmt.Errorf("scene collection %s is already active", cmd.Name)
|
||||
return fmt.Errorf("scene collection %s is already active", ctx.Style.Error(cmd.Name))
|
||||
}
|
||||
|
||||
_, err = ctx.Client.Config.SetCurrentSceneCollection(
|
||||
config.NewSetCurrentSceneCollectionParams().WithSceneCollectionName(cmd.Name),
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to switch scene collection: %w", err)
|
||||
return fmt.Errorf("failed to switch scene collection %s: %w", ctx.Style.Error(cmd.Name), err)
|
||||
}
|
||||
|
||||
fmt.Fprintf(ctx.Out, "Switched to scene collection: %s\n", cmd.Name)
|
||||
fmt.Fprintf(ctx.Out, "Switched to scene collection: %s\n", ctx.Style.Highlight(cmd.Name))
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -91,9 +108,9 @@ func (cmd *SceneCollectionCreateCmd) Run(ctx *context) error {
|
||||
config.NewCreateSceneCollectionParams().WithSceneCollectionName(cmd.Name),
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create scene collection: %w", err)
|
||||
return fmt.Errorf("failed to create scene collection %s: %w", ctx.Style.Error(cmd.Name), err)
|
||||
}
|
||||
|
||||
fmt.Fprintf(ctx.Out, "Created scene collection: %s\n", cmd.Name)
|
||||
fmt.Fprintf(ctx.Out, "Created scene collection: %s\n", ctx.Style.Highlight(cmd.Name))
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user