GetForegroundSessionID returns the ID of the session currently displayed in the TUI. This is only available when connecting to a server running in TUI+server mode (--ui-server). Returns nil if no foreground session is set. Example: sessionID, err := client.GetForegroundSessionID() if err != nil
(ctx context.Context)
| 1387 | // fmt.Printf("TUI is displaying session: %s\n", *sessionID) |
| 1388 | // } |
| 1389 | func (c *Client) GetForegroundSessionID(ctx context.Context) (*string, error) { |
| 1390 | if err := c.ensureConnected(ctx); err != nil { |
| 1391 | return nil, err |
| 1392 | } |
| 1393 | |
| 1394 | result, err := c.client.Request(ctx, "session.getForeground", getForegroundSessionRequest{}) |
| 1395 | if err != nil { |
| 1396 | return nil, err |
| 1397 | } |
| 1398 | |
| 1399 | var response getForegroundSessionResponse |
| 1400 | if err := json.Unmarshal(result, &response); err != nil { |
| 1401 | return nil, fmt.Errorf("failed to unmarshal getForeground response: %w", err) |
| 1402 | } |
| 1403 | |
| 1404 | return response.SessionID, nil |
| 1405 | } |
| 1406 | |
| 1407 | // SetForegroundSessionID requests the TUI to switch to displaying the specified session. |
| 1408 | // |