File size: 1,326 Bytes
6a7089a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package actions

import (
	"fmt"
	"net/http"
	"os"

	"github.com/pinchtab/pinchtab/internal/cli"
	"github.com/pinchtab/pinchtab/internal/cli/apiclient"
)

// TabList lists all open tabs.
func TabList(client *http.Client, base, token string) {
	apiclient.DoGet(client, base, token, "/tabs", nil)
}

// TabNew opens a new tab (exported for cobra subcommand).
func TabNew(client *http.Client, base, token string, body map[string]any) {
	// Check if any instances are running
	instances := getInstances(client, base, token)
	if len(instances) == 0 {
		fmt.Fprintln(os.Stderr, cli.StyleStderr(cli.WarningStyle, "No instances running, launching default..."))
		launchInstance(client, base, token, "default")
		fmt.Fprintln(os.Stderr, cli.StyleStderr(cli.SuccessStyle, "Instance launched"))
	}
	apiclient.DoPost(client, base, token, "/tab", body)
}

// TabClose closes a tab by ID.
func TabClose(client *http.Client, base, token string, tabID string) {
	apiclient.DoPost(client, base, token, "/tab", map[string]any{
		"action": "close",
		"tabId":  tabID,
	})
}

// TabFocus switches to a tab by ID, making it the active tab
// for subsequent commands.
func TabFocus(client *http.Client, base, token string, tabID string) {
	apiclient.DoPost(client, base, token, "/tab", map[string]any{
		"action": "focus",
		"tabId":  tabID,
	})
}