MCPcopy Index your code
hub / github.com/nikivdev/go / runFocusCursorWindow

Function runFocusCursorWindow

cli/flow/main.go:1745–1806  ·  view source on GitHub ↗
(ctx *snap.Context)

Source from the content-addressed store, hash-verified

1743}
1744
1745func runFocusCursorWindow(ctx *snap.Context) error {
1746 if ctx.NArgs() != 0 {
1747 fmt.Fprintf(ctx.Stderr(), "Usage: %s focusCursorWindow\n", commandName)
1748 return fmt.Errorf("expected 0 arguments, got %d", ctx.NArgs())
1749 }
1750
1751 entry, err := fetchLatestWindowFocusEntry()
1752 if err != nil {
1753 return reportError(ctx, fmt.Errorf("load latest window_focus entry: %w", err))
1754 }
1755 if entry == nil {
1756 fmt.Fprintln(ctx.Stdout(), "No window_focus entry without a trailing '.' workspace name was found.")
1757 return nil
1758 }
1759
1760 description := entry.WindowTitle
1761 if description == "" {
1762 description = entry.WorkspaceName
1763 }
1764 fmt.Fprintf(ctx.Stdout(), "Latest entry #%d: %s\n", entry.ID, description)
1765
1766 var (
1767 focused bool
1768 reason string
1769 )
1770
1771 if entry.WindowTitle != "" {
1772 focused, reason, err = focusCursorWindowByTitle(entry.WindowTitle)
1773 if err != nil {
1774 return reportError(ctx, fmt.Errorf("focus Cursor window %q: %w", entry.WindowTitle, err))
1775 }
1776 } else {
1777 reason = "entry has no window title"
1778 }
1779
1780 if focused {
1781 fmt.Fprintf(ctx.Stdout(), "✔️ Focused Cursor window %q\n", entry.WindowTitle)
1782 return nil
1783 }
1784
1785 openPath := entry.cursorOpenPath()
1786 if openPath == "" {
1787 if reason != "" {
1788 fmt.Fprintf(ctx.Stdout(), "ℹ️ %s\n", reason)
1789 }
1790 fmt.Fprintln(ctx.Stdout(), "No workspace path available to open in Cursor.")
1791 return nil
1792 }
1793
1794 if reason != "" {
1795 fmt.Fprintf(ctx.Stdout(), "ℹ️ %s; opening %s in Cursor instead.\n", reason, openPath)
1796 } else {
1797 fmt.Fprintf(ctx.Stdout(), "ℹ️ Opening %s in Cursor.\n", openPath)
1798 }
1799
1800 if err := openInCursor(ctx, openPath); err != nil {
1801 return reportError(ctx, fmt.Errorf("open %s in Cursor: %w", openPath, err))
1802 }

Callers 1

mainFunction · 0.85

Calls 5

reportErrorFunction · 0.85
focusCursorWindowByTitleFunction · 0.85
openInCursorFunction · 0.85
cursorOpenPathMethod · 0.80

Tested by

no test coverage detected