@namzu/cli 44.1.1 → 44.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/dist/bin.js +1 -1
- package/dist/chunks/acp-OUBJWH5B.js +7754 -0
- package/dist/chunks/acp-OUBJWH5B.js.map +6 -0
- package/dist/chunks/{activity-command-Y5ZLCQ63.js → activity-command-R7MUSZIY.js} +16 -15
- package/dist/chunks/activity-command-R7MUSZIY.js.map +6 -0
- package/dist/chunks/{add-F7M57FGR.js → add-PSEIDDRW.js} +21 -18
- package/dist/chunks/add-PSEIDDRW.js.map +6 -0
- package/dist/chunks/{agent-AFX2UZU5.js → agent-YPEXUYPH.js} +35 -30
- package/dist/chunks/agent-session-EZB2OYG3.js +65 -0
- package/dist/chunks/{archive-6NM6DYAT.js → archive-ET4PXE34.js} +11 -10
- package/dist/chunks/archive-ET4PXE34.js.map +6 -0
- package/dist/chunks/{bin-main-I6CHRYYQ.js → bin-main-PMB57AZJ.js} +9 -9
- package/dist/chunks/binding-K6RIQ5AP.js +17 -0
- package/dist/chunks/{browser-OPMOTWTV.js → browser-SKTIAVBF.js} +6 -6
- package/dist/chunks/{chat-KGVPXQS6.js → chat-AVIVXXMD.js} +20 -19
- package/dist/chunks/chat-AVIVXXMD.js.map +6 -0
- package/dist/chunks/chunk-26C37THH.js +867 -0
- package/dist/chunks/chunk-26C37THH.js.map +6 -0
- package/dist/chunks/{chunk-CTN4O42X.js → chunk-2EHPXO4E.js} +3 -3
- package/dist/chunks/{chunk-LS75R55C.js → chunk-2NI5NS5S.js} +3 -3
- package/dist/chunks/{chunk-RV5QY3IY.js → chunk-2U5M5IYH.js} +6 -6
- package/dist/chunks/{chunk-PWOG3OMH.js → chunk-2X6JZAKH.js} +9 -9
- package/dist/chunks/{chunk-W5QFVC74.js → chunk-2Y26DLOF.js} +27 -10
- package/dist/chunks/{chunk-W5QFVC74.js.map → chunk-2Y26DLOF.js.map} +1 -1
- package/dist/chunks/{chunk-BR6EWAKQ.js → chunk-3QGJXD7U.js} +5 -5
- package/dist/chunks/{chunk-XFNCCDJK.js → chunk-435DYOG4.js} +2 -2
- package/dist/chunks/{chunk-Y44FAVKA.js → chunk-4OXIJ2EF.js} +3 -3
- package/dist/chunks/{chunk-RSRJQB6Q.js → chunk-6EJFXJDO.js} +204 -68
- package/dist/chunks/chunk-6EJFXJDO.js.map +6 -0
- package/dist/chunks/{chunk-UC3ZACVN.js → chunk-6FWFSPUL.js} +2 -2
- package/dist/chunks/chunk-6HTC5TQ3.js +89 -0
- package/dist/chunks/chunk-6HTC5TQ3.js.map +6 -0
- package/dist/chunks/chunk-6IDFHPY3.js +413 -0
- package/dist/chunks/chunk-6IDFHPY3.js.map +6 -0
- package/dist/chunks/chunk-7FPKSX4M.js +61 -0
- package/dist/chunks/chunk-7FPKSX4M.js.map +6 -0
- package/dist/chunks/{chunk-EFEZWLZC.js → chunk-7QQOUCGI.js} +12 -10
- package/dist/chunks/chunk-7QQOUCGI.js.map +6 -0
- package/dist/chunks/{chunk-KHM2XON5.js → chunk-7TEXDZVO.js} +17 -3
- package/dist/chunks/chunk-7TEXDZVO.js.map +6 -0
- package/dist/chunks/{chunk-WPNT6IGU.js → chunk-A5GTZ7R2.js} +2 -2
- package/dist/chunks/{chunk-BIGRB2H4.js → chunk-ACSG5R5P.js} +3 -3
- package/dist/chunks/{chunk-QV43JSBP.js → chunk-AI6PBE5G.js} +2 -2
- package/dist/chunks/{chunk-HXZ2JXCO.js → chunk-AX5ESG6K.js} +2 -2
- package/dist/chunks/{chunk-DESOZLEL.js → chunk-B3XIVOLM.js} +2 -2
- package/dist/chunks/{chunk-ZXKN4TWP.js → chunk-BGKQCLLH.js} +242 -447
- package/dist/chunks/chunk-BGKQCLLH.js.map +6 -0
- package/dist/chunks/chunk-BT7ZELXJ.js +63 -0
- package/dist/chunks/chunk-BT7ZELXJ.js.map +6 -0
- package/dist/chunks/{chunk-ZUN2WRCB.js → chunk-DECJPLLA.js} +13 -13
- package/dist/chunks/{chunk-GSYPRZZU.js → chunk-DFCJYRT5.js} +2 -2
- package/dist/chunks/{chunk-QNTR7X7D.js → chunk-DQLSLXDF.js} +5 -5
- package/dist/chunks/chunk-EXFSMYH4.js +83 -0
- package/dist/chunks/chunk-EXFSMYH4.js.map +6 -0
- package/dist/chunks/{chunk-6Z2ZJ4BA.js → chunk-FHQTXWDA.js} +4 -4
- package/dist/chunks/chunk-G73G2WGR.js +242 -0
- package/dist/chunks/chunk-G73G2WGR.js.map +6 -0
- package/dist/chunks/{chunk-BLM6IQS4.js → chunk-GANFMGV7.js} +5 -5
- package/dist/chunks/{chunk-REDD2WY7.js → chunk-GBS6ATYF.js} +2 -2
- package/dist/chunks/{chunk-ORVWGSLG.js → chunk-GCCFTP47.js} +4 -4
- package/dist/chunks/{chunk-FKIO77IY.js → chunk-GNEDN6MU.js} +12 -12
- package/dist/chunks/{chunk-NS7EU37U.js → chunk-HB5ZN5KQ.js} +2 -2
- package/dist/chunks/{chunk-EFQ6FUFZ.js → chunk-HELINLSD.js} +2 -2
- package/dist/chunks/{chunk-AY7B43MK.js → chunk-HKCIZR5P.js} +13 -13
- package/dist/chunks/chunk-HRJPVPSU.js +164 -0
- package/dist/chunks/chunk-HRJPVPSU.js.map +6 -0
- package/dist/chunks/{chunk-NPZY5OJ5.js → chunk-HTBMDD6Y.js} +8 -8
- package/dist/chunks/{chunk-LN26A356.js → chunk-I5E4MT3C.js} +4 -4
- package/dist/chunks/{chunk-KK2L4FD2.js → chunk-IJZ7SLBV.js} +3 -3
- package/dist/chunks/{chunk-YAEHAYI4.js → chunk-ITA57VY5.js} +7 -5
- package/dist/chunks/chunk-ITA57VY5.js.map +6 -0
- package/dist/chunks/{chunk-W4E2N7TY.js → chunk-IZVN6K6U.js} +4 -4
- package/dist/chunks/{chunk-7U36A4WQ.js → chunk-JL64XHSL.js} +55 -5
- package/dist/chunks/chunk-JL64XHSL.js.map +6 -0
- package/dist/chunks/chunk-KLKAK2O5.js +5817 -0
- package/dist/chunks/chunk-KLKAK2O5.js.map +6 -0
- package/dist/chunks/{chunk-465CVUN4.js → chunk-L2NNJ4XL.js} +3 -3
- package/dist/chunks/{chunk-JCUPTKQY.js → chunk-LF76CVOZ.js} +4 -4
- package/dist/chunks/{chunk-ZATO2QOS.js → chunk-LFPTXRMM.js} +2 -2
- package/dist/chunks/chunk-LG27EJU6.js +189 -0
- package/dist/chunks/chunk-LG27EJU6.js.map +6 -0
- package/dist/chunks/{chunk-UHPRMPWX.js → chunk-LKJBDF7W.js} +15 -3
- package/dist/chunks/chunk-LKJBDF7W.js.map +6 -0
- package/dist/chunks/chunk-LKODRKMZ.js +575 -0
- package/dist/chunks/chunk-LKODRKMZ.js.map +6 -0
- package/dist/chunks/{chunk-WLUGKIYQ.js → chunk-LQRP2VRQ.js} +4 -4
- package/dist/chunks/{chunk-UGAT33T5.js → chunk-LYGD5P7O.js} +3 -3
- package/dist/chunks/{chunk-CRWNJ62V.js → chunk-M2OZ4SVS.js} +3 -3
- package/dist/chunks/{chunk-I32JTWDW.js → chunk-MGZSEPDY.js} +2 -2
- package/dist/chunks/{chunk-HYFX32Y3.js → chunk-MJBGVVI5.js} +3 -3
- package/dist/chunks/{chunk-YPRKTJ5P.js → chunk-MYL75RA4.js} +2 -2
- package/dist/chunks/chunk-PIVHVYCN.js +3925 -0
- package/dist/chunks/chunk-PIVHVYCN.js.map +6 -0
- package/dist/chunks/{chunk-AE4LOPZF.js → chunk-PMX2WTZL.js} +2 -2
- package/dist/chunks/{chunk-FPLDTTM2.js → chunk-QWSZ5P4C.js} +6 -6
- package/dist/chunks/{chunk-T5POXPXY.js → chunk-RSIWTHYS.js} +3 -3
- package/dist/chunks/{chunk-UP3SWACV.js → chunk-S4QOQGAT.js} +2 -2
- package/dist/chunks/chunk-S7WRWA25.js +33 -0
- package/dist/chunks/chunk-S7WRWA25.js.map +6 -0
- package/dist/chunks/{chunk-ZRBGY4SL.js → chunk-SGRO4RJP.js} +2 -2
- package/dist/chunks/{chunk-WKUTR7YW.js → chunk-SJFPZPOJ.js} +80 -17
- package/dist/chunks/chunk-SJFPZPOJ.js.map +6 -0
- package/dist/chunks/{chunk-JAYPFJGZ.js → chunk-TZZOQ62Z.js} +2 -2
- package/dist/chunks/chunk-U4SST7AD.js +219 -0
- package/dist/chunks/chunk-U4SST7AD.js.map +6 -0
- package/dist/chunks/{chunk-CMAZ3DYB.js → chunk-UGDZ7MLG.js} +4 -4
- package/dist/chunks/chunk-VDKDXDOH.js +290 -0
- package/dist/chunks/chunk-VDKDXDOH.js.map +6 -0
- package/dist/chunks/{chunk-2NFPIARP.js → chunk-VFVWHYHT.js} +4 -4
- package/dist/chunks/{chunk-5UB2LLPG.js → chunk-VZ4PKWLF.js} +2 -2
- package/dist/chunks/{chunk-WLAI3VCE.js → chunk-WKFHQQOU.js} +2 -2
- package/dist/chunks/{chunk-JSFF2HGX.js → chunk-WKPRYH24.js} +3 -3
- package/dist/chunks/{chunk-VR4MTSMH.js → chunk-WQFHJ4TO.js} +3 -3
- package/dist/chunks/{chunk-RFMODICJ.js → chunk-WYJ3CNXX.js} +80 -38
- package/dist/chunks/chunk-WYJ3CNXX.js.map +6 -0
- package/dist/chunks/{chunk-ZNYKZ3MI.js → chunk-XPLHAOGE.js} +2 -2
- package/dist/chunks/{chunk-2NGXQQPP.js → chunk-XX2SP5AM.js} +3 -3
- package/dist/chunks/{chunk-T2PF65KB.js → chunk-YDSWGJWF.js} +2 -2
- package/dist/chunks/{chunk-LUSUJZR2.js → chunk-YJ6NWB2B.js} +2 -2
- package/dist/chunks/{chunk-O4MFP726.js → chunk-YTE3QIH3.js} +998 -393
- package/dist/chunks/chunk-YTE3QIH3.js.map +6 -0
- package/dist/chunks/{chunk-JH3SDABI.js → chunk-YUYNIAJX.js} +6 -6
- package/dist/chunks/{chunk-TX2PUHTP.js → chunk-YXIG4OT2.js} +2 -2
- package/dist/chunks/{cli-runtime-HTTDQPEZ.js → cli-runtime-F4MEMBDL.js} +11 -10
- package/dist/chunks/cli-runtime-F4MEMBDL.js.map +6 -0
- package/dist/chunks/{commands-ZD2L5QMI.js → commands-ZCNZVYTG.js} +5 -5
- package/dist/chunks/{crash-report-2IRIZSBD.js → crash-report-K53VF4H5.js} +6 -6
- package/dist/chunks/{dist-GSYFGRQT.js → dist-6IPPA55L.js} +2 -2
- package/dist/chunks/{dist-45IFTDJW.js → dist-H53G25BE.js} +2 -2
- package/dist/chunks/{dist-RQJEJN3Z.js → dist-L5LBM77I.js} +2 -2
- package/dist/chunks/{dist-OJTB6QLR.js → dist-RIH2Q2ER.js} +2 -2
- package/dist/chunks/{dist-OCZJJFHF.js → dist-RTIKLSUV.js} +2 -2
- package/dist/chunks/{dist-TWYNAZDN.js → dist-T6KE7URX.js} +2 -2
- package/dist/chunks/{dist-FNGLTQIG.js → dist-VSJGDIXP.js} +32 -2
- package/dist/chunks/{dist-NL7WG7PX.js → dist-XNGK3C4G.js} +2 -2
- package/dist/chunks/{doctor-NKPCWPB4.js → doctor-DOCGTBME.js} +17 -15
- package/dist/chunks/{drain-YTSVAQP5.js → drain-LT3J2MEA.js} +13 -13
- package/dist/chunks/entry-UHKDLPDS.js +232 -0
- package/dist/chunks/entry-UHKDLPDS.js.map +6 -0
- package/dist/chunks/{eval-ILFXDQUQ.js → eval-DH26W2QK.js} +2 -2
- package/dist/chunks/{exec-3JDAB34N.js → exec-QGAHWUUQ.js} +57 -47
- package/dist/chunks/exec-QGAHWUUQ.js.map +6 -0
- package/dist/chunks/{github-FH7PPWVW.js → github-JTMZJAZL.js} +4 -4
- package/dist/chunks/{home-5OIZIDIT.js → home-GGVNSCCU.js} +3 -3
- package/dist/chunks/host-6CUYPX4T.js +23 -0
- package/dist/chunks/{host-queries-SO2NOQRR.js → host-queries-4EW7M54U.js} +16 -15
- package/dist/chunks/host-queries-4EW7M54U.js.map +6 -0
- package/dist/chunks/{learn-RHNMJ4BD.js → learn-PAO3IOYA.js} +13 -13
- package/dist/chunks/{learn-builtin-UQ3MWGK6.js → learn-builtin-DXZUXOGG.js} +19 -19
- package/dist/chunks/{lifecycle-RTDYXKBW.js → lifecycle-KDN4D7DP.js} +30 -26
- package/dist/chunks/{list-G6OA34RL.js → list-KSP6S57Z.js} +15 -14
- package/dist/chunks/list-KSP6S57Z.js.map +6 -0
- package/dist/chunks/{live-44HBQCQY.js → live-XWJ2JOFO.js} +15 -13
- package/dist/chunks/{login-J4PWR4FM.js → login-3Q2HKQUW.js} +10 -8
- package/dist/chunks/{logs-22QAEH2Q.js → logs-UYB55HOX.js} +4 -4
- package/dist/chunks/{mcp-EXFVIHPJ.js → mcp-JWSI4KA6.js} +25 -22
- package/dist/chunks/mcp-JWSI4KA6.js.map +6 -0
- package/dist/chunks/{message-command-B4L2W4YZ.js → message-command-YP6TGD3K.js} +47 -42
- package/dist/chunks/message-command-YP6TGD3K.js.map +6 -0
- package/dist/chunks/open-QUDHJK5H.js +19 -0
- package/dist/chunks/{operator-tools-TEP4UTI6.js → operator-tools-43NL7HKO.js} +15 -14
- package/dist/chunks/operator-tools-43NL7HKO.js.map +6 -0
- package/dist/chunks/{output-schema-FZXJ7V33.js → output-schema-TLW5FA37.js} +3 -3
- package/dist/chunks/{pal-BUDEBIBJ.js → pal-EZE2KLYZ.js} +16 -14
- package/dist/chunks/pal-EZE2KLYZ.js.map +6 -0
- package/dist/chunks/palette-WDPS7W6Q.js +15 -0
- package/dist/chunks/peers-OBENILN2.js +18 -0
- package/dist/chunks/prefix-MLAG4KTK.js +14 -0
- package/dist/chunks/{providers-EQ32NZAT.js → providers-PJIHLTXP.js} +22 -18
- package/dist/chunks/pty-HDEXCPR6.js +29 -0
- package/dist/chunks/{resident-FSUGNG56.js → resident-2GHB3BKR.js} +32 -30
- package/dist/chunks/resident-2GHB3BKR.js.map +6 -0
- package/dist/chunks/resume-FHPY2RU3.js +24 -0
- package/dist/chunks/resume-FHPY2RU3.js.map +6 -0
- package/dist/chunks/{resume-command-DHPXCZVL.js → resume-command-VB6VA64L.js} +4 -4
- package/dist/chunks/resume-command-VB6VA64L.js.map +6 -0
- package/dist/chunks/{schedule-OJMZEWJG.js → schedule-42N4JOQJ.js} +8 -8
- package/dist/chunks/{service-EP2QHCK7.js → service-6WGZKKI4.js} +33 -29
- package/dist/chunks/service-6WGZKKI4.js.map +6 -0
- package/dist/chunks/{session-step-44XBOUDV.js → session-step-SBWIM4MZ.js} +15 -15
- package/dist/chunks/session-step-SBWIM4MZ.js.map +6 -0
- package/dist/chunks/{skills-YHAQXVP2.js → skills-V3VDOL3D.js} +11 -11
- package/dist/chunks/spaces-6II4JYTZ.js +231 -0
- package/dist/chunks/spaces-6II4JYTZ.js.map +6 -0
- package/dist/chunks/{start-check-KVZFDBD3.js → start-check-MRSPS5JT.js} +2 -2
- package/dist/chunks/start-check-MRSPS5JT.js.map +6 -0
- package/dist/chunks/{state-NXFKMBOX.js → state-HX3XRNPC.js} +2 -2
- package/dist/chunks/store-7P462EUD.js +17 -0
- package/dist/chunks/store-7P462EUD.js.map +6 -0
- package/dist/chunks/{store-KFJWAELA.js → store-FUQE7EWU.js} +13 -10
- package/dist/chunks/store-FUQE7EWU.js.map +6 -0
- package/dist/chunks/{store-QNY242NN.js → store-IX6KNJA4.js} +6 -6
- package/dist/chunks/store-IX6KNJA4.js.map +6 -0
- package/dist/chunks/{store-JLTSSGKL.js → store-MQXI7G2H.js} +4 -4
- package/dist/chunks/store-MQXI7G2H.js.map +6 -0
- package/dist/chunks/{tui-L5GKR237.js → tui-PH5B6UCO.js} +1822 -816
- package/dist/chunks/tui-PH5B6UCO.js.map +6 -0
- package/dist/chunks/{upgrade-PROVWX55.js → upgrade-HDW5MWLE.js} +6 -6
- package/dist/chunks/{worktree-ELHDXX4X.js → worktree-MLFYZF56.js} +13 -12
- package/dist/chunks/worktree-MLFYZF56.js.map +6 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/commands/exec-json.d.ts.map +1 -1
- package/dist/commands/manifest.d.ts +1 -0
- package/dist/commands/manifest.d.ts.map +1 -1
- package/dist/commands/spaces.d.ts +42 -0
- package/dist/commands/spaces.d.ts.map +1 -0
- package/dist/config/load.d.ts.map +1 -1
- package/dist/config/schema.d.ts +7 -0
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/doctor/checks/index.d.ts +2 -1
- package/dist/doctor/checks/index.d.ts.map +1 -1
- package/dist/doctor/checks/terminal.d.ts +12 -0
- package/dist/doctor/checks/terminal.d.ts.map +1 -0
- package/dist/index.js +22 -19
- package/dist/integrations/accounts/activity.d.ts +39 -0
- package/dist/integrations/accounts/activity.d.ts.map +1 -0
- package/dist/integrations/accounts/binding.d.ts +30 -0
- package/dist/integrations/accounts/binding.d.ts.map +1 -0
- package/dist/integrations/accounts/codex-login.d.ts +33 -0
- package/dist/integrations/accounts/codex-login.d.ts.map +1 -0
- package/dist/integrations/accounts/host-facts.d.ts +22 -0
- package/dist/integrations/accounts/host-facts.d.ts.map +1 -0
- package/dist/integrations/accounts/open.d.ts +23 -0
- package/dist/integrations/accounts/open.d.ts.map +1 -0
- package/dist/integrations/accounts/rows.d.ts +45 -0
- package/dist/integrations/accounts/rows.d.ts.map +1 -0
- package/dist/integrations/peers/runtime.d.ts +12 -0
- package/dist/integrations/peers/runtime.d.ts.map +1 -1
- package/dist/integrations/providers/codex-account.d.ts +30 -0
- package/dist/integrations/providers/codex-account.d.ts.map +1 -0
- package/dist/integrations/providers/codex-oauth.d.ts +12 -0
- package/dist/integrations/providers/codex-oauth.d.ts.map +1 -1
- package/dist/integrations/providers/preferences.d.ts +8 -0
- package/dist/integrations/providers/preferences.d.ts.map +1 -1
- package/dist/integrations/resident/runner-worker.js +24 -23
- package/dist/integrations/resident/runner-worker.js.map +1 -1
- package/dist/integrations/sessions/store.d.ts +13 -1
- package/dist/integrations/sessions/store.d.ts.map +1 -1
- package/dist/spaces/git.d.ts +27 -0
- package/dist/spaces/git.d.ts.map +1 -0
- package/dist/spaces/goto.d.ts +31 -0
- package/dist/spaces/goto.d.ts.map +1 -0
- package/dist/spaces/host.d.ts +380 -0
- package/dist/spaces/host.d.ts.map +1 -0
- package/dist/spaces/input.d.ts +87 -0
- package/dist/spaces/input.d.ts.map +1 -0
- package/dist/spaces/keymap.d.ts +30 -0
- package/dist/spaces/keymap.d.ts.map +1 -0
- package/dist/spaces/layout.d.ts +34 -0
- package/dist/spaces/layout.d.ts.map +1 -0
- package/dist/spaces/overlay.d.ts +105 -0
- package/dist/spaces/overlay.d.ts.map +1 -0
- package/dist/spaces/palette.d.ts +35 -0
- package/dist/spaces/palette.d.ts.map +1 -0
- package/dist/spaces/peers.d.ts +19 -0
- package/dist/spaces/peers.d.ts.map +1 -0
- package/dist/spaces/prefix.d.ts +19 -0
- package/dist/spaces/prefix.d.ts.map +1 -0
- package/dist/spaces/roster.d.ts +111 -0
- package/dist/spaces/roster.d.ts.map +1 -0
- package/dist/spaces/session.d.ts +83 -0
- package/dist/spaces/session.d.ts.map +1 -0
- package/dist/spaces/sidebar.d.ts +99 -0
- package/dist/spaces/sidebar.d.ts.map +1 -0
- package/dist/spaces/signal.d.ts +28 -0
- package/dist/spaces/signal.d.ts.map +1 -0
- package/dist/spaces/status.d.ts +20 -0
- package/dist/spaces/status.d.ts.map +1 -0
- package/dist/spaces/store.d.ts +69 -0
- package/dist/spaces/store.d.ts.map +1 -0
- package/dist/spaces/tabbar.d.ts +36 -0
- package/dist/spaces/tabbar.d.ts.map +1 -0
- package/dist/spaces/tiling.d.ts +90 -0
- package/dist/spaces/tiling.d.ts.map +1 -0
- package/dist/terminal/host/cell.d.ts +35 -0
- package/dist/terminal/host/cell.d.ts.map +1 -0
- package/dist/terminal/host/frame.d.ts +64 -0
- package/dist/terminal/host/frame.d.ts.map +1 -0
- package/dist/terminal/host/index.d.ts +5 -0
- package/dist/terminal/host/index.d.ts.map +1 -0
- package/dist/terminal/host/writer.d.ts +21 -0
- package/dist/terminal/host/writer.d.ts.map +1 -0
- package/dist/terminal/host/xterm-source.d.ts +18 -0
- package/dist/terminal/host/xterm-source.d.ts.map +1 -0
- package/dist/terminal/pty.d.ts.map +1 -1
- package/dist/terminal/screen.d.ts +12 -0
- package/dist/terminal/screen.d.ts.map +1 -1
- package/dist/tui/App.d.ts +106 -1
- package/dist/tui/App.d.ts.map +1 -1
- package/dist/tui/Composer.d.ts +7 -1
- package/dist/tui/Composer.d.ts.map +1 -1
- package/dist/tui/ResumePicker.d.ts.map +1 -1
- package/dist/tui/TextPrompt.d.ts +5 -1
- package/dist/tui/TextPrompt.d.ts.map +1 -1
- package/dist/tui/account-flow.d.ts +126 -0
- package/dist/tui/account-flow.d.ts.map +1 -0
- package/dist/tui/agent.d.ts +17 -1
- package/dist/tui/agent.d.ts.map +1 -1
- package/dist/tui/compaction-rows.d.ts.map +1 -1
- package/dist/tui/context-usage.d.ts +14 -0
- package/dist/tui/context-usage.d.ts.map +1 -1
- package/dist/tui/index.d.ts.map +1 -1
- package/dist/tui/launch-settings.d.ts +5 -2
- package/dist/tui/launch-settings.d.ts.map +1 -1
- package/dist/tui/plain-interruption.d.ts +3 -1
- package/dist/tui/plain-interruption.d.ts.map +1 -1
- package/dist/tui/resume-picker-state.d.ts +7 -0
- package/dist/tui/resume-picker-state.d.ts.map +1 -1
- package/dist/tui/slashCommands.d.ts +11 -0
- package/dist/tui/slashCommands.d.ts.map +1 -1
- package/dist/tui/tidy-tool-output.d.ts +3 -1
- package/dist/tui/tidy-tool-output.d.ts.map +1 -1
- package/dist/tui/tool-end-rows.d.ts +2 -0
- package/dist/tui/tool-end-rows.d.ts.map +1 -1
- package/dist/tui/zoom/entry.d.ts +34 -0
- package/dist/tui/zoom/entry.d.ts.map +1 -0
- package/dist/tui/zoom/gesture.d.ts +51 -0
- package/dist/tui/zoom/gesture.d.ts.map +1 -0
- package/dist/tui/zoom/leave.d.ts +11 -0
- package/dist/tui/zoom/leave.d.ts.map +1 -0
- package/dist/tui/zoom/local.d.ts +55 -0
- package/dist/tui/zoom/local.d.ts.map +1 -0
- package/dist/tui/zoom/proxy.d.ts +40 -0
- package/dist/tui/zoom/proxy.d.ts.map +1 -0
- package/package.json +9 -8
- package/dist/chunks/acp-P3S54TTC.js +0 -13601
- package/dist/chunks/acp-P3S54TTC.js.map +0 -6
- package/dist/chunks/activity-command-Y5ZLCQ63.js.map +0 -6
- package/dist/chunks/add-F7M57FGR.js.map +0 -6
- package/dist/chunks/agent-session-CFWQHSYT.js +0 -60
- package/dist/chunks/archive-6NM6DYAT.js.map +0 -6
- package/dist/chunks/chat-KGVPXQS6.js.map +0 -6
- package/dist/chunks/chunk-43PPWWYD.js +0 -1415
- package/dist/chunks/chunk-43PPWWYD.js.map +0 -6
- package/dist/chunks/chunk-7U36A4WQ.js.map +0 -6
- package/dist/chunks/chunk-EFEZWLZC.js.map +0 -6
- package/dist/chunks/chunk-KHM2XON5.js.map +0 -6
- package/dist/chunks/chunk-O4MFP726.js.map +0 -6
- package/dist/chunks/chunk-RFMODICJ.js.map +0 -6
- package/dist/chunks/chunk-RSRJQB6Q.js.map +0 -6
- package/dist/chunks/chunk-UHPRMPWX.js.map +0 -6
- package/dist/chunks/chunk-WKUTR7YW.js.map +0 -6
- package/dist/chunks/chunk-YAEHAYI4.js.map +0 -6
- package/dist/chunks/chunk-ZXKN4TWP.js.map +0 -6
- package/dist/chunks/cli-runtime-HTTDQPEZ.js.map +0 -6
- package/dist/chunks/exec-3JDAB34N.js.map +0 -6
- package/dist/chunks/host-queries-SO2NOQRR.js.map +0 -6
- package/dist/chunks/list-G6OA34RL.js.map +0 -6
- package/dist/chunks/mcp-EXFVIHPJ.js.map +0 -6
- package/dist/chunks/message-command-B4L2W4YZ.js.map +0 -6
- package/dist/chunks/operator-tools-TEP4UTI6.js.map +0 -6
- package/dist/chunks/pal-BUDEBIBJ.js.map +0 -6
- package/dist/chunks/resident-FSUGNG56.js.map +0 -6
- package/dist/chunks/resume-VXHGE5GC.js +0 -23
- package/dist/chunks/service-EP2QHCK7.js.map +0 -6
- package/dist/chunks/tui-L5GKR237.js.map +0 -6
- package/dist/chunks/worktree-ELHDXX4X.js.map +0 -6
- /package/dist/chunks/{agent-AFX2UZU5.js.map → agent-YPEXUYPH.js.map} +0 -0
- /package/dist/chunks/{agent-session-CFWQHSYT.js.map → agent-session-EZB2OYG3.js.map} +0 -0
- /package/dist/chunks/{bin-main-I6CHRYYQ.js.map → bin-main-PMB57AZJ.js.map} +0 -0
- /package/dist/chunks/{commands-ZD2L5QMI.js.map → binding-K6RIQ5AP.js.map} +0 -0
- /package/dist/chunks/{browser-OPMOTWTV.js.map → browser-SKTIAVBF.js.map} +0 -0
- /package/dist/chunks/{chunk-CTN4O42X.js.map → chunk-2EHPXO4E.js.map} +0 -0
- /package/dist/chunks/{chunk-LS75R55C.js.map → chunk-2NI5NS5S.js.map} +0 -0
- /package/dist/chunks/{chunk-RV5QY3IY.js.map → chunk-2U5M5IYH.js.map} +0 -0
- /package/dist/chunks/{chunk-PWOG3OMH.js.map → chunk-2X6JZAKH.js.map} +0 -0
- /package/dist/chunks/{chunk-BR6EWAKQ.js.map → chunk-3QGJXD7U.js.map} +0 -0
- /package/dist/chunks/{chunk-XFNCCDJK.js.map → chunk-435DYOG4.js.map} +0 -0
- /package/dist/chunks/{chunk-Y44FAVKA.js.map → chunk-4OXIJ2EF.js.map} +0 -0
- /package/dist/chunks/{chunk-UC3ZACVN.js.map → chunk-6FWFSPUL.js.map} +0 -0
- /package/dist/chunks/{chunk-WPNT6IGU.js.map → chunk-A5GTZ7R2.js.map} +0 -0
- /package/dist/chunks/{chunk-BIGRB2H4.js.map → chunk-ACSG5R5P.js.map} +0 -0
- /package/dist/chunks/{chunk-QV43JSBP.js.map → chunk-AI6PBE5G.js.map} +0 -0
- /package/dist/chunks/{chunk-HXZ2JXCO.js.map → chunk-AX5ESG6K.js.map} +0 -0
- /package/dist/chunks/{chunk-DESOZLEL.js.map → chunk-B3XIVOLM.js.map} +0 -0
- /package/dist/chunks/{chunk-ZUN2WRCB.js.map → chunk-DECJPLLA.js.map} +0 -0
- /package/dist/chunks/{chunk-GSYPRZZU.js.map → chunk-DFCJYRT5.js.map} +0 -0
- /package/dist/chunks/{chunk-QNTR7X7D.js.map → chunk-DQLSLXDF.js.map} +0 -0
- /package/dist/chunks/{chunk-6Z2ZJ4BA.js.map → chunk-FHQTXWDA.js.map} +0 -0
- /package/dist/chunks/{chunk-BLM6IQS4.js.map → chunk-GANFMGV7.js.map} +0 -0
- /package/dist/chunks/{chunk-REDD2WY7.js.map → chunk-GBS6ATYF.js.map} +0 -0
- /package/dist/chunks/{chunk-ORVWGSLG.js.map → chunk-GCCFTP47.js.map} +0 -0
- /package/dist/chunks/{chunk-FKIO77IY.js.map → chunk-GNEDN6MU.js.map} +0 -0
- /package/dist/chunks/{chunk-NS7EU37U.js.map → chunk-HB5ZN5KQ.js.map} +0 -0
- /package/dist/chunks/{chunk-EFQ6FUFZ.js.map → chunk-HELINLSD.js.map} +0 -0
- /package/dist/chunks/{chunk-AY7B43MK.js.map → chunk-HKCIZR5P.js.map} +0 -0
- /package/dist/chunks/{chunk-NPZY5OJ5.js.map → chunk-HTBMDD6Y.js.map} +0 -0
- /package/dist/chunks/{chunk-LN26A356.js.map → chunk-I5E4MT3C.js.map} +0 -0
- /package/dist/chunks/{chunk-KK2L4FD2.js.map → chunk-IJZ7SLBV.js.map} +0 -0
- /package/dist/chunks/{chunk-W4E2N7TY.js.map → chunk-IZVN6K6U.js.map} +0 -0
- /package/dist/chunks/{chunk-465CVUN4.js.map → chunk-L2NNJ4XL.js.map} +0 -0
- /package/dist/chunks/{chunk-JCUPTKQY.js.map → chunk-LF76CVOZ.js.map} +0 -0
- /package/dist/chunks/{chunk-ZATO2QOS.js.map → chunk-LFPTXRMM.js.map} +0 -0
- /package/dist/chunks/{chunk-WLUGKIYQ.js.map → chunk-LQRP2VRQ.js.map} +0 -0
- /package/dist/chunks/{chunk-UGAT33T5.js.map → chunk-LYGD5P7O.js.map} +0 -0
- /package/dist/chunks/{chunk-CRWNJ62V.js.map → chunk-M2OZ4SVS.js.map} +0 -0
- /package/dist/chunks/{chunk-I32JTWDW.js.map → chunk-MGZSEPDY.js.map} +0 -0
- /package/dist/chunks/{chunk-HYFX32Y3.js.map → chunk-MJBGVVI5.js.map} +0 -0
- /package/dist/chunks/{chunk-YPRKTJ5P.js.map → chunk-MYL75RA4.js.map} +0 -0
- /package/dist/chunks/{chunk-AE4LOPZF.js.map → chunk-PMX2WTZL.js.map} +0 -0
- /package/dist/chunks/{chunk-FPLDTTM2.js.map → chunk-QWSZ5P4C.js.map} +0 -0
- /package/dist/chunks/{chunk-T5POXPXY.js.map → chunk-RSIWTHYS.js.map} +0 -0
- /package/dist/chunks/{chunk-UP3SWACV.js.map → chunk-S4QOQGAT.js.map} +0 -0
- /package/dist/chunks/{chunk-ZRBGY4SL.js.map → chunk-SGRO4RJP.js.map} +0 -0
- /package/dist/chunks/{chunk-JAYPFJGZ.js.map → chunk-TZZOQ62Z.js.map} +0 -0
- /package/dist/chunks/{chunk-CMAZ3DYB.js.map → chunk-UGDZ7MLG.js.map} +0 -0
- /package/dist/chunks/{chunk-2NFPIARP.js.map → chunk-VFVWHYHT.js.map} +0 -0
- /package/dist/chunks/{chunk-5UB2LLPG.js.map → chunk-VZ4PKWLF.js.map} +0 -0
- /package/dist/chunks/{chunk-WLAI3VCE.js.map → chunk-WKFHQQOU.js.map} +0 -0
- /package/dist/chunks/{chunk-JSFF2HGX.js.map → chunk-WKPRYH24.js.map} +0 -0
- /package/dist/chunks/{chunk-VR4MTSMH.js.map → chunk-WQFHJ4TO.js.map} +0 -0
- /package/dist/chunks/{chunk-ZNYKZ3MI.js.map → chunk-XPLHAOGE.js.map} +0 -0
- /package/dist/chunks/{chunk-2NGXQQPP.js.map → chunk-XX2SP5AM.js.map} +0 -0
- /package/dist/chunks/{chunk-T2PF65KB.js.map → chunk-YDSWGJWF.js.map} +0 -0
- /package/dist/chunks/{chunk-LUSUJZR2.js.map → chunk-YJ6NWB2B.js.map} +0 -0
- /package/dist/chunks/{chunk-JH3SDABI.js.map → chunk-YUYNIAJX.js.map} +0 -0
- /package/dist/chunks/{chunk-TX2PUHTP.js.map → chunk-YXIG4OT2.js.map} +0 -0
- /package/dist/chunks/{crash-report-2IRIZSBD.js.map → commands-ZCNZVYTG.js.map} +0 -0
- /package/dist/chunks/{dist-FNGLTQIG.js.map → crash-report-K53VF4H5.js.map} +0 -0
- /package/dist/chunks/{dist-GSYFGRQT.js.map → dist-6IPPA55L.js.map} +0 -0
- /package/dist/chunks/{dist-45IFTDJW.js.map → dist-H53G25BE.js.map} +0 -0
- /package/dist/chunks/{dist-RQJEJN3Z.js.map → dist-L5LBM77I.js.map} +0 -0
- /package/dist/chunks/{dist-OJTB6QLR.js.map → dist-RIH2Q2ER.js.map} +0 -0
- /package/dist/chunks/{dist-OCZJJFHF.js.map → dist-RTIKLSUV.js.map} +0 -0
- /package/dist/chunks/{dist-TWYNAZDN.js.map → dist-T6KE7URX.js.map} +0 -0
- /package/dist/chunks/{doctor-NKPCWPB4.js.map → dist-VSJGDIXP.js.map} +0 -0
- /package/dist/chunks/{dist-NL7WG7PX.js.map → dist-XNGK3C4G.js.map} +0 -0
- /package/dist/chunks/{home-5OIZIDIT.js.map → doctor-DOCGTBME.js.map} +0 -0
- /package/dist/chunks/{drain-YTSVAQP5.js.map → drain-LT3J2MEA.js.map} +0 -0
- /package/dist/chunks/{eval-ILFXDQUQ.js.map → eval-DH26W2QK.js.map} +0 -0
- /package/dist/chunks/{github-FH7PPWVW.js.map → github-JTMZJAZL.js.map} +0 -0
- /package/dist/chunks/{lifecycle-RTDYXKBW.js.map → home-GGVNSCCU.js.map} +0 -0
- /package/dist/chunks/{live-44HBQCQY.js.map → host-6CUYPX4T.js.map} +0 -0
- /package/dist/chunks/{learn-RHNMJ4BD.js.map → learn-PAO3IOYA.js.map} +0 -0
- /package/dist/chunks/{learn-builtin-UQ3MWGK6.js.map → learn-builtin-DXZUXOGG.js.map} +0 -0
- /package/dist/chunks/{login-J4PWR4FM.js.map → lifecycle-KDN4D7DP.js.map} +0 -0
- /package/dist/chunks/{output-schema-FZXJ7V33.js.map → live-XWJ2JOFO.js.map} +0 -0
- /package/dist/chunks/{providers-EQ32NZAT.js.map → login-3Q2HKQUW.js.map} +0 -0
- /package/dist/chunks/{logs-22QAEH2Q.js.map → logs-UYB55HOX.js.map} +0 -0
- /package/dist/chunks/{resume-VXHGE5GC.js.map → open-QUDHJK5H.js.map} +0 -0
- /package/dist/chunks/{resume-command-DHPXCZVL.js.map → output-schema-TLW5FA37.js.map} +0 -0
- /package/dist/chunks/{session-step-44XBOUDV.js.map → palette-WDPS7W6Q.js.map} +0 -0
- /package/dist/chunks/{start-check-KVZFDBD3.js.map → peers-OBENILN2.js.map} +0 -0
- /package/dist/chunks/{store-JLTSSGKL.js.map → prefix-MLAG4KTK.js.map} +0 -0
- /package/dist/chunks/{store-KFJWAELA.js.map → providers-PJIHLTXP.js.map} +0 -0
- /package/dist/chunks/{store-QNY242NN.js.map → pty-HDEXCPR6.js.map} +0 -0
- /package/dist/chunks/{schedule-OJMZEWJG.js.map → schedule-42N4JOQJ.js.map} +0 -0
- /package/dist/chunks/{skills-YHAQXVP2.js.map → skills-V3VDOL3D.js.map} +0 -0
- /package/dist/chunks/{state-NXFKMBOX.js.map → state-HX3XRNPC.js.map} +0 -0
- /package/dist/chunks/{upgrade-PROVWX55.js.map → upgrade-HDW5MWLE.js.map} +0 -0
|
@@ -0,0 +1,3925 @@
|
|
|
1
|
+
import { createRequire as __namzuCreateRequire } from 'node:module';
|
|
2
|
+
const require = __namzuCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
SignalFilter,
|
|
5
|
+
formatResetTime
|
|
6
|
+
} from "./chunk-HRJPVPSU.js";
|
|
7
|
+
import {
|
|
8
|
+
advertisesTruecolor,
|
|
9
|
+
paletteFor
|
|
10
|
+
} from "./chunk-EXFSMYH4.js";
|
|
11
|
+
import {
|
|
12
|
+
recordForPid,
|
|
13
|
+
recordForSlot
|
|
14
|
+
} from "./chunk-7FPKSX4M.js";
|
|
15
|
+
import {
|
|
16
|
+
HeadlessScreen
|
|
17
|
+
} from "./chunk-KLKAK2O5.js";
|
|
18
|
+
import {
|
|
19
|
+
ATTR_BOLD,
|
|
20
|
+
ATTR_DIM,
|
|
21
|
+
ATTR_INVERSE,
|
|
22
|
+
ATTR_UNDERLINE,
|
|
23
|
+
BLANK_CELL,
|
|
24
|
+
CONTINUATION_CELL,
|
|
25
|
+
sameCell,
|
|
26
|
+
sgr
|
|
27
|
+
} from "./chunk-6HTC5TQ3.js";
|
|
28
|
+
import {
|
|
29
|
+
killProcessTree
|
|
30
|
+
} from "./chunk-LG27EJU6.js";
|
|
31
|
+
import {
|
|
32
|
+
stringWidth
|
|
33
|
+
} from "./chunk-U5UV2YRE.js";
|
|
34
|
+
import {
|
|
35
|
+
__name
|
|
36
|
+
} from "./chunk-76FLAFCG.js";
|
|
37
|
+
|
|
38
|
+
// src/spaces/host.ts
|
|
39
|
+
import { randomUUID } from "node:crypto";
|
|
40
|
+
import { existsSync, statSync } from "node:fs";
|
|
41
|
+
import { homedir } from "node:os";
|
|
42
|
+
import { basename, isAbsolute, join, resolve } from "node:path";
|
|
43
|
+
|
|
44
|
+
// src/terminal/host/frame.ts
|
|
45
|
+
var segmenter = new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
46
|
+
var Frame = class {
|
|
47
|
+
constructor(cols, rows) {
|
|
48
|
+
this.cols = cols;
|
|
49
|
+
this.rows = rows;
|
|
50
|
+
this.cells = new Array(cols * rows).fill(BLANK_CELL);
|
|
51
|
+
}
|
|
52
|
+
cols;
|
|
53
|
+
rows;
|
|
54
|
+
static {
|
|
55
|
+
__name(this, "Frame");
|
|
56
|
+
}
|
|
57
|
+
cells;
|
|
58
|
+
cursor = { x: 0, y: 0, visible: false };
|
|
59
|
+
cellAt(x, y) {
|
|
60
|
+
if (x < 0 || y < 0 || x >= this.cols || y >= this.rows) return void 0;
|
|
61
|
+
return this.cells[y * this.cols + x];
|
|
62
|
+
}
|
|
63
|
+
/** Sets one cell, ignoring positions outside the frame. */
|
|
64
|
+
set(x, y, cell) {
|
|
65
|
+
if (x < 0 || y < 0 || x >= this.cols || y >= this.rows) return;
|
|
66
|
+
this.cells[y * this.cols + x] = cell;
|
|
67
|
+
}
|
|
68
|
+
clip(rect) {
|
|
69
|
+
const x = Math.max(0, rect.x);
|
|
70
|
+
const y = Math.max(0, rect.y);
|
|
71
|
+
const right = Math.min(this.cols, rect.x + rect.width);
|
|
72
|
+
const bottom = Math.min(this.rows, rect.y + rect.height);
|
|
73
|
+
return { x, y, width: Math.max(0, right - x), height: Math.max(0, bottom - y) };
|
|
74
|
+
}
|
|
75
|
+
/** Fills a rectangle with blanks in the given style. */
|
|
76
|
+
fillRect(rect, style = {}) {
|
|
77
|
+
const blank = styled(" ", 1, style);
|
|
78
|
+
const r = this.clip(rect);
|
|
79
|
+
for (let y = r.y; y < r.y + r.height; y++)
|
|
80
|
+
for (let x = r.x; x < r.x + r.width; x++) this.cells[y * this.cols + x] = blank;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Writes text on one row of a rectangle, clipped to the rectangle's width. Wide
|
|
84
|
+
* characters take two cells; one that would straddle the right edge is replaced
|
|
85
|
+
* by a blank. Returns the number of columns used.
|
|
86
|
+
*/
|
|
87
|
+
writeText(rect, row, text, style = {}) {
|
|
88
|
+
if (row < 0 || row >= rect.height) return 0;
|
|
89
|
+
const y = rect.y + row;
|
|
90
|
+
let used = 0;
|
|
91
|
+
for (const { segment } of segmenter.segment(text)) {
|
|
92
|
+
const w = Math.min(2, stringWidth(segment));
|
|
93
|
+
if (w === 0) continue;
|
|
94
|
+
if (used + w > rect.width) {
|
|
95
|
+
if (used < rect.width) {
|
|
96
|
+
this.set(rect.x + used, y, styled(" ", 1, style));
|
|
97
|
+
used += 1;
|
|
98
|
+
}
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
this.set(rect.x + used, y, styled(segment, w, style));
|
|
102
|
+
if (w === 2) this.set(rect.x + used + 1, y, CONTINUATION_CELL);
|
|
103
|
+
used += w;
|
|
104
|
+
}
|
|
105
|
+
return used;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Copies a source screen into a rectangle, top-left aligned and clipped to the
|
|
109
|
+
* rectangle, the frame and the source. A wide character cut by the clip edge, or
|
|
110
|
+
* whose second half is missing, becomes a blank.
|
|
111
|
+
*/
|
|
112
|
+
blit(source, rect) {
|
|
113
|
+
const r = this.clip(rect);
|
|
114
|
+
const w = Math.min(r.width, source.cols);
|
|
115
|
+
const h = Math.min(r.height, source.rows);
|
|
116
|
+
for (let dy = 0; dy < h; dy++) {
|
|
117
|
+
for (let dx = 0; dx < w; dx++) {
|
|
118
|
+
let cell = source.cell(dx, dy) ?? BLANK_CELL;
|
|
119
|
+
if (cell.width === 2 && dx + 1 >= w) cell = BLANK_CELL;
|
|
120
|
+
else if (cell.width === 0 && dx === 0) cell = BLANK_CELL;
|
|
121
|
+
this.cells[(r.y + dy) * this.cols + r.x + dx] = cell;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const c = source.cursor;
|
|
125
|
+
const cx = rect.x + c.x;
|
|
126
|
+
const cy = rect.y + c.y;
|
|
127
|
+
const inside = cx >= r.x && cx < r.x + w && cy >= r.y && cy < r.y + h;
|
|
128
|
+
this.cursor = { x: cx, y: cy, visible: c.visible && inside };
|
|
129
|
+
}
|
|
130
|
+
/** Places the cursor explicitly (for example on a sidebar input row). */
|
|
131
|
+
setCursor(cursor) {
|
|
132
|
+
this.cursor = cursor;
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
function styled(ch, width, style) {
|
|
136
|
+
if (ch === " " && style.fg === void 0 && style.bg === void 0 && !style.attrs)
|
|
137
|
+
return BLANK_CELL;
|
|
138
|
+
return { ch, width, fg: style.fg ?? -1, bg: style.bg ?? -1, attrs: style.attrs ?? 0 };
|
|
139
|
+
}
|
|
140
|
+
__name(styled, "styled");
|
|
141
|
+
|
|
142
|
+
// src/terminal/host/writer.ts
|
|
143
|
+
var SYNC_BEGIN = "\x1B[?2026h";
|
|
144
|
+
var SYNC_END = "\x1B[?2026l";
|
|
145
|
+
var HIDE_CURSOR = "\x1B[?25l";
|
|
146
|
+
var SHOW_CURSOR = "\x1B[?25h";
|
|
147
|
+
var DiffWriter = class {
|
|
148
|
+
static {
|
|
149
|
+
__name(this, "DiffWriter");
|
|
150
|
+
}
|
|
151
|
+
previous;
|
|
152
|
+
previousCols = 0;
|
|
153
|
+
previousRows = 0;
|
|
154
|
+
cursor;
|
|
155
|
+
/** Forget what the terminal shows; the next render repaints every cell. */
|
|
156
|
+
invalidate() {
|
|
157
|
+
this.previous = void 0;
|
|
158
|
+
this.cursor = void 0;
|
|
159
|
+
}
|
|
160
|
+
/** The bytes that bring the terminal from the previous frame to this one. Empty when nothing changed. */
|
|
161
|
+
render(frame) {
|
|
162
|
+
const full = this.previous === void 0 || this.previousCols !== frame.cols || this.previousRows !== frame.rows;
|
|
163
|
+
let body = full ? "\x1B[0m\x1B[2J" : "";
|
|
164
|
+
let sgrFg = -1;
|
|
165
|
+
let sgrBg = -1;
|
|
166
|
+
let sgrAttrs = 0;
|
|
167
|
+
let styleKnown = false;
|
|
168
|
+
const prev = full ? void 0 : this.previous;
|
|
169
|
+
for (let y = 0; y < frame.rows; y++) {
|
|
170
|
+
let runEnd = -1;
|
|
171
|
+
for (let x = 0; x < frame.cols; x++) {
|
|
172
|
+
const cell = frame.cells[y * frame.cols + x];
|
|
173
|
+
if (cell.width === 0) continue;
|
|
174
|
+
const before = prev?.[y * frame.cols + x];
|
|
175
|
+
const second = cell.width === 2 ? frame.cells[y * frame.cols + x + 1] : void 0;
|
|
176
|
+
const beforeSecond = cell.width === 2 ? prev?.[y * frame.cols + x + 1] : void 0;
|
|
177
|
+
const unchanged = before !== void 0 && sameCell(before, cell) && (second === void 0 || beforeSecond !== void 0 && sameCell(beforeSecond, second));
|
|
178
|
+
if (unchanged) {
|
|
179
|
+
if (cell.width === 2) x += 1;
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
if (full && cell.ch === " " && cell.fg === -1 && cell.bg === -1 && cell.attrs === 0)
|
|
183
|
+
continue;
|
|
184
|
+
if (runEnd !== x) body += `\x1B[${y + 1};${x + 1}H`;
|
|
185
|
+
if (!styleKnown || cell.fg !== sgrFg || cell.bg !== sgrBg || cell.attrs !== sgrAttrs) {
|
|
186
|
+
body += sgr(cell.fg, cell.bg, cell.attrs);
|
|
187
|
+
sgrFg = cell.fg;
|
|
188
|
+
sgrBg = cell.bg;
|
|
189
|
+
sgrAttrs = cell.attrs;
|
|
190
|
+
styleKnown = true;
|
|
191
|
+
}
|
|
192
|
+
body += cell.ch;
|
|
193
|
+
runEnd = x + cell.width;
|
|
194
|
+
if (cell.width === 2) x += 1;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const c = frame.cursor;
|
|
198
|
+
const cursorChanged = full || this.cursor === void 0 || this.cursor.x !== c.x || this.cursor.y !== c.y || this.cursor.visible !== c.visible;
|
|
199
|
+
const wrote = body.length > 0;
|
|
200
|
+
let out = "";
|
|
201
|
+
if (wrote || cursorChanged) {
|
|
202
|
+
out = HIDE_CURSOR + body + (styleKnown ? "\x1B[0m" : "");
|
|
203
|
+
if (c.visible) out += `\x1B[${c.y + 1};${c.x + 1}H${SHOW_CURSOR}`;
|
|
204
|
+
if (wrote) out = SYNC_BEGIN + out + SYNC_END;
|
|
205
|
+
}
|
|
206
|
+
this.previous = frame.cells.slice();
|
|
207
|
+
this.previousCols = frame.cols;
|
|
208
|
+
this.previousRows = frame.rows;
|
|
209
|
+
this.cursor = { ...c };
|
|
210
|
+
return out;
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
// src/spaces/git.ts
|
|
215
|
+
import { execFile } from "node:child_process";
|
|
216
|
+
var GIT_TIMEOUT_MS = 2e3;
|
|
217
|
+
function run(cwd, args) {
|
|
218
|
+
return new Promise((resolve2) => {
|
|
219
|
+
try {
|
|
220
|
+
execFile(
|
|
221
|
+
"git",
|
|
222
|
+
[...args],
|
|
223
|
+
{
|
|
224
|
+
cwd,
|
|
225
|
+
timeout: GIT_TIMEOUT_MS,
|
|
226
|
+
maxBuffer: 64 * 1024,
|
|
227
|
+
windowsHide: true,
|
|
228
|
+
// Reading must never take the index lock a person's own git command wants.
|
|
229
|
+
env: { ...process.env, GIT_OPTIONAL_LOCKS: "0" }
|
|
230
|
+
},
|
|
231
|
+
(error, stdout) => resolve2(error ? void 0 : String(stdout).trim())
|
|
232
|
+
);
|
|
233
|
+
} catch {
|
|
234
|
+
resolve2(void 0);
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
__name(run, "run");
|
|
239
|
+
var gitLookup = /* @__PURE__ */ __name(async (cwd) => {
|
|
240
|
+
const branch = await run(cwd, ["symbolic-ref", "--short", "-q", "HEAD"]) || await run(cwd, ["rev-parse", "--short", "HEAD"]);
|
|
241
|
+
if (!branch) return void 0;
|
|
242
|
+
const counts = await run(cwd, ["rev-list", "--left-right", "--count", "HEAD...@{upstream}"]);
|
|
243
|
+
const match = counts ? /^(\d+)\s+(\d+)$/u.exec(counts) : null;
|
|
244
|
+
return {
|
|
245
|
+
branch,
|
|
246
|
+
ahead: match ? Number(match[1]) : 0,
|
|
247
|
+
behind: match ? Number(match[2]) : 0
|
|
248
|
+
};
|
|
249
|
+
}, "gitLookup");
|
|
250
|
+
var GitCache = class {
|
|
251
|
+
constructor(lookup, changed, now) {
|
|
252
|
+
this.lookup = lookup;
|
|
253
|
+
this.changed = changed;
|
|
254
|
+
this.now = now;
|
|
255
|
+
}
|
|
256
|
+
lookup;
|
|
257
|
+
changed;
|
|
258
|
+
now;
|
|
259
|
+
static {
|
|
260
|
+
__name(this, "GitCache");
|
|
261
|
+
}
|
|
262
|
+
known = /* @__PURE__ */ new Map();
|
|
263
|
+
started = /* @__PURE__ */ new Map();
|
|
264
|
+
running = /* @__PURE__ */ new Set();
|
|
265
|
+
get(cwd) {
|
|
266
|
+
return this.known.get(cwd);
|
|
267
|
+
}
|
|
268
|
+
/** Looks again at a folder unless a lookup is running or one started within `within` ms. */
|
|
269
|
+
refresh(cwd, within3 = 0) {
|
|
270
|
+
if (this.running.has(cwd)) return;
|
|
271
|
+
const last = this.started.get(cwd);
|
|
272
|
+
const at = this.now();
|
|
273
|
+
if (last !== void 0 && at - last < within3) return;
|
|
274
|
+
this.running.add(cwd);
|
|
275
|
+
this.started.set(cwd, at);
|
|
276
|
+
void this.lookup(cwd).catch(() => void 0).then((status) => {
|
|
277
|
+
this.running.delete(cwd);
|
|
278
|
+
const before = this.known.get(cwd);
|
|
279
|
+
this.known.set(cwd, status);
|
|
280
|
+
if (before?.branch !== status?.branch || before?.ahead !== status?.ahead || before?.behind !== status?.behind)
|
|
281
|
+
this.changed();
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
refreshAll(cwds) {
|
|
285
|
+
for (const cwd of new Set(cwds)) this.refresh(cwd);
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
// src/spaces/status.ts
|
|
290
|
+
var PRIORITY = ["blocked", "done", "working", "idle", "none"];
|
|
291
|
+
function deriveActivity(child, reported) {
|
|
292
|
+
if (child === "none") return "not-started";
|
|
293
|
+
if (child === "exited") return "exited";
|
|
294
|
+
if (reported === void 0) return "starting";
|
|
295
|
+
if (reported === "busy") return "working";
|
|
296
|
+
return reported === "awaiting-permission" ? "needs-approval" : "idle";
|
|
297
|
+
}
|
|
298
|
+
__name(deriveActivity, "deriveActivity");
|
|
299
|
+
function dotFor(activity, unseen) {
|
|
300
|
+
if (activity === "needs-approval") return "blocked";
|
|
301
|
+
if (activity === "exited" || activity === "not-started" || activity === "starting") return "none";
|
|
302
|
+
if (unseen) return "done";
|
|
303
|
+
return activity === "working" ? "working" : "idle";
|
|
304
|
+
}
|
|
305
|
+
__name(dotFor, "dotFor");
|
|
306
|
+
function aggregateDot(dots) {
|
|
307
|
+
for (const dot of PRIORITY) if (dots.includes(dot)) return dot;
|
|
308
|
+
return "none";
|
|
309
|
+
}
|
|
310
|
+
__name(aggregateDot, "aggregateDot");
|
|
311
|
+
function spaceNote(dot) {
|
|
312
|
+
if (dot === "blocked") return "needs approval";
|
|
313
|
+
if (dot === "done") return "finished, not seen";
|
|
314
|
+
return void 0;
|
|
315
|
+
}
|
|
316
|
+
__name(spaceNote, "spaceNote");
|
|
317
|
+
function limitedNote(until, now) {
|
|
318
|
+
if (until === void 0) return "may be limited";
|
|
319
|
+
return `limited until ${formatResetTime(until, now)}`;
|
|
320
|
+
}
|
|
321
|
+
__name(limitedNote, "limitedNote");
|
|
322
|
+
|
|
323
|
+
// src/spaces/tiling.ts
|
|
324
|
+
var MIN_RATIO = 0.1;
|
|
325
|
+
var MAX_RATIO = 0.9;
|
|
326
|
+
var MIN_PANE_WIDTH = 12;
|
|
327
|
+
var MIN_PANE_HEIGHT = 5;
|
|
328
|
+
var RESIZE_STEP = 0.05;
|
|
329
|
+
function leaf(entry) {
|
|
330
|
+
return { kind: "leaf", entry };
|
|
331
|
+
}
|
|
332
|
+
__name(leaf, "leaf");
|
|
333
|
+
function clampRatio(ratio) {
|
|
334
|
+
if (!Number.isFinite(ratio)) return 0.5;
|
|
335
|
+
return Math.max(MIN_RATIO, Math.min(MAX_RATIO, ratio));
|
|
336
|
+
}
|
|
337
|
+
__name(clampRatio, "clampRatio");
|
|
338
|
+
function leaves(node) {
|
|
339
|
+
return node.kind === "leaf" ? [node.entry] : [...leaves(node.a), ...leaves(node.b)];
|
|
340
|
+
}
|
|
341
|
+
__name(leaves, "leaves");
|
|
342
|
+
function contains(node, entry) {
|
|
343
|
+
return node.kind === "leaf" ? node.entry === entry : contains(node.a, entry) || contains(node.b, entry);
|
|
344
|
+
}
|
|
345
|
+
__name(contains, "contains");
|
|
346
|
+
function splitLeaf(node, target, created, dir) {
|
|
347
|
+
if (node.kind === "leaf")
|
|
348
|
+
return node.entry === target ? { kind: "split", dir, ratio: 0.5, a: node, b: leaf(created) } : node;
|
|
349
|
+
node.a = splitLeaf(node.a, target, created, dir);
|
|
350
|
+
node.b = splitLeaf(node.b, target, created, dir);
|
|
351
|
+
return node;
|
|
352
|
+
}
|
|
353
|
+
__name(splitLeaf, "splitLeaf");
|
|
354
|
+
function removeLeaf(node, entry) {
|
|
355
|
+
if (node.kind === "leaf")
|
|
356
|
+
return node.entry === entry ? { root: void 0, next: void 0 } : { root: node, next: void 0 };
|
|
357
|
+
if (node.a.kind === "leaf" && node.a.entry === entry)
|
|
358
|
+
return { root: node.b, next: leaves(node.b)[0] };
|
|
359
|
+
if (node.b.kind === "leaf" && node.b.entry === entry)
|
|
360
|
+
return { root: node.a, next: leaves(node.a).at(-1) };
|
|
361
|
+
if (contains(node.a, entry)) {
|
|
362
|
+
const inner = removeLeaf(node.a, entry);
|
|
363
|
+
if (inner.root) node.a = inner.root;
|
|
364
|
+
return { root: node, next: inner.next };
|
|
365
|
+
}
|
|
366
|
+
if (contains(node.b, entry)) {
|
|
367
|
+
const inner = removeLeaf(node.b, entry);
|
|
368
|
+
if (inner.root) node.b = inner.root;
|
|
369
|
+
return { root: node, next: inner.next };
|
|
370
|
+
}
|
|
371
|
+
return { root: node, next: void 0 };
|
|
372
|
+
}
|
|
373
|
+
__name(removeLeaf, "removeLeaf");
|
|
374
|
+
function swapLeaves(node, first, second) {
|
|
375
|
+
if (node.kind === "leaf") {
|
|
376
|
+
if (node.entry === first) node.entry = second;
|
|
377
|
+
else if (node.entry === second) node.entry = first;
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
swapLeaves(node.a, first, second);
|
|
381
|
+
swapLeaves(node.b, first, second);
|
|
382
|
+
}
|
|
383
|
+
__name(swapLeaves, "swapLeaves");
|
|
384
|
+
function resizeAt(node, entry, axis, forward, step = RESIZE_STEP) {
|
|
385
|
+
const chain = [];
|
|
386
|
+
for (let at = node; at.kind === "split"; ) {
|
|
387
|
+
const inA = contains(at.a, entry);
|
|
388
|
+
if (!inA && !contains(at.b, entry)) return false;
|
|
389
|
+
if (at.dir === axis) chain.unshift({ split: at, inA });
|
|
390
|
+
at = inA ? at.a : at.b;
|
|
391
|
+
}
|
|
392
|
+
const found = chain.find((c) => c.inA === forward) ?? chain.find((c) => c.inA !== forward);
|
|
393
|
+
if (!found) return false;
|
|
394
|
+
const next = clampRatio(found.split.ratio + (forward ? step : -step));
|
|
395
|
+
if (next === found.split.ratio) return false;
|
|
396
|
+
found.split.ratio = next;
|
|
397
|
+
return true;
|
|
398
|
+
}
|
|
399
|
+
__name(resizeAt, "resizeAt");
|
|
400
|
+
function shrink(rect) {
|
|
401
|
+
return {
|
|
402
|
+
x: rect.x + 1,
|
|
403
|
+
y: rect.y + 1,
|
|
404
|
+
width: Math.max(1, rect.width - 2),
|
|
405
|
+
height: Math.max(1, rect.height - 2)
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
__name(shrink, "shrink");
|
|
409
|
+
function firstShare(total, ratio, least) {
|
|
410
|
+
const low = Math.min(least, Math.floor(total / 2));
|
|
411
|
+
return Math.max(low, Math.min(total - low, Math.round(total * ratio)));
|
|
412
|
+
}
|
|
413
|
+
__name(firstShare, "firstShare");
|
|
414
|
+
function place(root, area) {
|
|
415
|
+
const count = leaves(root).length;
|
|
416
|
+
const bordered = count > 1;
|
|
417
|
+
const panes = [];
|
|
418
|
+
const dividers = [];
|
|
419
|
+
const walk = /* @__PURE__ */ __name((node, rect) => {
|
|
420
|
+
if (node.kind === "leaf") {
|
|
421
|
+
panes.push({
|
|
422
|
+
entry: node.entry,
|
|
423
|
+
outer: rect,
|
|
424
|
+
inner: bordered ? shrink(rect) : rect
|
|
425
|
+
});
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
if (node.dir === "side") {
|
|
429
|
+
const first = firstShare(rect.width, node.ratio, MIN_PANE_WIDTH);
|
|
430
|
+
dividers.push({ split: node, area: rect, at: rect.x + first });
|
|
431
|
+
walk(node.a, { ...rect, width: first });
|
|
432
|
+
walk(node.b, { ...rect, x: rect.x + first, width: rect.width - first });
|
|
433
|
+
} else {
|
|
434
|
+
const first = firstShare(rect.height, node.ratio, MIN_PANE_HEIGHT);
|
|
435
|
+
dividers.push({ split: node, area: rect, at: rect.y + first });
|
|
436
|
+
walk(node.a, { ...rect, height: first });
|
|
437
|
+
walk(node.b, { ...rect, y: rect.y + first, height: rect.height - first });
|
|
438
|
+
}
|
|
439
|
+
}, "walk");
|
|
440
|
+
walk(root, area);
|
|
441
|
+
return { panes, dividers, bordered };
|
|
442
|
+
}
|
|
443
|
+
__name(place, "place");
|
|
444
|
+
function ratioFor(divider, at) {
|
|
445
|
+
const total = divider.split.dir === "side" ? divider.area.width : divider.area.height;
|
|
446
|
+
const start = divider.split.dir === "side" ? divider.area.x : divider.area.y;
|
|
447
|
+
return clampRatio((at - start) / total);
|
|
448
|
+
}
|
|
449
|
+
__name(ratioFor, "ratioFor");
|
|
450
|
+
function dividerAt(dividers, x, y) {
|
|
451
|
+
return dividers.find((d) => {
|
|
452
|
+
const { area } = d;
|
|
453
|
+
if (d.split.dir === "side")
|
|
454
|
+
return (x === d.at - 1 || x === d.at) && y >= area.y && y < area.y + area.height;
|
|
455
|
+
return (y === d.at - 1 || y === d.at) && x >= area.x && x < area.x + area.width;
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
__name(dividerAt, "dividerAt");
|
|
459
|
+
function paneAt(panes, x, y) {
|
|
460
|
+
return panes.find(
|
|
461
|
+
({ outer }) => x >= outer.x && x < outer.x + outer.width && y >= outer.y && y < outer.y + outer.height
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
__name(paneAt, "paneAt");
|
|
465
|
+
function overlap(aStart, aLen, bStart, bLen) {
|
|
466
|
+
return Math.max(0, Math.min(aStart + aLen, bStart + bLen) - Math.max(aStart, bStart));
|
|
467
|
+
}
|
|
468
|
+
__name(overlap, "overlap");
|
|
469
|
+
function neighbour(panes, from, direction) {
|
|
470
|
+
const origin = panes.find((p) => p.entry === from)?.outer;
|
|
471
|
+
if (!origin) return void 0;
|
|
472
|
+
const horizontal = direction === "left" || direction === "right";
|
|
473
|
+
const middle = horizontal ? origin.y + origin.height / 2 : origin.x + origin.width / 2;
|
|
474
|
+
let best;
|
|
475
|
+
for (const { entry, outer } of panes) {
|
|
476
|
+
if (entry === from) continue;
|
|
477
|
+
let gap;
|
|
478
|
+
if (direction === "left") gap = origin.x - (outer.x + outer.width);
|
|
479
|
+
else if (direction === "right") gap = outer.x - (origin.x + origin.width);
|
|
480
|
+
else if (direction === "up") gap = origin.y - (outer.y + outer.height);
|
|
481
|
+
else gap = outer.y - (origin.y + origin.height);
|
|
482
|
+
if (gap < 0) continue;
|
|
483
|
+
const across = horizontal ? overlap(origin.y, origin.height, outer.y, outer.height) : overlap(origin.x, origin.width, outer.x, outer.width);
|
|
484
|
+
if (across === 0) continue;
|
|
485
|
+
const start = horizontal ? outer.y : outer.x;
|
|
486
|
+
const length = horizontal ? outer.height : outer.width;
|
|
487
|
+
const covers = middle >= start && middle < start + length;
|
|
488
|
+
if (!best || gap < best.gap || gap === best.gap && (Number(covers) > Number(best.covers) || covers === best.covers && across > best.across))
|
|
489
|
+
best = { entry, gap, across, covers };
|
|
490
|
+
}
|
|
491
|
+
return best?.entry;
|
|
492
|
+
}
|
|
493
|
+
__name(neighbour, "neighbour");
|
|
494
|
+
function placeTab(tab, area) {
|
|
495
|
+
if (tab.zoomed && leaves(tab.root).length > 1)
|
|
496
|
+
return {
|
|
497
|
+
panes: [{ entry: tab.focus, outer: area, inner: shrink(area) }],
|
|
498
|
+
dividers: [],
|
|
499
|
+
bordered: true
|
|
500
|
+
};
|
|
501
|
+
return place(tab.root, area);
|
|
502
|
+
}
|
|
503
|
+
__name(placeTab, "placeTab");
|
|
504
|
+
|
|
505
|
+
// src/spaces/goto.ts
|
|
506
|
+
function gotoRows(roster) {
|
|
507
|
+
const rows = [];
|
|
508
|
+
for (const space of roster.spaces) {
|
|
509
|
+
rows.push({
|
|
510
|
+
depth: 0,
|
|
511
|
+
text: space.name,
|
|
512
|
+
dot: roster.spaceDot(space),
|
|
513
|
+
target: { kind: "space", space }
|
|
514
|
+
});
|
|
515
|
+
space.tabs.forEach((tab, i) => {
|
|
516
|
+
const panes = leaves(tab.root);
|
|
517
|
+
rows.push({
|
|
518
|
+
depth: 1,
|
|
519
|
+
text: tab.name ?? `tab ${i + 1}`,
|
|
520
|
+
dot: aggregateDot(panes.map((p) => p.dot())),
|
|
521
|
+
target: { kind: "tab", space, tab }
|
|
522
|
+
});
|
|
523
|
+
for (const entry of panes)
|
|
524
|
+
rows.push({
|
|
525
|
+
depth: 2,
|
|
526
|
+
text: entry.account ? `${entry.label} \xB7 ${entry.account}` : entry.label,
|
|
527
|
+
dot: entry.dot(),
|
|
528
|
+
target: { kind: "pane", entry }
|
|
529
|
+
});
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
return rows;
|
|
533
|
+
}
|
|
534
|
+
__name(gotoRows, "gotoRows");
|
|
535
|
+
function filterGoto(rows, query) {
|
|
536
|
+
const wanted = query.trim().toLowerCase();
|
|
537
|
+
if (wanted === "") return [...rows];
|
|
538
|
+
const own = rows.map((r) => r.text.toLowerCase().includes(wanted));
|
|
539
|
+
const keep = rows.map(() => false);
|
|
540
|
+
const chain = [];
|
|
541
|
+
rows.forEach((row, i) => {
|
|
542
|
+
while (chain.length > row.depth) chain.pop();
|
|
543
|
+
chain[row.depth] = i;
|
|
544
|
+
const underMatch = chain.slice(0, row.depth).some((at) => own[at]);
|
|
545
|
+
if (own[i] || underMatch) {
|
|
546
|
+
keep[i] = true;
|
|
547
|
+
for (const at of chain.slice(0, row.depth)) keep[at] = true;
|
|
548
|
+
}
|
|
549
|
+
});
|
|
550
|
+
return rows.filter((_, i) => keep[i]);
|
|
551
|
+
}
|
|
552
|
+
__name(filterGoto, "filterGoto");
|
|
553
|
+
function currentRow(rows, entry) {
|
|
554
|
+
const at = rows.findIndex((r) => r.target.kind === "pane" && r.target.entry === entry);
|
|
555
|
+
return Math.max(0, at);
|
|
556
|
+
}
|
|
557
|
+
__name(currentRow, "currentRow");
|
|
558
|
+
|
|
559
|
+
// src/spaces/input.ts
|
|
560
|
+
var ESC = String.fromCharCode(27);
|
|
561
|
+
var ARROW = new RegExp(`^${ESC}[[O]([ABCD])`, "u");
|
|
562
|
+
var CSI = new RegExp(`^${ESC}\\[[0-9;?]*[ -/]*[@-~]`, "u");
|
|
563
|
+
var MOUSE = new RegExp(`^${ESC}\\[<(\\d+);(\\d+);(\\d+)([Mm])`, "u");
|
|
564
|
+
var MOUSE_PARTIAL = new RegExp(`${ESC}(\\[(<[0-9;]*)?)?$`, "u");
|
|
565
|
+
var PASTE_BEGIN = "\x1B[200~";
|
|
566
|
+
var PASTE_END = "\x1B[201~";
|
|
567
|
+
var CLEAR = "";
|
|
568
|
+
var MODE_KEYS = {
|
|
569
|
+
r: "resize",
|
|
570
|
+
w: "navigate"
|
|
571
|
+
};
|
|
572
|
+
var InputRouter = class {
|
|
573
|
+
constructor(prefix) {
|
|
574
|
+
this.prefix = prefix;
|
|
575
|
+
}
|
|
576
|
+
prefix;
|
|
577
|
+
static {
|
|
578
|
+
__name(this, "InputRouter");
|
|
579
|
+
}
|
|
580
|
+
mode = "terminal";
|
|
581
|
+
pasting = false;
|
|
582
|
+
carry = "";
|
|
583
|
+
capturing = false;
|
|
584
|
+
get current() {
|
|
585
|
+
return this.mode;
|
|
586
|
+
}
|
|
587
|
+
/** Hands the keyboard back to the session. */
|
|
588
|
+
focus() {
|
|
589
|
+
this.mode = "terminal";
|
|
590
|
+
}
|
|
591
|
+
/** Puts the keyboard on the sidebar: arrows move through the sessions. */
|
|
592
|
+
enterNavigate() {
|
|
593
|
+
this.mode = "navigate";
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* While on, every key goes to the host as text or a key (a name being typed, an
|
|
597
|
+
* answer to a question): escape and enter come through as keys, and the
|
|
598
|
+
* prefix is just a control byte nobody types.
|
|
599
|
+
*/
|
|
600
|
+
capture(on) {
|
|
601
|
+
this.capturing = on;
|
|
602
|
+
}
|
|
603
|
+
feed(input) {
|
|
604
|
+
let chunk = this.carry + input;
|
|
605
|
+
this.carry = "";
|
|
606
|
+
const cut = this.pasting ? null : MOUSE_PARTIAL.exec(chunk);
|
|
607
|
+
if (cut?.[2] !== void 0) {
|
|
608
|
+
this.carry = cut[0];
|
|
609
|
+
chunk = chunk.slice(0, cut.index);
|
|
610
|
+
}
|
|
611
|
+
const actions = [];
|
|
612
|
+
let pending = "";
|
|
613
|
+
const flush = /* @__PURE__ */ __name(() => {
|
|
614
|
+
if (pending !== "") actions.push({ type: "write", data: pending });
|
|
615
|
+
pending = "";
|
|
616
|
+
}, "flush");
|
|
617
|
+
const enter = /* @__PURE__ */ __name((mode) => {
|
|
618
|
+
this.mode = mode;
|
|
619
|
+
actions.push({ type: "mode", mode });
|
|
620
|
+
}, "enter");
|
|
621
|
+
let i = 0;
|
|
622
|
+
while (i < chunk.length) {
|
|
623
|
+
if (this.mode === "terminal" && !this.capturing) {
|
|
624
|
+
if (this.pasting) {
|
|
625
|
+
const end = chunk.indexOf(PASTE_END, i);
|
|
626
|
+
if (end < 0) {
|
|
627
|
+
pending += chunk.slice(i);
|
|
628
|
+
i = chunk.length;
|
|
629
|
+
} else {
|
|
630
|
+
pending += chunk.slice(i, end + PASTE_END.length);
|
|
631
|
+
i = end + PASTE_END.length;
|
|
632
|
+
this.pasting = false;
|
|
633
|
+
}
|
|
634
|
+
continue;
|
|
635
|
+
}
|
|
636
|
+
if (chunk.startsWith(PASTE_BEGIN, i)) {
|
|
637
|
+
pending += PASTE_BEGIN;
|
|
638
|
+
i += PASTE_BEGIN.length;
|
|
639
|
+
this.pasting = true;
|
|
640
|
+
continue;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
const mouse = readMouse(chunk, i);
|
|
644
|
+
if (mouse) {
|
|
645
|
+
flush();
|
|
646
|
+
actions.push({ type: "mouse", mouse: mouse.event });
|
|
647
|
+
i += mouse.length;
|
|
648
|
+
continue;
|
|
649
|
+
}
|
|
650
|
+
if (this.mode === "terminal" && !this.capturing) {
|
|
651
|
+
const ch = chunk[i];
|
|
652
|
+
if (ch === this.prefix.byte) {
|
|
653
|
+
flush();
|
|
654
|
+
enter("prefix");
|
|
655
|
+
} else pending += ch;
|
|
656
|
+
i += 1;
|
|
657
|
+
continue;
|
|
658
|
+
}
|
|
659
|
+
const key = readKey(chunk.slice(i));
|
|
660
|
+
i += key.length;
|
|
661
|
+
if (this.capturing) {
|
|
662
|
+
if (key.nav.kind === "char" && (key.nav.char === "" || key.nav.char < " " && key.nav.char !== CLEAR))
|
|
663
|
+
continue;
|
|
664
|
+
actions.push({ type: "nav", key: key.nav, from: "text" });
|
|
665
|
+
continue;
|
|
666
|
+
}
|
|
667
|
+
if (key.text === this.prefix.byte && this.mode === "navigate") {
|
|
668
|
+
enter("prefix");
|
|
669
|
+
continue;
|
|
670
|
+
}
|
|
671
|
+
if (key.text === this.prefix.byte) {
|
|
672
|
+
const literal = this.mode === "prefix";
|
|
673
|
+
enter("terminal");
|
|
674
|
+
if (literal) actions.push({ type: "write", data: this.prefix.byte });
|
|
675
|
+
continue;
|
|
676
|
+
}
|
|
677
|
+
if (key.nav.kind === "escape") {
|
|
678
|
+
enter("terminal");
|
|
679
|
+
continue;
|
|
680
|
+
}
|
|
681
|
+
if (this.mode === "prefix") {
|
|
682
|
+
const started = key.nav.kind === "char" ? MODE_KEYS[key.nav.char] : void 0;
|
|
683
|
+
enter(started ?? "terminal");
|
|
684
|
+
actions.push({ type: "nav", key: key.nav, from: "prefix" });
|
|
685
|
+
continue;
|
|
686
|
+
}
|
|
687
|
+
if (key.nav.kind === "enter") {
|
|
688
|
+
enter("terminal");
|
|
689
|
+
continue;
|
|
690
|
+
}
|
|
691
|
+
actions.push({
|
|
692
|
+
type: "nav",
|
|
693
|
+
key: key.nav,
|
|
694
|
+
from: this.mode
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
flush();
|
|
698
|
+
return actions;
|
|
699
|
+
}
|
|
700
|
+
};
|
|
701
|
+
function readMouse(chunk, at) {
|
|
702
|
+
if (chunk[at] !== ESC) return void 0;
|
|
703
|
+
const match = MOUSE.exec(chunk.slice(at));
|
|
704
|
+
if (!match) return void 0;
|
|
705
|
+
const code = Number(match[1]);
|
|
706
|
+
const x = Number(match[2]) - 1;
|
|
707
|
+
const y = Number(match[3]) - 1;
|
|
708
|
+
const released = match[4] === "m";
|
|
709
|
+
let kind = "other";
|
|
710
|
+
if (code & 64) kind = (code & 3) === 0 ? "wheel-up" : (code & 3) === 1 ? "wheel-down" : "other";
|
|
711
|
+
else if ((code & 3) === 0) kind = code & 32 ? "drag" : released ? "release" : "press";
|
|
712
|
+
else if ((code & 3) === 2 && !(code & 32) && !released) kind = "context";
|
|
713
|
+
return { length: match[0].length, event: { kind, x, y } };
|
|
714
|
+
}
|
|
715
|
+
__name(readMouse, "readMouse");
|
|
716
|
+
function readKey(text) {
|
|
717
|
+
const first = text[0];
|
|
718
|
+
if (first === "\x1B") {
|
|
719
|
+
const arrow = ARROW.exec(text);
|
|
720
|
+
if (arrow) {
|
|
721
|
+
const code2 = arrow[1];
|
|
722
|
+
const nav = code2 === "A" ? { kind: "up" } : code2 === "B" ? { kind: "down" } : code2 === "C" ? { kind: "right" } : { kind: "left" };
|
|
723
|
+
return { length: arrow[0].length, text: arrow[0], nav };
|
|
724
|
+
}
|
|
725
|
+
if (text.startsWith("\x1B[Z")) return { length: 3, text: "\x1B[Z", nav: { kind: "backtab" } };
|
|
726
|
+
const sequence = CSI.exec(text);
|
|
727
|
+
if (sequence)
|
|
728
|
+
return {
|
|
729
|
+
length: sequence[0].length,
|
|
730
|
+
text: sequence[0],
|
|
731
|
+
nav: { kind: "char", char: "" }
|
|
732
|
+
};
|
|
733
|
+
return { length: 1, text: first, nav: { kind: "escape" } };
|
|
734
|
+
}
|
|
735
|
+
if (first === "\x7F" || first === "\b")
|
|
736
|
+
return { length: 1, text: first, nav: { kind: "backspace" } };
|
|
737
|
+
if (first === "\r" || first === "\n") return { length: 1, text: first, nav: { kind: "enter" } };
|
|
738
|
+
if (first === " ") return { length: 1, text: first, nav: { kind: "tab" } };
|
|
739
|
+
const code = first.codePointAt(0);
|
|
740
|
+
const length = code > 65535 ? 2 : 1;
|
|
741
|
+
return {
|
|
742
|
+
length,
|
|
743
|
+
text: text.slice(0, length),
|
|
744
|
+
nav: { kind: "char", char: text.slice(0, length) }
|
|
745
|
+
};
|
|
746
|
+
}
|
|
747
|
+
__name(readKey, "readKey");
|
|
748
|
+
|
|
749
|
+
// src/spaces/keymap.ts
|
|
750
|
+
var DIGITS = ["1", "2", "3", "4", "5", "6", "7", "8", "9"];
|
|
751
|
+
var BINDINGS = [
|
|
752
|
+
{ keys: ["?"], action: "help", group: "General", label: "keybinds" },
|
|
753
|
+
{ keys: ["g"], action: "goto", group: "General", label: "go to a space, tab or pane" },
|
|
754
|
+
{ keys: ["s"], action: "menu", group: "General", label: "menu" },
|
|
755
|
+
{ keys: ["q"], action: "quit", group: "General", label: "quit" },
|
|
756
|
+
{ keys: ["N"], action: "new-space", group: "Spaces", label: "new space" },
|
|
757
|
+
{ keys: ["O"], action: "open-folder", group: "Spaces", label: "open a folder as a space" },
|
|
758
|
+
{ keys: ["W"], action: "rename-space", group: "Spaces", label: "rename space" },
|
|
759
|
+
{ keys: ["D"], action: "close-space", group: "Spaces", label: "close space" },
|
|
760
|
+
{ keys: ["w"], action: "space-mode", group: "Spaces", label: "move through the spaces" },
|
|
761
|
+
{ keys: ["b"], action: "sidebar", group: "Spaces", label: "toggle sidebar" },
|
|
762
|
+
{ keys: ["c"], action: "new-tab", group: "Tabs", label: "new tab" },
|
|
763
|
+
{ keys: ["T"], action: "rename-tab", group: "Tabs", label: "rename tab" },
|
|
764
|
+
{ keys: ["X"], action: "close-tab", group: "Tabs", label: "close tab" },
|
|
765
|
+
{ keys: ["p"], action: "prev-tab", group: "Tabs", label: "previous tab" },
|
|
766
|
+
{ keys: ["n"], action: "next-tab", group: "Tabs", label: "next tab" },
|
|
767
|
+
{ keys: DIGITS, action: "tab-number", group: "Tabs", label: "tab by number" },
|
|
768
|
+
{ keys: ["v"], action: "split-side", group: "Panes", label: "split side by side" },
|
|
769
|
+
{ keys: ["-"], action: "split-stack", group: "Panes", label: "split top over bottom" },
|
|
770
|
+
{ keys: ["h"], action: "focus-left", group: "Panes", label: "focus left" },
|
|
771
|
+
{ keys: ["j"], action: "focus-down", group: "Panes", label: "focus down" },
|
|
772
|
+
{ keys: ["k"], action: "focus-up", group: "Panes", label: "focus up" },
|
|
773
|
+
{ keys: ["l"], action: "focus-right", group: "Panes", label: "focus right" },
|
|
774
|
+
{ keys: ["H"], action: "swap-left", group: "Panes", label: "swap pane left" },
|
|
775
|
+
{ keys: ["J"], action: "swap-down", group: "Panes", label: "swap pane down" },
|
|
776
|
+
{ keys: ["K"], action: "swap-up", group: "Panes", label: "swap pane up" },
|
|
777
|
+
{ keys: ["L"], action: "swap-right", group: "Panes", label: "swap pane right" },
|
|
778
|
+
{ keys: ["tab"], action: "next-pane", group: "Panes", label: "next pane" },
|
|
779
|
+
{ keys: ["backtab"], action: "prev-pane", group: "Panes", label: "previous pane" },
|
|
780
|
+
{ keys: ["x"], action: "close-pane", group: "Panes", label: "close pane" },
|
|
781
|
+
{ keys: ["z"], action: "zoom", group: "Panes", label: "zoom pane" },
|
|
782
|
+
{ keys: ["r"], action: "resize-mode", group: "Panes", label: "resize mode" },
|
|
783
|
+
{ keys: ["P"], action: "rename-pane", group: "Panes", label: "rename pane" }
|
|
784
|
+
];
|
|
785
|
+
function keyName(key) {
|
|
786
|
+
if (key === "backtab") return "shift+tab";
|
|
787
|
+
if (/^[A-Z]$/u.test(key)) return `shift+${key.toLowerCase()}`;
|
|
788
|
+
return key;
|
|
789
|
+
}
|
|
790
|
+
__name(keyName, "keyName");
|
|
791
|
+
function keysText(binding) {
|
|
792
|
+
if (binding.keys === DIGITS) return "1-9";
|
|
793
|
+
return binding.keys.map(keyName).join(" ");
|
|
794
|
+
}
|
|
795
|
+
__name(keysText, "keysText");
|
|
796
|
+
function bindingFor(key) {
|
|
797
|
+
const name = key.kind === "tab" ? "tab" : key.kind === "backtab" ? "backtab" : void 0;
|
|
798
|
+
const wanted = name ?? (key.kind === "char" ? key.char : void 0);
|
|
799
|
+
if (wanted === void 0) return void 0;
|
|
800
|
+
return BINDINGS.find((b) => b.keys.includes(wanted));
|
|
801
|
+
}
|
|
802
|
+
__name(bindingFor, "bindingFor");
|
|
803
|
+
function helpRows(prefixName) {
|
|
804
|
+
const rows = [{ heading: `${prefixName} then a key; twice sends it to the pane` }];
|
|
805
|
+
for (const group of ["General", "Spaces", "Tabs", "Panes"]) {
|
|
806
|
+
rows.push({ heading: group });
|
|
807
|
+
for (const b of BINDINGS)
|
|
808
|
+
if (b.group === group) rows.push({ keys: keysText(b), label: b.label });
|
|
809
|
+
}
|
|
810
|
+
return rows;
|
|
811
|
+
}
|
|
812
|
+
__name(helpRows, "helpRows");
|
|
813
|
+
|
|
814
|
+
// src/spaces/layout.ts
|
|
815
|
+
var SIDEBAR_MIN = 18;
|
|
816
|
+
var SIDEBAR_MAX = 36;
|
|
817
|
+
var SIDEBAR_DEFAULT = 26;
|
|
818
|
+
var RAIL_WIDTH = 4;
|
|
819
|
+
var MAIN_MIN = 40;
|
|
820
|
+
var DEFAULT_SIDEBAR = {
|
|
821
|
+
collapsed: false,
|
|
822
|
+
width: SIDEBAR_DEFAULT
|
|
823
|
+
};
|
|
824
|
+
function clampSidebarWidth(width) {
|
|
825
|
+
if (!Number.isFinite(width)) return SIDEBAR_DEFAULT;
|
|
826
|
+
return Math.max(SIDEBAR_MIN, Math.min(SIDEBAR_MAX, Math.round(width)));
|
|
827
|
+
}
|
|
828
|
+
__name(clampSidebarWidth, "clampSidebarWidth");
|
|
829
|
+
function computeLayout(cols, rows, sidebar = DEFAULT_SIDEBAR) {
|
|
830
|
+
let total = sidebar.collapsed ? RAIL_WIDTH : clampSidebarWidth(sidebar.width);
|
|
831
|
+
let rail = sidebar.collapsed;
|
|
832
|
+
if (!rail && cols - total < MAIN_MIN) {
|
|
833
|
+
rail = true;
|
|
834
|
+
total = RAIL_WIDTH;
|
|
835
|
+
}
|
|
836
|
+
const shown = cols - total >= MAIN_MIN;
|
|
837
|
+
const main = shown ? { x: total, y: 0, width: cols - total, height: rows } : { x: 0, y: 0, width: cols, height: rows };
|
|
838
|
+
const tabBar = { ...main, height: Math.min(1, main.height) };
|
|
839
|
+
const panes = {
|
|
840
|
+
...main,
|
|
841
|
+
y: main.y + 1,
|
|
842
|
+
height: Math.max(1, main.height - 1)
|
|
843
|
+
};
|
|
844
|
+
if (!shown)
|
|
845
|
+
return {
|
|
846
|
+
sidebar: void 0,
|
|
847
|
+
rail: false,
|
|
848
|
+
rule: void 0,
|
|
849
|
+
main,
|
|
850
|
+
tabBar,
|
|
851
|
+
panes
|
|
852
|
+
};
|
|
853
|
+
return {
|
|
854
|
+
sidebar: { x: 0, y: 0, width: total - 1, height: rows },
|
|
855
|
+
rail,
|
|
856
|
+
rule: { x: total - 1, y: 0, width: 1, height: rows },
|
|
857
|
+
main,
|
|
858
|
+
tabBar,
|
|
859
|
+
panes
|
|
860
|
+
};
|
|
861
|
+
}
|
|
862
|
+
__name(computeLayout, "computeLayout");
|
|
863
|
+
|
|
864
|
+
// src/spaces/overlay.ts
|
|
865
|
+
function within(rect, x, y) {
|
|
866
|
+
return x >= rect.x && x < rect.x + rect.width && y >= rect.y && y < rect.y + rect.height;
|
|
867
|
+
}
|
|
868
|
+
__name(within, "within");
|
|
869
|
+
function hitSurface(surface, x, y) {
|
|
870
|
+
for (const b of surface.buttons)
|
|
871
|
+
if (within(b.rect, x, y)) return { kind: "button", action: b.action };
|
|
872
|
+
for (const r of surface.rows) if (within(r.rect, x, y)) return { kind: "row", index: r.index };
|
|
873
|
+
return within(surface.rect, x, y) ? { kind: "inside" } : { kind: "outside" };
|
|
874
|
+
}
|
|
875
|
+
__name(hitSurface, "hitSurface");
|
|
876
|
+
function drawBox(frame, rect, fg, bg) {
|
|
877
|
+
if (rect.width < 2 || rect.height < 2) return;
|
|
878
|
+
const style = { fg, ...bg !== void 0 ? { bg } : {} };
|
|
879
|
+
const right = rect.x + rect.width - 1;
|
|
880
|
+
const bottom = rect.y + rect.height - 1;
|
|
881
|
+
const across = "\u2500".repeat(rect.width - 2);
|
|
882
|
+
frame.writeText({ ...rect, height: 1 }, 0, `\u250C${across}\u2510`, style);
|
|
883
|
+
frame.writeText({ ...rect, y: bottom, height: 1 }, 0, `\u2514${across}\u2518`, style);
|
|
884
|
+
for (let y = rect.y + 1; y < bottom; y++) {
|
|
885
|
+
frame.writeText({ x: rect.x, y, width: 1, height: 1 }, 0, "\u2502", style);
|
|
886
|
+
frame.writeText({ x: right, y, width: 1, height: 1 }, 0, "\u2502", style);
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
__name(drawBox, "drawBox");
|
|
890
|
+
function dimFrame(frame) {
|
|
891
|
+
for (let i = 0; i < frame.cells.length; i++) {
|
|
892
|
+
const cell = frame.cells[i];
|
|
893
|
+
if (cell && cell.width > 0) frame.cells[i] = { ...cell, attrs: cell.attrs | ATTR_DIM };
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
__name(dimFrame, "dimFrame");
|
|
897
|
+
function clamp(value, low, high) {
|
|
898
|
+
return Math.max(low, Math.min(high, value));
|
|
899
|
+
}
|
|
900
|
+
__name(clamp, "clamp");
|
|
901
|
+
function centred(screen, width, height) {
|
|
902
|
+
const w = Math.min(width, screen.cols);
|
|
903
|
+
const h = Math.min(height, screen.rows);
|
|
904
|
+
return {
|
|
905
|
+
x: Math.floor((screen.cols - w) / 2),
|
|
906
|
+
y: Math.floor((screen.rows - h) / 2),
|
|
907
|
+
width: w,
|
|
908
|
+
height: h
|
|
909
|
+
};
|
|
910
|
+
}
|
|
911
|
+
__name(centred, "centred");
|
|
912
|
+
var BUTTON_GAP = 2;
|
|
913
|
+
function buttonWidth(button) {
|
|
914
|
+
return stringWidth(button.label) + 2;
|
|
915
|
+
}
|
|
916
|
+
__name(buttonWidth, "buttonWidth");
|
|
917
|
+
function fittingButtons(buttons, room) {
|
|
918
|
+
const total = /* @__PURE__ */ __name((list) => list.reduce((sum, b) => sum + buttonWidth(b), 0) + BUTTON_GAP * Math.max(0, list.length - 1), "total");
|
|
919
|
+
const kept = [...buttons];
|
|
920
|
+
for (let i = kept.length - 1; i >= 0 && total(kept) > room; i--) {
|
|
921
|
+
const b = kept[i];
|
|
922
|
+
if (b && !b.primary && b.action !== "cancel") kept.splice(i, 1);
|
|
923
|
+
}
|
|
924
|
+
return kept;
|
|
925
|
+
}
|
|
926
|
+
__name(fittingButtons, "fittingButtons");
|
|
927
|
+
function layoutModal(screen, fullSpec) {
|
|
928
|
+
const spec = {
|
|
929
|
+
...fullSpec,
|
|
930
|
+
buttons: fittingButtons(fullSpec.buttons, screen.cols - 4)
|
|
931
|
+
};
|
|
932
|
+
const buttonsWidth = spec.buttons.reduce((sum, b) => sum + buttonWidth(b), 0) + BUTTON_GAP * Math.max(0, spec.buttons.length - 1);
|
|
933
|
+
const content = Math.max(
|
|
934
|
+
stringWidth(spec.title),
|
|
935
|
+
buttonsWidth,
|
|
936
|
+
...(spec.lines ?? []).map((l) => stringWidth(l))
|
|
937
|
+
);
|
|
938
|
+
const width = Math.min(screen.cols - 2, Math.max(spec.input ? 56 : 40, content + 6));
|
|
939
|
+
const body = (spec.lines?.length ?? 0) + (spec.input ? 2 + (spec.error ? 1 : 0) : 0);
|
|
940
|
+
const rect = centred(screen, width, body + 5);
|
|
941
|
+
const inner = rect.width - 2;
|
|
942
|
+
let y = rect.y + 2 + (spec.lines?.length ?? 0);
|
|
943
|
+
let inputRect;
|
|
944
|
+
if (spec.input) {
|
|
945
|
+
inputRect = { x: rect.x + 1, y: y + 1, width: inner, height: 1 };
|
|
946
|
+
y += 2 + (spec.error ? 1 : 0);
|
|
947
|
+
}
|
|
948
|
+
const buttons = [];
|
|
949
|
+
let x = rect.x + 1 + Math.max(1, Math.floor((inner - buttonsWidth) / 2));
|
|
950
|
+
const by = rect.y + rect.height - 2;
|
|
951
|
+
for (const b of spec.buttons) {
|
|
952
|
+
buttons.push({ rect: { x, y: by, width: buttonWidth(b), height: 1 }, action: b.action });
|
|
953
|
+
x += buttonWidth(b) + BUTTON_GAP;
|
|
954
|
+
}
|
|
955
|
+
return { rect, buttons, rows: [], inputRect };
|
|
956
|
+
}
|
|
957
|
+
__name(layoutModal, "layoutModal");
|
|
958
|
+
function drawModal(frame, layout, spec, palette) {
|
|
959
|
+
const { rect } = layout;
|
|
960
|
+
const tone = spec.danger ? palette.red : palette.accent;
|
|
961
|
+
frame.fillRect(rect, { bg: palette.panelBg });
|
|
962
|
+
drawBox(frame, rect, tone, palette.panelBg);
|
|
963
|
+
const inner = { x: rect.x + 2, y: rect.y, width: rect.width - 4, height: rect.height };
|
|
964
|
+
frame.writeText(inner, 1, spec.title, {
|
|
965
|
+
fg: spec.danger ? palette.red : palette.text,
|
|
966
|
+
bg: palette.panelBg,
|
|
967
|
+
attrs: ATTR_BOLD
|
|
968
|
+
});
|
|
969
|
+
(spec.lines ?? []).forEach(
|
|
970
|
+
(line, i) => frame.writeText(inner, 2 + i, line, { fg: palette.subtext, bg: palette.panelBg })
|
|
971
|
+
);
|
|
972
|
+
if (layout.inputRect && spec.input) {
|
|
973
|
+
const field = layout.inputRect;
|
|
974
|
+
frame.fillRect(field, { bg: palette.surface });
|
|
975
|
+
const room = Math.max(0, field.width - 3);
|
|
976
|
+
let shown = spec.input.value;
|
|
977
|
+
while (stringWidth(shown) > room) shown = shown.slice(1);
|
|
978
|
+
const used = frame.writeText({ ...field, x: field.x + 1, width: field.width - 1 }, 0, shown, {
|
|
979
|
+
fg: palette.text,
|
|
980
|
+
bg: palette.surface
|
|
981
|
+
});
|
|
982
|
+
frame.writeText({ ...field, x: field.x + 1 + used, width: 1 }, 0, " ", {
|
|
983
|
+
bg: palette.text
|
|
984
|
+
});
|
|
985
|
+
if (spec.error)
|
|
986
|
+
frame.writeText(inner, field.y - rect.y + 1, spec.error, {
|
|
987
|
+
fg: palette.red,
|
|
988
|
+
bg: palette.panelBg
|
|
989
|
+
});
|
|
990
|
+
}
|
|
991
|
+
spec.buttons.forEach((b) => {
|
|
992
|
+
const at = layout.buttons.find((l) => l.action === b.action)?.rect;
|
|
993
|
+
if (!at) return;
|
|
994
|
+
const fill = b.primary ? tone : palette.surface;
|
|
995
|
+
frame.fillRect(at, { bg: fill });
|
|
996
|
+
frame.writeText({ ...at, x: at.x + 1, width: at.width - 1 }, 0, b.label, {
|
|
997
|
+
fg: b.primary ? palette.panelBg : palette.text,
|
|
998
|
+
bg: fill,
|
|
999
|
+
...b.primary ? { attrs: ATTR_BOLD } : {}
|
|
1000
|
+
});
|
|
1001
|
+
});
|
|
1002
|
+
}
|
|
1003
|
+
__name(drawModal, "drawModal");
|
|
1004
|
+
function layoutList(screen, spec) {
|
|
1005
|
+
const head = spec.input ? 4 : 3;
|
|
1006
|
+
const chrome = head + 3;
|
|
1007
|
+
const wanted = Math.max(1, spec.rows.length) + chrome;
|
|
1008
|
+
const height = Math.min(screen.rows - 2, wanted);
|
|
1009
|
+
const rect = centred(screen, Math.min(screen.cols - 2, spec.width), Math.max(chrome + 1, height));
|
|
1010
|
+
const capacity = Math.max(1, rect.height - chrome);
|
|
1011
|
+
const most = Math.max(0, spec.rows.length - capacity);
|
|
1012
|
+
let top = clamp(spec.scroll, 0, most);
|
|
1013
|
+
if (spec.index >= 0) {
|
|
1014
|
+
if (spec.index < top) top = spec.index;
|
|
1015
|
+
else if (spec.index >= top + capacity) top = spec.index - capacity + 1;
|
|
1016
|
+
top = clamp(top, 0, most);
|
|
1017
|
+
}
|
|
1018
|
+
const first = rect.y + head;
|
|
1019
|
+
const rows = [];
|
|
1020
|
+
for (let i = 0; i < capacity && top + i < spec.rows.length; i++) {
|
|
1021
|
+
const row = spec.rows[top + i];
|
|
1022
|
+
if (row?.heading) continue;
|
|
1023
|
+
rows.push({
|
|
1024
|
+
rect: { x: rect.x + 1, y: first + i, width: rect.width - 2, height: 1 },
|
|
1025
|
+
index: top + i
|
|
1026
|
+
});
|
|
1027
|
+
}
|
|
1028
|
+
const inputRect = spec.input ? { x: rect.x + 1, y: rect.y + 2, width: rect.width - 2, height: 1 } : void 0;
|
|
1029
|
+
return { rect, buttons: [], rows, inputRect, top, capacity };
|
|
1030
|
+
}
|
|
1031
|
+
__name(layoutList, "layoutList");
|
|
1032
|
+
function drawList(frame, layout, spec, palette) {
|
|
1033
|
+
const { rect } = layout;
|
|
1034
|
+
frame.fillRect(rect, { bg: palette.panelBg });
|
|
1035
|
+
drawBox(frame, rect, palette.accent, palette.panelBg);
|
|
1036
|
+
const inner = { x: rect.x + 2, y: rect.y, width: rect.width - 4, height: rect.height };
|
|
1037
|
+
frame.writeText(inner, 1, spec.title, { fg: palette.text, bg: palette.panelBg, attrs: ATTR_BOLD });
|
|
1038
|
+
if (layout.inputRect && spec.input) {
|
|
1039
|
+
const field = layout.inputRect;
|
|
1040
|
+
frame.fillRect(field, { bg: palette.surface });
|
|
1041
|
+
const room = Math.max(0, field.width - 3);
|
|
1042
|
+
let shown = spec.input.value;
|
|
1043
|
+
while (stringWidth(shown) > room) shown = shown.slice(1);
|
|
1044
|
+
const used = frame.writeText({ ...field, x: field.x + 1, width: field.width - 1 }, 0, shown, {
|
|
1045
|
+
fg: palette.text,
|
|
1046
|
+
bg: palette.surface
|
|
1047
|
+
});
|
|
1048
|
+
frame.writeText({ ...field, x: field.x + 1 + used, width: 1 }, 0, " ", { bg: palette.text });
|
|
1049
|
+
}
|
|
1050
|
+
const first = rect.y + (spec.input ? 4 : 3);
|
|
1051
|
+
for (let i = 0; i < layout.capacity; i++) {
|
|
1052
|
+
const row = spec.rows[layout.top + i];
|
|
1053
|
+
if (!row) break;
|
|
1054
|
+
const area = { x: rect.x + 1, y: first + i, width: rect.width - 2, height: 1 };
|
|
1055
|
+
const chosen = layout.top + i === spec.index;
|
|
1056
|
+
const bg = chosen ? palette.cursorRow : palette.panelBg;
|
|
1057
|
+
frame.fillRect(area, { bg });
|
|
1058
|
+
let x = 1 + (row.indent ?? 0);
|
|
1059
|
+
const put = /* @__PURE__ */ __name((text, style) => {
|
|
1060
|
+
x += frame.writeText(
|
|
1061
|
+
{ ...area, x: area.x + x, width: Math.max(0, area.width - x) },
|
|
1062
|
+
0,
|
|
1063
|
+
text,
|
|
1064
|
+
{
|
|
1065
|
+
...style,
|
|
1066
|
+
bg
|
|
1067
|
+
}
|
|
1068
|
+
);
|
|
1069
|
+
}, "put");
|
|
1070
|
+
if (row.dot) {
|
|
1071
|
+
put(row.dot.glyph, { fg: row.dot.fg });
|
|
1072
|
+
x += 1;
|
|
1073
|
+
}
|
|
1074
|
+
if (row.keys !== void 0) {
|
|
1075
|
+
put(row.keys.padEnd(12), { fg: palette.accent, attrs: ATTR_BOLD });
|
|
1076
|
+
x += 1;
|
|
1077
|
+
}
|
|
1078
|
+
put(row.text, {
|
|
1079
|
+
fg: row.heading ? palette.dimmer : row.muted ? palette.dim : chosen ? palette.text : palette.subtext,
|
|
1080
|
+
...row.heading || chosen ? { attrs: ATTR_BOLD } : {}
|
|
1081
|
+
});
|
|
1082
|
+
}
|
|
1083
|
+
frame.writeText({ ...inner, y: rect.y + rect.height - 2, height: 1 }, 0, spec.footer, {
|
|
1084
|
+
fg: palette.dim,
|
|
1085
|
+
bg: palette.panelBg
|
|
1086
|
+
});
|
|
1087
|
+
}
|
|
1088
|
+
__name(drawList, "drawList");
|
|
1089
|
+
function layoutPopup(screen, at, items, minWidth = 14) {
|
|
1090
|
+
const width = Math.min(
|
|
1091
|
+
screen.cols,
|
|
1092
|
+
Math.max(minWidth, ...items.map((i) => stringWidth(i) + 4)) + 2
|
|
1093
|
+
);
|
|
1094
|
+
const height = items.length + 2;
|
|
1095
|
+
const x = clamp(at.x, 0, Math.max(0, screen.cols - width));
|
|
1096
|
+
const y = clamp(at.y, 0, Math.max(0, screen.rows - height));
|
|
1097
|
+
const rect = { x, y, width, height };
|
|
1098
|
+
return {
|
|
1099
|
+
rect,
|
|
1100
|
+
buttons: [],
|
|
1101
|
+
rows: items.map((_, i) => ({
|
|
1102
|
+
rect: { x: x + 1, y: y + 1 + i, width: width - 2, height: 1 },
|
|
1103
|
+
index: i
|
|
1104
|
+
}))
|
|
1105
|
+
};
|
|
1106
|
+
}
|
|
1107
|
+
__name(layoutPopup, "layoutPopup");
|
|
1108
|
+
function drawPopup(frame, surface, items, index, palette) {
|
|
1109
|
+
frame.fillRect(surface.rect, { bg: palette.panelBg });
|
|
1110
|
+
drawBox(frame, surface.rect, palette.accent, palette.panelBg);
|
|
1111
|
+
items.forEach((item, i) => {
|
|
1112
|
+
const row = surface.rows[i]?.rect;
|
|
1113
|
+
if (!row) return;
|
|
1114
|
+
const chosen = i === index;
|
|
1115
|
+
const bg = chosen ? palette.accent : palette.panelBg;
|
|
1116
|
+
frame.fillRect(row, { bg });
|
|
1117
|
+
frame.writeText({ ...row, x: row.x + 1, width: row.width - 1 }, 0, item, {
|
|
1118
|
+
fg: chosen ? palette.panelBg : palette.subtext,
|
|
1119
|
+
bg,
|
|
1120
|
+
...chosen ? { attrs: ATTR_BOLD } : {}
|
|
1121
|
+
});
|
|
1122
|
+
});
|
|
1123
|
+
}
|
|
1124
|
+
__name(drawPopup, "drawPopup");
|
|
1125
|
+
|
|
1126
|
+
// src/spaces/roster.ts
|
|
1127
|
+
var Entry = class {
|
|
1128
|
+
constructor(slot, spaceId, label) {
|
|
1129
|
+
this.slot = slot;
|
|
1130
|
+
this.spaceId = spaceId;
|
|
1131
|
+
this.label = label;
|
|
1132
|
+
}
|
|
1133
|
+
slot;
|
|
1134
|
+
spaceId;
|
|
1135
|
+
label;
|
|
1136
|
+
static {
|
|
1137
|
+
__name(this, "Entry");
|
|
1138
|
+
}
|
|
1139
|
+
child;
|
|
1140
|
+
/** What the session's own terminal last reported through the peer feed. */
|
|
1141
|
+
reported;
|
|
1142
|
+
/** A turn finished while nobody was looking at this session. */
|
|
1143
|
+
unseen = false;
|
|
1144
|
+
/** Rows scrolled back into the session's history; 0 follows the live screen. */
|
|
1145
|
+
scrollBack = 0;
|
|
1146
|
+
/** The label of the non-usual account the session is on, as its terminal last reported. */
|
|
1147
|
+
account;
|
|
1148
|
+
conversationId;
|
|
1149
|
+
limited = false;
|
|
1150
|
+
/** When the spent allowance is expected back (epoch ms), if the terminal knows. */
|
|
1151
|
+
limitedUntil;
|
|
1152
|
+
/** The account id picked when the session was started; what a first launch binds. */
|
|
1153
|
+
pickedAccount;
|
|
1154
|
+
/** The session the command itself started, which alone receives the command's options. */
|
|
1155
|
+
first = false;
|
|
1156
|
+
/** The conversation to open when the session first starts, for one restored from a previous run. */
|
|
1157
|
+
resume;
|
|
1158
|
+
/** Whether its conversation is already open in another terminal: it is not started. */
|
|
1159
|
+
openElsewhere = false;
|
|
1160
|
+
/** Restored from a previous run: its folder is looked at again each time it is opened. */
|
|
1161
|
+
verifyFolder = false;
|
|
1162
|
+
/** Its folder was not found when it was last opened, so it is not started. */
|
|
1163
|
+
folderMissing = false;
|
|
1164
|
+
/** The check for that is running. */
|
|
1165
|
+
checking = false;
|
|
1166
|
+
/** When its activity last changed, as a count that only grows; the priority order puts the newest first. */
|
|
1167
|
+
changedAt = 0;
|
|
1168
|
+
seen = "not-started";
|
|
1169
|
+
activity() {
|
|
1170
|
+
return deriveActivity(this.child ? this.child.status : "none", this.reported);
|
|
1171
|
+
}
|
|
1172
|
+
dot() {
|
|
1173
|
+
return dotFor(this.activity(), this.unseen);
|
|
1174
|
+
}
|
|
1175
|
+
/** Records the activity just observed; returns the previous one. */
|
|
1176
|
+
observe() {
|
|
1177
|
+
const previous = this.seen;
|
|
1178
|
+
this.seen = this.activity();
|
|
1179
|
+
return previous;
|
|
1180
|
+
}
|
|
1181
|
+
};
|
|
1182
|
+
var Roster = class {
|
|
1183
|
+
static {
|
|
1184
|
+
__name(this, "Roster");
|
|
1185
|
+
}
|
|
1186
|
+
spaces = [];
|
|
1187
|
+
entries = [];
|
|
1188
|
+
current;
|
|
1189
|
+
counter = 0;
|
|
1190
|
+
ticks = 0;
|
|
1191
|
+
/** The session with focus: the focused pane of the shown tab of the shown space. */
|
|
1192
|
+
get selected() {
|
|
1193
|
+
return this.current;
|
|
1194
|
+
}
|
|
1195
|
+
spaceOf(entry) {
|
|
1196
|
+
return this.spaces.find((s) => s.id === entry.spaceId);
|
|
1197
|
+
}
|
|
1198
|
+
entriesOf(space) {
|
|
1199
|
+
return this.entries.filter((e) => e.spaceId === space.id);
|
|
1200
|
+
}
|
|
1201
|
+
tabOf(entry) {
|
|
1202
|
+
return this.spaceOf(entry)?.tabs.find((t) => contains(t.root, entry));
|
|
1203
|
+
}
|
|
1204
|
+
/** The tab being shown. */
|
|
1205
|
+
get shownTab() {
|
|
1206
|
+
const entry = this.current;
|
|
1207
|
+
return entry ? this.tabOf(entry) : void 0;
|
|
1208
|
+
}
|
|
1209
|
+
addSpace(cwd, name) {
|
|
1210
|
+
const space = {
|
|
1211
|
+
id: `space-${++this.counter}`,
|
|
1212
|
+
name,
|
|
1213
|
+
cwd,
|
|
1214
|
+
tabs: [],
|
|
1215
|
+
activeTab: void 0
|
|
1216
|
+
};
|
|
1217
|
+
this.spaces.push(space);
|
|
1218
|
+
return space;
|
|
1219
|
+
}
|
|
1220
|
+
/** Moves a space to a place in the list; the others keep their order. False when nothing moved. */
|
|
1221
|
+
moveSpace(space, to) {
|
|
1222
|
+
const from = this.spaces.indexOf(space);
|
|
1223
|
+
const target = Math.max(0, Math.min(this.spaces.length - 1, to));
|
|
1224
|
+
if (from < 0 || from === target) return false;
|
|
1225
|
+
this.spaces.splice(from, 1);
|
|
1226
|
+
this.spaces.splice(target, 0, space);
|
|
1227
|
+
return true;
|
|
1228
|
+
}
|
|
1229
|
+
/** A session that is not in any tab yet; give it a place with `addTab` or `splitBeside`. */
|
|
1230
|
+
addSession(space, slot, label) {
|
|
1231
|
+
const own = this.entriesOf(space);
|
|
1232
|
+
const entry = new Entry(slot, space.id, label ?? this.freeLabel(own));
|
|
1233
|
+
this.entries.push(entry);
|
|
1234
|
+
this.current ??= entry;
|
|
1235
|
+
return entry;
|
|
1236
|
+
}
|
|
1237
|
+
/** A tab holding one pane, after the space's others. */
|
|
1238
|
+
addTab(space, entry, name) {
|
|
1239
|
+
const tab = {
|
|
1240
|
+
root: leaf(entry),
|
|
1241
|
+
focus: entry,
|
|
1242
|
+
zoomed: false,
|
|
1243
|
+
...name ? { name } : {}
|
|
1244
|
+
};
|
|
1245
|
+
space.tabs.push(tab);
|
|
1246
|
+
space.activeTab ??= tab;
|
|
1247
|
+
return tab;
|
|
1248
|
+
}
|
|
1249
|
+
/** A tab built from a whole tree, as when a layout is restored. */
|
|
1250
|
+
addTree(space, root, focus, name, zoomed = false) {
|
|
1251
|
+
const tab = { root, focus, zoomed, ...name ? { name } : {} };
|
|
1252
|
+
space.tabs.push(tab);
|
|
1253
|
+
space.activeTab ??= tab;
|
|
1254
|
+
return tab;
|
|
1255
|
+
}
|
|
1256
|
+
/** Splits the pane of `target` and puts `created` in the new half, which takes focus. */
|
|
1257
|
+
splitBeside(target, created, dir) {
|
|
1258
|
+
const tab = this.tabOf(target);
|
|
1259
|
+
if (!tab) return;
|
|
1260
|
+
tab.root = splitLeaf(tab.root, target, created, dir);
|
|
1261
|
+
tab.zoomed = false;
|
|
1262
|
+
tab.focus = created;
|
|
1263
|
+
}
|
|
1264
|
+
/** `session N` for the smallest N not already used, so a name never repeats after a close. */
|
|
1265
|
+
freeLabel(own) {
|
|
1266
|
+
const used = new Set(own.map((e) => e.label));
|
|
1267
|
+
for (let n = own.length + 1; ; n++) if (!used.has(`session ${n}`)) return `session ${n}`;
|
|
1268
|
+
}
|
|
1269
|
+
/** Whether the entry's pane is on screen: in the shown tab of the shown space. */
|
|
1270
|
+
isVisible(entry) {
|
|
1271
|
+
const tab = this.shownTab;
|
|
1272
|
+
return tab !== void 0 && contains(tab.root, entry);
|
|
1273
|
+
}
|
|
1274
|
+
/** Shows an entry's tab with that pane focused; looking at panes clears their "finished" mark. */
|
|
1275
|
+
select(entry) {
|
|
1276
|
+
if (!this.entries.includes(entry)) return;
|
|
1277
|
+
const space = this.spaceOf(entry);
|
|
1278
|
+
const tab = this.tabOf(entry);
|
|
1279
|
+
if (tab) {
|
|
1280
|
+
tab.focus = entry;
|
|
1281
|
+
space.activeTab = tab;
|
|
1282
|
+
}
|
|
1283
|
+
this.current = entry;
|
|
1284
|
+
entry.scrollBack = 0;
|
|
1285
|
+
for (const seen of tab ? leaves(tab.root) : [entry]) seen.unseen = false;
|
|
1286
|
+
}
|
|
1287
|
+
/** Re-reads an entry's activity and marks a finished turn nobody was watching. */
|
|
1288
|
+
update(entry) {
|
|
1289
|
+
const before = entry.observe();
|
|
1290
|
+
const now = entry.activity();
|
|
1291
|
+
if (before !== now) entry.changedAt = ++this.ticks;
|
|
1292
|
+
if ((before === "working" || before === "needs-approval") && now === "idle") {
|
|
1293
|
+
if (!this.isVisible(entry)) entry.unseen = true;
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
spaceDot(space) {
|
|
1297
|
+
return aggregateDot(this.entriesOf(space).map((e) => e.dot()));
|
|
1298
|
+
}
|
|
1299
|
+
/**
|
|
1300
|
+
* Removes a session and its pane: the neighbour takes the room and focus. A tab
|
|
1301
|
+
* left empty goes, and so does a space left with no tab.
|
|
1302
|
+
*/
|
|
1303
|
+
removeEntry(entry) {
|
|
1304
|
+
const index = this.entries.indexOf(entry);
|
|
1305
|
+
if (index < 0) return;
|
|
1306
|
+
const space = this.spaces.find((s) => s.id === entry.spaceId);
|
|
1307
|
+
const tab = space?.tabs.find((t) => contains(t.root, entry));
|
|
1308
|
+
let landing;
|
|
1309
|
+
this.entries.splice(index, 1);
|
|
1310
|
+
if (space && tab) {
|
|
1311
|
+
const { root, next } = removeLeaf(tab.root, entry);
|
|
1312
|
+
if (root) {
|
|
1313
|
+
tab.root = root;
|
|
1314
|
+
tab.zoomed = tab.zoomed && leaves(root).length > 1;
|
|
1315
|
+
if (tab.focus === entry) tab.focus = next ?? leaves(root)[0];
|
|
1316
|
+
landing = tab.focus;
|
|
1317
|
+
} else {
|
|
1318
|
+
const at = space.tabs.indexOf(tab);
|
|
1319
|
+
space.tabs.splice(at, 1);
|
|
1320
|
+
if (space.activeTab === tab)
|
|
1321
|
+
space.activeTab = space.tabs[Math.min(at, space.tabs.length - 1)];
|
|
1322
|
+
landing = space.activeTab?.focus;
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
if (space && space.tabs.length === 0) this.spaces.splice(this.spaces.indexOf(space), 1);
|
|
1326
|
+
if (this.current === entry) {
|
|
1327
|
+
const next = landing ?? this.entries[Math.min(index, this.entries.length - 1)];
|
|
1328
|
+
this.current = next;
|
|
1329
|
+
if (next) {
|
|
1330
|
+
const there = this.spaces.find((s) => s.id === next.spaceId);
|
|
1331
|
+
const nextTab = there?.tabs.find((t) => contains(t.root, next));
|
|
1332
|
+
if (there && nextTab) there.activeTab = nextTab;
|
|
1333
|
+
for (const seen of nextTab ? leaves(nextTab.root) : [next]) seen.unseen = false;
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
removeSpace(space) {
|
|
1338
|
+
const gone = this.entriesOf(space);
|
|
1339
|
+
for (const entry of gone) this.removeEntry(entry);
|
|
1340
|
+
return gone;
|
|
1341
|
+
}
|
|
1342
|
+
/** Takes a tab out with its sessions. */
|
|
1343
|
+
removeTab(space, tab) {
|
|
1344
|
+
const gone = leaves(tab.root);
|
|
1345
|
+
for (const entry of gone) this.removeEntry(entry);
|
|
1346
|
+
return gone;
|
|
1347
|
+
}
|
|
1348
|
+
};
|
|
1349
|
+
|
|
1350
|
+
// src/spaces/session.ts
|
|
1351
|
+
var SCROLLBACK = 2e3;
|
|
1352
|
+
var ChildSession = class {
|
|
1353
|
+
constructor(label, spec, size, onChange, kill = killProcessTree, onSignal) {
|
|
1354
|
+
this.label = label;
|
|
1355
|
+
this.spec = spec;
|
|
1356
|
+
this.onChange = onChange;
|
|
1357
|
+
this.kill = kill;
|
|
1358
|
+
this.onSignal = onSignal;
|
|
1359
|
+
this.cols = size.cols;
|
|
1360
|
+
this.rows = size.rows;
|
|
1361
|
+
this.screen = new HeadlessScreen(size.cols, size.rows, SCROLLBACK);
|
|
1362
|
+
}
|
|
1363
|
+
label;
|
|
1364
|
+
spec;
|
|
1365
|
+
onChange;
|
|
1366
|
+
kill;
|
|
1367
|
+
onSignal;
|
|
1368
|
+
static {
|
|
1369
|
+
__name(this, "ChildSession");
|
|
1370
|
+
}
|
|
1371
|
+
status = "starting";
|
|
1372
|
+
ending;
|
|
1373
|
+
screen;
|
|
1374
|
+
pty;
|
|
1375
|
+
signals = new SignalFilter();
|
|
1376
|
+
cols;
|
|
1377
|
+
rows;
|
|
1378
|
+
/** The process id of the program, once it has started. */
|
|
1379
|
+
get pid() {
|
|
1380
|
+
return this.pty?.pid;
|
|
1381
|
+
}
|
|
1382
|
+
start(binding) {
|
|
1383
|
+
try {
|
|
1384
|
+
const pty = binding.spawn(this.spec.file, [...this.spec.args], {
|
|
1385
|
+
name: "xterm-256color",
|
|
1386
|
+
cols: this.cols,
|
|
1387
|
+
rows: this.rows,
|
|
1388
|
+
cwd: this.spec.cwd,
|
|
1389
|
+
env: this.spec.env
|
|
1390
|
+
});
|
|
1391
|
+
this.pty = pty;
|
|
1392
|
+
pty.onData((data) => {
|
|
1393
|
+
try {
|
|
1394
|
+
if (this.status === "starting") this.status = "running";
|
|
1395
|
+
const { text, signals } = this.signals.feed(data);
|
|
1396
|
+
if (text !== "") this.screen.write(text);
|
|
1397
|
+
this.onChange();
|
|
1398
|
+
for (const signal of signals) this.onSignal?.(signal);
|
|
1399
|
+
} catch {
|
|
1400
|
+
}
|
|
1401
|
+
});
|
|
1402
|
+
pty.onExit(({ exitCode, signal }) => {
|
|
1403
|
+
this.finish(exitCode === 0 && !signal ? "finished" : "stopped");
|
|
1404
|
+
});
|
|
1405
|
+
this.screen.onResponse((reply) => this.write(reply));
|
|
1406
|
+
} catch {
|
|
1407
|
+
this.finish("could-not-start");
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
finish(ending) {
|
|
1411
|
+
if (this.status === "exited") return;
|
|
1412
|
+
this.status = "exited";
|
|
1413
|
+
this.ending = ending;
|
|
1414
|
+
this.onChange();
|
|
1415
|
+
}
|
|
1416
|
+
/** Sends input to the program; nothing once it has ended. */
|
|
1417
|
+
write(data) {
|
|
1418
|
+
if (this.status === "exited" || !this.pty) return;
|
|
1419
|
+
try {
|
|
1420
|
+
this.pty.write(data);
|
|
1421
|
+
} catch {
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
/** Gives the program a new size; the screen follows even when the program is gone. */
|
|
1425
|
+
resize(cols, rows) {
|
|
1426
|
+
if (cols < 1 || rows < 1) return;
|
|
1427
|
+
if (cols === this.cols && rows === this.rows) return;
|
|
1428
|
+
this.cols = cols;
|
|
1429
|
+
this.rows = rows;
|
|
1430
|
+
try {
|
|
1431
|
+
this.screen.resize(cols, rows);
|
|
1432
|
+
} catch {
|
|
1433
|
+
}
|
|
1434
|
+
if (this.status === "exited" || !this.pty) return;
|
|
1435
|
+
try {
|
|
1436
|
+
this.pty.resize(cols, rows);
|
|
1437
|
+
} catch {
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
/** Ends the program and what it started. */
|
|
1441
|
+
stop(signal = "SIGHUP") {
|
|
1442
|
+
if (this.status === "exited" || !this.pty) return;
|
|
1443
|
+
this.kill(this.pty, signal);
|
|
1444
|
+
}
|
|
1445
|
+
dispose() {
|
|
1446
|
+
this.screen.dispose();
|
|
1447
|
+
}
|
|
1448
|
+
};
|
|
1449
|
+
|
|
1450
|
+
// src/spaces/sidebar.ts
|
|
1451
|
+
var GLYPHS = {
|
|
1452
|
+
blocked: "\u25CF",
|
|
1453
|
+
done: "\u25CF",
|
|
1454
|
+
working: "\u25CF",
|
|
1455
|
+
idle: "\u25CB",
|
|
1456
|
+
none: "\xB7"
|
|
1457
|
+
};
|
|
1458
|
+
function dotColor(dot, palette) {
|
|
1459
|
+
switch (dot) {
|
|
1460
|
+
case "blocked":
|
|
1461
|
+
return palette.red;
|
|
1462
|
+
case "done":
|
|
1463
|
+
return palette.teal;
|
|
1464
|
+
case "working":
|
|
1465
|
+
return palette.yellow;
|
|
1466
|
+
case "idle":
|
|
1467
|
+
return palette.green;
|
|
1468
|
+
case "none":
|
|
1469
|
+
return palette.dim;
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
__name(dotColor, "dotColor");
|
|
1473
|
+
function dotStyle(dot, palette) {
|
|
1474
|
+
return { glyph: GLYPHS[dot], fg: dotColor(dot, palette) };
|
|
1475
|
+
}
|
|
1476
|
+
__name(dotStyle, "dotStyle");
|
|
1477
|
+
var NEW_WIDTH = 5;
|
|
1478
|
+
var MENU_WIDTH = 6;
|
|
1479
|
+
var TOGGLE_WIDTH = 3;
|
|
1480
|
+
var MIN_SECTION = 3;
|
|
1481
|
+
function ruleRow(height, split) {
|
|
1482
|
+
if (height < MIN_SECTION * 2 + 2) return Math.floor(height / 2);
|
|
1483
|
+
const wanted = Math.round(height * (Number.isFinite(split) ? split : 0.5));
|
|
1484
|
+
return Math.max(MIN_SECTION, Math.min(height - MIN_SECTION - 1, wanted));
|
|
1485
|
+
}
|
|
1486
|
+
__name(ruleRow, "ruleRow");
|
|
1487
|
+
function geometry(height, footLines, split, rail) {
|
|
1488
|
+
const ruleY = ruleRow(height, split);
|
|
1489
|
+
const toggleY = Math.max(0, height - 1);
|
|
1490
|
+
if (rail)
|
|
1491
|
+
return {
|
|
1492
|
+
rail,
|
|
1493
|
+
height,
|
|
1494
|
+
ruleY,
|
|
1495
|
+
headerY: void 0,
|
|
1496
|
+
spaceTop: 0,
|
|
1497
|
+
spaceStep: 1,
|
|
1498
|
+
spaceCap: Math.max(0, ruleY),
|
|
1499
|
+
footerY: void 0,
|
|
1500
|
+
agentHeaderY: void 0,
|
|
1501
|
+
agentTop: ruleY + 1,
|
|
1502
|
+
agentCap: Math.max(0, toggleY - (ruleY + 1)),
|
|
1503
|
+
toggleY
|
|
1504
|
+
};
|
|
1505
|
+
const footerY = ruleY - 1;
|
|
1506
|
+
const agentTop = ruleY + 3;
|
|
1507
|
+
const agentBottom = Math.max(agentTop, height - 1 - footLines);
|
|
1508
|
+
return {
|
|
1509
|
+
rail,
|
|
1510
|
+
height,
|
|
1511
|
+
ruleY,
|
|
1512
|
+
headerY: 0,
|
|
1513
|
+
spaceTop: 2,
|
|
1514
|
+
spaceStep: 2,
|
|
1515
|
+
spaceCap: Math.max(0, Math.floor((footerY - 2) / 2)),
|
|
1516
|
+
footerY,
|
|
1517
|
+
agentHeaderY: ruleY + 1,
|
|
1518
|
+
agentTop,
|
|
1519
|
+
agentCap: Math.max(0, Math.floor((agentBottom - agentTop) / 2)),
|
|
1520
|
+
toggleY
|
|
1521
|
+
};
|
|
1522
|
+
}
|
|
1523
|
+
__name(geometry, "geometry");
|
|
1524
|
+
var RANK = {
|
|
1525
|
+
blocked: 0,
|
|
1526
|
+
done: 1,
|
|
1527
|
+
working: 2,
|
|
1528
|
+
idle: 3,
|
|
1529
|
+
none: 4
|
|
1530
|
+
};
|
|
1531
|
+
function agentList(roster, order) {
|
|
1532
|
+
const grouped = roster.spaces.flatMap((space) => space.tabs.flatMap((tab) => leaves(tab.root)));
|
|
1533
|
+
if (order === "grouped") return grouped;
|
|
1534
|
+
return grouped.map((entry, index) => ({ entry, index })).sort(
|
|
1535
|
+
(a, b) => RANK[a.entry.dot()] - RANK[b.entry.dot()] || b.entry.changedAt - a.entry.changedAt || a.index - b.index
|
|
1536
|
+
).map((item) => item.entry);
|
|
1537
|
+
}
|
|
1538
|
+
__name(agentList, "agentList");
|
|
1539
|
+
function within2(scroll, total, cap, reveal) {
|
|
1540
|
+
const most = Math.max(0, total - cap);
|
|
1541
|
+
let next = Math.max(0, Math.min(scroll, most));
|
|
1542
|
+
if (reveal >= 0 && cap > 0) {
|
|
1543
|
+
if (reveal < next) next = reveal;
|
|
1544
|
+
else if (reveal >= next + cap) next = reveal - cap + 1;
|
|
1545
|
+
}
|
|
1546
|
+
return Math.max(0, Math.min(next, most));
|
|
1547
|
+
}
|
|
1548
|
+
__name(within2, "within");
|
|
1549
|
+
function clampScroll(scroll, model, height, reveal = false) {
|
|
1550
|
+
const geo = geometry(height, model.foot.length, model.split, model.rail);
|
|
1551
|
+
const selected = model.roster.selected;
|
|
1552
|
+
const space = selected ? model.roster.spaceOf(selected) : void 0;
|
|
1553
|
+
const agents = agentList(model.roster, model.order);
|
|
1554
|
+
return {
|
|
1555
|
+
spaces: within2(
|
|
1556
|
+
scroll.spaces,
|
|
1557
|
+
model.roster.spaces.length,
|
|
1558
|
+
geo.spaceCap,
|
|
1559
|
+
reveal && space ? model.roster.spaces.indexOf(space) : -1
|
|
1560
|
+
),
|
|
1561
|
+
agents: within2(
|
|
1562
|
+
scroll.agents,
|
|
1563
|
+
agents.length,
|
|
1564
|
+
geo.agentCap,
|
|
1565
|
+
reveal && selected ? agents.indexOf(selected) : -1
|
|
1566
|
+
)
|
|
1567
|
+
};
|
|
1568
|
+
}
|
|
1569
|
+
__name(clampScroll, "clampScroll");
|
|
1570
|
+
function regionAt(model, height, y) {
|
|
1571
|
+
const geo = geometry(height, model.foot.length, model.split, model.rail);
|
|
1572
|
+
if (y < geo.ruleY) return "spaces";
|
|
1573
|
+
if (y > geo.ruleY) return "agents";
|
|
1574
|
+
return void 0;
|
|
1575
|
+
}
|
|
1576
|
+
__name(regionAt, "regionAt");
|
|
1577
|
+
function orderLabel(order) {
|
|
1578
|
+
return order;
|
|
1579
|
+
}
|
|
1580
|
+
__name(orderLabel, "orderLabel");
|
|
1581
|
+
function hitTest(model, width, height, x, y) {
|
|
1582
|
+
const geo = geometry(height, model.foot.length, model.split, model.rail);
|
|
1583
|
+
if (y === geo.toggleY && x >= width - TOGGLE_WIDTH) return { kind: "collapse" };
|
|
1584
|
+
if (y === geo.ruleY) return { kind: "split" };
|
|
1585
|
+
if (geo.footerY !== void 0 && y === geo.footerY) {
|
|
1586
|
+
if (x < NEW_WIDTH) return { kind: "new" };
|
|
1587
|
+
if (x >= width - MENU_WIDTH) return { kind: "menu" };
|
|
1588
|
+
return void 0;
|
|
1589
|
+
}
|
|
1590
|
+
if (geo.agentHeaderY !== void 0 && y === geo.agentHeaderY) {
|
|
1591
|
+
return x >= width - orderLabel(model.order).length - 1 ? { kind: "order" } : void 0;
|
|
1592
|
+
}
|
|
1593
|
+
const spaceLine = y - geo.spaceTop;
|
|
1594
|
+
if (spaceLine >= 0 && spaceLine < geo.spaceCap * geo.spaceStep && y < geo.ruleY) {
|
|
1595
|
+
const space = model.roster.spaces[model.scroll.spaces + Math.floor(spaceLine / geo.spaceStep)];
|
|
1596
|
+
return space ? { kind: "space", space } : void 0;
|
|
1597
|
+
}
|
|
1598
|
+
const agentLine = y - geo.agentTop;
|
|
1599
|
+
if (agentLine >= 0 && agentLine < geo.agentCap * geo.spaceStep) {
|
|
1600
|
+
const entry = agentList(model.roster, model.order)[model.scroll.agents + Math.floor(agentLine / geo.spaceStep)];
|
|
1601
|
+
return entry ? { kind: "agent", entry } : void 0;
|
|
1602
|
+
}
|
|
1603
|
+
return void 0;
|
|
1604
|
+
}
|
|
1605
|
+
__name(hitTest, "hitTest");
|
|
1606
|
+
function clip(text, max) {
|
|
1607
|
+
if (max <= 0) return "";
|
|
1608
|
+
if (stringWidth(text) <= max) return text;
|
|
1609
|
+
let out = "";
|
|
1610
|
+
let used = 0;
|
|
1611
|
+
for (const ch of text) {
|
|
1612
|
+
const w = stringWidth(ch);
|
|
1613
|
+
if (used + w > max - 1) break;
|
|
1614
|
+
out += ch;
|
|
1615
|
+
used += w;
|
|
1616
|
+
}
|
|
1617
|
+
return `${out}\u2026`;
|
|
1618
|
+
}
|
|
1619
|
+
__name(clip, "clip");
|
|
1620
|
+
function agentDetail(roster, entry, width = Number.POSITIVE_INFINITY) {
|
|
1621
|
+
const space = roster.spaceOf(entry);
|
|
1622
|
+
const tab = roster.tabOf(entry);
|
|
1623
|
+
const index = tab ? space.tabs.indexOf(tab) + 1 : 0;
|
|
1624
|
+
const many = space.tabs.length > 1 && tab !== void 0;
|
|
1625
|
+
const join2 = /* @__PURE__ */ __name((parts) => parts.join(" \xB7 "), "join");
|
|
1626
|
+
const account = entry.account ? [entry.account] : [];
|
|
1627
|
+
const full = join2([...many ? [tab.name ?? `tab ${index}`] : [], entry.label, ...account]);
|
|
1628
|
+
if (stringWidth(full) <= width) return full;
|
|
1629
|
+
const short = join2([...many ? [String(index)] : [], entry.label, ...account]);
|
|
1630
|
+
if (stringWidth(short) <= width) return short;
|
|
1631
|
+
const tail = account.length > 0 ? ` \xB7 ${entry.account}` : "";
|
|
1632
|
+
const head = join2([...many ? [String(index)] : [], entry.label]);
|
|
1633
|
+
return `${clip(head, Math.max(1, width - stringWidth(tail)))}${tail}`;
|
|
1634
|
+
}
|
|
1635
|
+
__name(agentDetail, "agentDetail");
|
|
1636
|
+
function agentWarning(entry) {
|
|
1637
|
+
if (entry.folderMissing) return "folder not found";
|
|
1638
|
+
if (entry.openElsewhere) return "open in another terminal";
|
|
1639
|
+
if (entry.limited && entry.activity() !== "exited")
|
|
1640
|
+
return limitedNote(entry.limitedUntil, Date.now());
|
|
1641
|
+
return void 0;
|
|
1642
|
+
}
|
|
1643
|
+
__name(agentWarning, "agentWarning");
|
|
1644
|
+
function attention(roster) {
|
|
1645
|
+
let found;
|
|
1646
|
+
for (const space of roster.spaces) {
|
|
1647
|
+
const dot = roster.spaceDot(space);
|
|
1648
|
+
if (dot === "blocked") return dot;
|
|
1649
|
+
if (dot === "done") found = dot;
|
|
1650
|
+
}
|
|
1651
|
+
return found;
|
|
1652
|
+
}
|
|
1653
|
+
__name(attention, "attention");
|
|
1654
|
+
function readable(fg, bg, palette) {
|
|
1655
|
+
return bg >= 0 && fg === bg ? palette.text : fg;
|
|
1656
|
+
}
|
|
1657
|
+
__name(readable, "readable");
|
|
1658
|
+
function scrollThumb(total, cap, scroll, rows) {
|
|
1659
|
+
if (cap <= 0 || total <= cap || rows <= 0) return void 0;
|
|
1660
|
+
const length = Math.max(1, Math.min(rows, Math.round(rows * cap / total)));
|
|
1661
|
+
const most = total - cap;
|
|
1662
|
+
const start = Math.round((rows - length) * Math.max(0, Math.min(scroll, most)) / most);
|
|
1663
|
+
return { start, length };
|
|
1664
|
+
}
|
|
1665
|
+
__name(scrollThumb, "scrollThumb");
|
|
1666
|
+
function railIndex(index) {
|
|
1667
|
+
return String((index + 1) % 100).padStart(index + 1 > 99 ? 2 : 0, "0");
|
|
1668
|
+
}
|
|
1669
|
+
__name(railIndex, "railIndex");
|
|
1670
|
+
function drawSidebar(frame, rect, model) {
|
|
1671
|
+
const { palette, roster } = model;
|
|
1672
|
+
const geo = geometry(rect.height, model.foot.length, model.split, model.rail);
|
|
1673
|
+
const navigating = model.mode === "navigate";
|
|
1674
|
+
frame.fillRect(rect);
|
|
1675
|
+
const at = /* @__PURE__ */ __name((x, y, text, style = {}) => {
|
|
1676
|
+
if (x >= rect.width) return;
|
|
1677
|
+
const fg = style.fg !== void 0 && style.bg !== void 0 ? readable(style.fg, style.bg, palette) : style.fg;
|
|
1678
|
+
frame.writeText({ ...rect, x: rect.x + x, width: rect.width - x }, y, text, {
|
|
1679
|
+
...style,
|
|
1680
|
+
...fg !== void 0 ? { fg } : {}
|
|
1681
|
+
});
|
|
1682
|
+
}, "at");
|
|
1683
|
+
const tint = /* @__PURE__ */ __name((y, height, bg) => {
|
|
1684
|
+
if (bg >= 0) frame.fillRect({ ...rect, y: rect.y + y, height }, { bg });
|
|
1685
|
+
}, "tint");
|
|
1686
|
+
const bar = /* @__PURE__ */ __name((x, top2, rows, total, cap, scroll) => {
|
|
1687
|
+
const thumb = scrollThumb(total, cap, scroll, rows);
|
|
1688
|
+
if (!thumb) return;
|
|
1689
|
+
for (let i = 0; i < thumb.length; i++) at(x, top2 + thumb.start + i, "\u2503", { fg: palette.dim });
|
|
1690
|
+
}, "bar");
|
|
1691
|
+
const spaceRoom = rect.width - 3 - (roster.spaces.length > geo.spaceCap ? 1 : 0);
|
|
1692
|
+
const agentRoom = rect.width - 3 - (agentList(roster, model.order).length > geo.agentCap ? 1 : 0);
|
|
1693
|
+
const shown = roster.selected ? roster.spaceOf(roster.selected) : void 0;
|
|
1694
|
+
const agents = agentList(roster, model.order);
|
|
1695
|
+
if (geo.headerY !== void 0) at(1, geo.headerY, "spaces", { fg: palette.dim, attrs: ATTR_BOLD });
|
|
1696
|
+
const spaces = roster.spaces.slice(model.scroll.spaces, model.scroll.spaces + geo.spaceCap);
|
|
1697
|
+
spaces.forEach((space, i) => {
|
|
1698
|
+
const y = geo.spaceTop + i * geo.spaceStep;
|
|
1699
|
+
const index = model.scroll.spaces + i;
|
|
1700
|
+
const focused = space === shown;
|
|
1701
|
+
const dot = roster.spaceDot(space);
|
|
1702
|
+
const bg = focused ? navigating ? palette.cursorRow : palette.activeRow : -1;
|
|
1703
|
+
tint(y, geo.spaceStep, bg);
|
|
1704
|
+
if (geo.rail) {
|
|
1705
|
+
at(0, y, railIndex(index), { fg: palette.dim, bg });
|
|
1706
|
+
at(2, y, GLYPHS[dot], {
|
|
1707
|
+
fg: dotColor(dot, palette),
|
|
1708
|
+
bg,
|
|
1709
|
+
...focused ? { attrs: ATTR_BOLD } : {}
|
|
1710
|
+
});
|
|
1711
|
+
return;
|
|
1712
|
+
}
|
|
1713
|
+
at(1, y, GLYPHS[dot], { fg: dotColor(dot, palette), bg });
|
|
1714
|
+
at(3, y, clip(space.name, spaceRoom), {
|
|
1715
|
+
fg: focused ? palette.text : palette.subtext,
|
|
1716
|
+
bg,
|
|
1717
|
+
...focused ? { attrs: ATTR_BOLD } : {}
|
|
1718
|
+
});
|
|
1719
|
+
const note = spaceNote(dot);
|
|
1720
|
+
if (note) {
|
|
1721
|
+
at(3, y + 1, clip(note, spaceRoom), {
|
|
1722
|
+
fg: dot === "blocked" ? palette.red : palette.teal,
|
|
1723
|
+
bg
|
|
1724
|
+
});
|
|
1725
|
+
return;
|
|
1726
|
+
}
|
|
1727
|
+
const git = model.git(space.cwd);
|
|
1728
|
+
if (!git) return;
|
|
1729
|
+
const counts = [];
|
|
1730
|
+
if (git.ahead > 0) counts.push({ text: `\u2191${git.ahead}`, fg: palette.green });
|
|
1731
|
+
if (git.behind > 0) counts.push({ text: `\u2193${git.behind}`, fg: palette.red });
|
|
1732
|
+
const tail = counts.reduce((sum, c) => sum + 1 + c.text.length, 0);
|
|
1733
|
+
const branch = clip(git.branch, spaceRoom - tail);
|
|
1734
|
+
at(3, y + 1, branch, { fg: focused ? palette.mauve : palette.dim, bg });
|
|
1735
|
+
let x = 3 + stringWidth(branch);
|
|
1736
|
+
for (const c of counts) {
|
|
1737
|
+
at(x + 1, y + 1, c.text, { fg: c.fg, bg });
|
|
1738
|
+
x += 1 + c.text.length;
|
|
1739
|
+
}
|
|
1740
|
+
});
|
|
1741
|
+
if (!geo.rail)
|
|
1742
|
+
bar(
|
|
1743
|
+
rect.width - 1,
|
|
1744
|
+
geo.spaceTop,
|
|
1745
|
+
geo.spaceCap * geo.spaceStep,
|
|
1746
|
+
roster.spaces.length,
|
|
1747
|
+
geo.spaceCap,
|
|
1748
|
+
model.scroll.spaces
|
|
1749
|
+
);
|
|
1750
|
+
if (geo.footerY !== void 0) {
|
|
1751
|
+
at(1, geo.footerY, "new", { fg: palette.dim });
|
|
1752
|
+
const menuX = rect.width - 4;
|
|
1753
|
+
at(menuX, geo.footerY, "menu", { fg: palette.dim });
|
|
1754
|
+
const flag = attention(roster);
|
|
1755
|
+
if (flag) at(menuX - 2, geo.footerY, GLYPHS[flag], { fg: dotColor(flag, palette) });
|
|
1756
|
+
}
|
|
1757
|
+
at(0, geo.ruleY, "\u2500".repeat(rect.width), {
|
|
1758
|
+
fg: palette.dim,
|
|
1759
|
+
attrs: ATTR_DIM
|
|
1760
|
+
});
|
|
1761
|
+
if (geo.agentHeaderY !== void 0) {
|
|
1762
|
+
at(1, geo.agentHeaderY, "agents", { fg: palette.dim, attrs: ATTR_BOLD });
|
|
1763
|
+
const label = orderLabel(model.order);
|
|
1764
|
+
at(rect.width - label.length, geo.agentHeaderY, label, { fg: palette.dim });
|
|
1765
|
+
}
|
|
1766
|
+
const visible = agents.slice(model.scroll.agents, model.scroll.agents + geo.agentCap);
|
|
1767
|
+
visible.forEach((entry, i) => {
|
|
1768
|
+
const y = geo.agentTop + i * geo.spaceStep;
|
|
1769
|
+
const index = model.scroll.agents + i;
|
|
1770
|
+
const focused = entry === roster.selected;
|
|
1771
|
+
const dot = entry.dot();
|
|
1772
|
+
const bg = focused ? palette.activeRow : -1;
|
|
1773
|
+
tint(y, geo.spaceStep, bg);
|
|
1774
|
+
if (geo.rail) {
|
|
1775
|
+
at(0, y, railIndex(index), { fg: palette.dim, bg });
|
|
1776
|
+
at(2, y, GLYPHS[dot], {
|
|
1777
|
+
fg: dotColor(dot, palette),
|
|
1778
|
+
bg,
|
|
1779
|
+
...focused ? { attrs: ATTR_BOLD } : {}
|
|
1780
|
+
});
|
|
1781
|
+
return;
|
|
1782
|
+
}
|
|
1783
|
+
at(1, y, GLYPHS[dot], { fg: dotColor(dot, palette), bg });
|
|
1784
|
+
const gone = entry.child?.status === "exited";
|
|
1785
|
+
at(3, y, clip(roster.spaceOf(entry).name, agentRoom), {
|
|
1786
|
+
fg: gone ? palette.dim : focused ? palette.text : palette.subtext,
|
|
1787
|
+
bg,
|
|
1788
|
+
attrs: ATTR_BOLD
|
|
1789
|
+
});
|
|
1790
|
+
const warning = agentWarning(entry);
|
|
1791
|
+
at(3, y + 1, clip(warning ?? agentDetail(roster, entry, agentRoom), agentRoom), {
|
|
1792
|
+
fg: warning ? palette.yellow : palette.dim,
|
|
1793
|
+
bg
|
|
1794
|
+
});
|
|
1795
|
+
});
|
|
1796
|
+
if (!geo.rail)
|
|
1797
|
+
bar(
|
|
1798
|
+
rect.width - 1,
|
|
1799
|
+
geo.agentTop,
|
|
1800
|
+
geo.agentCap * geo.spaceStep,
|
|
1801
|
+
agents.length,
|
|
1802
|
+
geo.agentCap,
|
|
1803
|
+
model.scroll.agents
|
|
1804
|
+
);
|
|
1805
|
+
const top = rect.height - 1 - model.foot.length;
|
|
1806
|
+
if (!geo.rail)
|
|
1807
|
+
model.foot.forEach((line, i) => at(1, top + i, clip(line, rect.width - 1), { fg: palette.dim }));
|
|
1808
|
+
if (geo.rail) at(1, geo.toggleY, "\xBB", { fg: palette.dim });
|
|
1809
|
+
else at(rect.width - 1, geo.toggleY, "\xAB", { fg: palette.dim });
|
|
1810
|
+
}
|
|
1811
|
+
__name(drawSidebar, "drawSidebar");
|
|
1812
|
+
function drawRule(frame, rect, palette) {
|
|
1813
|
+
for (let y = 0; y < rect.height; y++)
|
|
1814
|
+
frame.writeText({ ...rect, height: rect.height }, y, "\u2502", {
|
|
1815
|
+
fg: palette.dim
|
|
1816
|
+
});
|
|
1817
|
+
}
|
|
1818
|
+
__name(drawRule, "drawRule");
|
|
1819
|
+
function endedMessage(ending, prefixName) {
|
|
1820
|
+
const leave = `Leave with ${prefixName} q`;
|
|
1821
|
+
if (ending === "could-not-start") return `This session could not start. ${leave}.`;
|
|
1822
|
+
if (ending === "finished") return `This session has ended. ${leave}.`;
|
|
1823
|
+
return `This session stopped. Its conversation is saved. ${leave}.`;
|
|
1824
|
+
}
|
|
1825
|
+
__name(endedMessage, "endedMessage");
|
|
1826
|
+
|
|
1827
|
+
// src/spaces/tabbar.ts
|
|
1828
|
+
var MIN_TAB_WIDTH = 8;
|
|
1829
|
+
var NEW_TAB_WIDTH = 3;
|
|
1830
|
+
function tabLabel(tab, index) {
|
|
1831
|
+
const base = tab.name ?? String(index + 1);
|
|
1832
|
+
return tab.zoomed ? `${base} Z` : base;
|
|
1833
|
+
}
|
|
1834
|
+
__name(tabLabel, "tabLabel");
|
|
1835
|
+
function layoutTabBar(space, area) {
|
|
1836
|
+
const widths = space.tabs.map(
|
|
1837
|
+
(tab, i) => Math.max(MIN_TAB_WIDTH, stringWidth(tabLabel(tab, i)) + 4)
|
|
1838
|
+
);
|
|
1839
|
+
const room = Math.max(0, area.width - NEW_TAB_WIDTH);
|
|
1840
|
+
const active = space.activeTab ? space.tabs.indexOf(space.activeTab) : -1;
|
|
1841
|
+
const span = /* @__PURE__ */ __name((from, to) => widths.slice(from, to + 1).reduce((sum, w) => sum + w + 1, -1), "span");
|
|
1842
|
+
let first = 0;
|
|
1843
|
+
while (first < active && span(first, active) > room) first++;
|
|
1844
|
+
const chips = [];
|
|
1845
|
+
let x = area.x;
|
|
1846
|
+
for (let i = first; i < space.tabs.length; i++) {
|
|
1847
|
+
const width = widths[i];
|
|
1848
|
+
if (x + width > area.x + room) break;
|
|
1849
|
+
const tab = space.tabs[i];
|
|
1850
|
+
chips.push({
|
|
1851
|
+
tab,
|
|
1852
|
+
rect: { x, y: area.y, width, height: 1 },
|
|
1853
|
+
label: tabLabel(tab, i),
|
|
1854
|
+
active: tab === space.activeTab
|
|
1855
|
+
});
|
|
1856
|
+
x += width + 1;
|
|
1857
|
+
}
|
|
1858
|
+
const plusX = Math.min(x, area.x + area.width - NEW_TAB_WIDTH);
|
|
1859
|
+
const plus = area.width >= NEW_TAB_WIDTH ? { x: plusX, y: area.y, width: NEW_TAB_WIDTH, height: 1 } : void 0;
|
|
1860
|
+
return { chips, plus };
|
|
1861
|
+
}
|
|
1862
|
+
__name(layoutTabBar, "layoutTabBar");
|
|
1863
|
+
function drawTabBar(frame, area, space, palette) {
|
|
1864
|
+
frame.fillRect(area, { bg: palette.panelBg });
|
|
1865
|
+
const bar = layoutTabBar(space, area);
|
|
1866
|
+
for (const chip of bar.chips) {
|
|
1867
|
+
const style = chip.active ? {
|
|
1868
|
+
fg: palette.panelBg,
|
|
1869
|
+
bg: palette.accent,
|
|
1870
|
+
...chip.tab.name ? { attrs: ATTR_BOLD } : {}
|
|
1871
|
+
} : { fg: palette.tabRest, bg: palette.surface };
|
|
1872
|
+
frame.fillRect(chip.rect, style);
|
|
1873
|
+
const pad = Math.max(0, chip.rect.width - stringWidth(chip.label));
|
|
1874
|
+
frame.writeText(chip.rect, 0, `${" ".repeat(Math.floor(pad / 2))}${chip.label}`, style);
|
|
1875
|
+
}
|
|
1876
|
+
if (bar.plus)
|
|
1877
|
+
frame.writeText(bar.plus, 0, " + ", {
|
|
1878
|
+
fg: palette.dimmer,
|
|
1879
|
+
bg: palette.panelBg
|
|
1880
|
+
});
|
|
1881
|
+
}
|
|
1882
|
+
__name(drawTabBar, "drawTabBar");
|
|
1883
|
+
function tabBarTarget(bar, x, y) {
|
|
1884
|
+
const inside = /* @__PURE__ */ __name((r) => y === r.y && x >= r.x && x < r.x + r.width, "inside");
|
|
1885
|
+
for (const chip of bar.chips) if (inside(chip.rect)) return { kind: "tab", tab: chip.tab };
|
|
1886
|
+
if (bar.plus && inside(bar.plus)) return { kind: "new" };
|
|
1887
|
+
return void 0;
|
|
1888
|
+
}
|
|
1889
|
+
__name(tabBarTarget, "tabBarTarget");
|
|
1890
|
+
|
|
1891
|
+
// src/spaces/host.ts
|
|
1892
|
+
var realSchedule = /* @__PURE__ */ __name((run2, ms) => {
|
|
1893
|
+
const timer = setTimeout(run2, ms);
|
|
1894
|
+
return () => clearTimeout(timer);
|
|
1895
|
+
}, "realSchedule");
|
|
1896
|
+
var FRAME_MS = 16;
|
|
1897
|
+
var POLL_MS = 1e3;
|
|
1898
|
+
var RECONCILE_MS = 2500;
|
|
1899
|
+
var SAVE_MS = 250;
|
|
1900
|
+
var QUIT_GRACE_MS = 3e3;
|
|
1901
|
+
var GIT_MS = 5e3;
|
|
1902
|
+
var GIT_STALE_MS = 1500;
|
|
1903
|
+
var DOUBLE_CLICK_MS = 400;
|
|
1904
|
+
var WHEEL_ROWS = 3;
|
|
1905
|
+
var ENTER_SCREEN = "\x1B[?1049h\x1B[2J\x1B[?1000h\x1B[?1002h\x1B[?1006h";
|
|
1906
|
+
var MAX_PAINT_FAILURES = 3;
|
|
1907
|
+
var LEAVE_TO_NATIVE = "\x1B[?1006l\x1B[?1002l\x1B[?1000l\x1B[?1049l";
|
|
1908
|
+
var LEAVE_SCREEN = "\x1B[?1006l\x1B[?1002l\x1B[?1000l\x1B[?2004l\x1B[?25h\x1B[?1049l";
|
|
1909
|
+
var MENU_ITEMS = ["accounts", "add account", "sidebar", "keybinds", "quit"];
|
|
1910
|
+
var CONTEXT_ITEMS = {
|
|
1911
|
+
space: ["Rename", "New tab", "Close"],
|
|
1912
|
+
tab: ["Rename", "Close"],
|
|
1913
|
+
pane: ["Rename", "Split right", "Split down", "Zoom", "Close"]
|
|
1914
|
+
};
|
|
1915
|
+
function defaultIsDirectory(path) {
|
|
1916
|
+
try {
|
|
1917
|
+
return existsSync(path) && statSync(path).isDirectory();
|
|
1918
|
+
} catch {
|
|
1919
|
+
return false;
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
__name(defaultIsDirectory, "defaultIsDirectory");
|
|
1923
|
+
var SpacesHost = class {
|
|
1924
|
+
constructor(options) {
|
|
1925
|
+
this.options = options;
|
|
1926
|
+
this.router = new InputRouter(options.prefix);
|
|
1927
|
+
this.schedule = options.schedule ?? realSchedule;
|
|
1928
|
+
this.palette = paletteFor(options.truecolor ?? advertisesTruecolor(process.env));
|
|
1929
|
+
this.git = new GitCache(
|
|
1930
|
+
options.git ?? gitLookup,
|
|
1931
|
+
() => this.requestRender(),
|
|
1932
|
+
options.now ?? Date.now
|
|
1933
|
+
);
|
|
1934
|
+
this.hidden = options.local !== void 0;
|
|
1935
|
+
const saved = options.restored?.sidebar;
|
|
1936
|
+
if (saved) {
|
|
1937
|
+
this.sidebar = {
|
|
1938
|
+
collapsed: saved.collapsed === true,
|
|
1939
|
+
width: clampSidebarWidth(saved.width ?? SIDEBAR_DEFAULT)
|
|
1940
|
+
};
|
|
1941
|
+
if (saved.split !== void 0) this.split = saved.split;
|
|
1942
|
+
if (saved.order) this.order = saved.order;
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1945
|
+
options;
|
|
1946
|
+
static {
|
|
1947
|
+
__name(this, "SpacesHost");
|
|
1948
|
+
}
|
|
1949
|
+
roster = new Roster();
|
|
1950
|
+
sidebar = DEFAULT_SIDEBAR;
|
|
1951
|
+
split = 0.5;
|
|
1952
|
+
order = "grouped";
|
|
1953
|
+
menu;
|
|
1954
|
+
sidebarScroll = { spaces: 0, agents: 0 };
|
|
1955
|
+
sidebarDrag;
|
|
1956
|
+
lastEdgePress;
|
|
1957
|
+
git;
|
|
1958
|
+
gitStarted = false;
|
|
1959
|
+
cancelGit;
|
|
1960
|
+
confirm;
|
|
1961
|
+
prompt;
|
|
1962
|
+
picker;
|
|
1963
|
+
help;
|
|
1964
|
+
goto;
|
|
1965
|
+
accountList;
|
|
1966
|
+
context;
|
|
1967
|
+
/** A space being dragged in the sidebar, and the place it would land. */
|
|
1968
|
+
reorder;
|
|
1969
|
+
cancelSave;
|
|
1970
|
+
forgetAll = false;
|
|
1971
|
+
notice;
|
|
1972
|
+
pasteOn = false;
|
|
1973
|
+
pending;
|
|
1974
|
+
rendering = Promise.resolve();
|
|
1975
|
+
closed = false;
|
|
1976
|
+
/** True while the real terminal belongs to the local session and nothing of the host is drawn. */
|
|
1977
|
+
hidden = false;
|
|
1978
|
+
/** `split` is the spaces screen; `full` draws the selected child alone on the whole terminal. */
|
|
1979
|
+
view = "split";
|
|
1980
|
+
localEntry;
|
|
1981
|
+
quitting = false;
|
|
1982
|
+
/** Answers the running conversation's wish to end while other sessions are mid-turn. */
|
|
1983
|
+
exitGate;
|
|
1984
|
+
paintFailures = 0;
|
|
1985
|
+
cancelKill;
|
|
1986
|
+
cancelPoll;
|
|
1987
|
+
cancelReconcile;
|
|
1988
|
+
stopWatching;
|
|
1989
|
+
reconciling = false;
|
|
1990
|
+
leaving = [];
|
|
1991
|
+
palette;
|
|
1992
|
+
/** A border being dragged: the split it moves and where on the border it was grabbed. */
|
|
1993
|
+
drag;
|
|
1994
|
+
router;
|
|
1995
|
+
writer = new DiffWriter();
|
|
1996
|
+
schedule;
|
|
1997
|
+
finish;
|
|
1998
|
+
/** Resolves with the exit code once the host has left the terminal alone. */
|
|
1999
|
+
done = new Promise((resolve2) => {
|
|
2000
|
+
this.finish = resolve2;
|
|
2001
|
+
});
|
|
2002
|
+
onData = /* @__PURE__ */ __name((chunk) => this.handleInput(typeof chunk === "string" ? chunk : chunk.toString("utf8")), "onData");
|
|
2003
|
+
onResize = /* @__PURE__ */ __name(() => this.relayout(), "onResize");
|
|
2004
|
+
/** If the process ends without a clean close, still hand the terminal back and stop the sessions. */
|
|
2005
|
+
onProcessExit = /* @__PURE__ */ __name(() => {
|
|
2006
|
+
if (this.closed) return;
|
|
2007
|
+
this.cancelSave?.();
|
|
2008
|
+
this.cancelSave = void 0;
|
|
2009
|
+
this.writeLayout();
|
|
2010
|
+
this.closed = true;
|
|
2011
|
+
try {
|
|
2012
|
+
this.options.input.setRawMode?.(false);
|
|
2013
|
+
if (!this.hidden) this.options.output.write(LEAVE_SCREEN);
|
|
2014
|
+
} catch {
|
|
2015
|
+
}
|
|
2016
|
+
for (const session of this.everyChild()) {
|
|
2017
|
+
if (session.local) continue;
|
|
2018
|
+
try {
|
|
2019
|
+
session.stop("SIGHUP");
|
|
2020
|
+
} catch {
|
|
2021
|
+
}
|
|
2022
|
+
}
|
|
2023
|
+
}, "onProcessExit");
|
|
2024
|
+
start() {
|
|
2025
|
+
const { input, output, local } = this.options;
|
|
2026
|
+
if (!local) output.write(ENTER_SCREEN);
|
|
2027
|
+
input.setEncoding?.("utf8");
|
|
2028
|
+
input.setRawMode?.(true);
|
|
2029
|
+
input.resume?.();
|
|
2030
|
+
input.on("data", this.onData);
|
|
2031
|
+
output.on("resize", this.onResize);
|
|
2032
|
+
process.once("exit", this.onProcessExit);
|
|
2033
|
+
if (local) this.seedLocal(local);
|
|
2034
|
+
else this.open(this.options.restored ? this.restore(this.options.restored) : this.fresh());
|
|
2035
|
+
this.armPoll();
|
|
2036
|
+
this.armReconcile();
|
|
2037
|
+
this.stopWatching = this.options.peers?.watch?.(() => this.readStatus());
|
|
2038
|
+
this.requestRender();
|
|
2039
|
+
}
|
|
2040
|
+
/**
|
|
2041
|
+
* Brings back the saved spaces and makes the running conversation one of the
|
|
2042
|
+
* panes: the one that carries its conversation id, or else a new tab in the
|
|
2043
|
+
* space of its folder. Nothing else is started here.
|
|
2044
|
+
*/
|
|
2045
|
+
seedLocal(local) {
|
|
2046
|
+
const layout = this.options.restored;
|
|
2047
|
+
if (layout) this.restoreSpaces(layout);
|
|
2048
|
+
const id = local.conversationId();
|
|
2049
|
+
const carried = id ? this.roster.entries.find((e) => (e.conversationId ?? e.resume) === id) : void 0;
|
|
2050
|
+
let entry = carried;
|
|
2051
|
+
if (!entry) {
|
|
2052
|
+
const { cwd, name } = this.options.folder;
|
|
2053
|
+
const space = this.roster.spaces.find((s) => s.cwd === cwd) ?? this.roster.addSpace(cwd, name);
|
|
2054
|
+
entry = this.newTabIn(space);
|
|
2055
|
+
}
|
|
2056
|
+
entry.child = local.session;
|
|
2057
|
+
entry.resume = void 0;
|
|
2058
|
+
entry.first = false;
|
|
2059
|
+
entry.verifyFolder = false;
|
|
2060
|
+
entry.folderMissing = false;
|
|
2061
|
+
entry.openElsewhere = false;
|
|
2062
|
+
entry.checking = false;
|
|
2063
|
+
if (id) entry.conversationId = id;
|
|
2064
|
+
const adopted = entry;
|
|
2065
|
+
local.session.observe(() => this.childChanged(adopted));
|
|
2066
|
+
this.localEntry = entry;
|
|
2067
|
+
this.roster.select(entry);
|
|
2068
|
+
this.roster.update(entry);
|
|
2069
|
+
this.persist();
|
|
2070
|
+
}
|
|
2071
|
+
/** True while the spaces screen is on the terminal. */
|
|
2072
|
+
get visible() {
|
|
2073
|
+
return !this.hidden && !this.closed;
|
|
2074
|
+
}
|
|
2075
|
+
/** Puts the spaces screen up, with the running conversation selected and the keyboard on the sidebar. */
|
|
2076
|
+
openSpaces() {
|
|
2077
|
+
const entry = this.localEntry;
|
|
2078
|
+
if (this.closed || !entry) return;
|
|
2079
|
+
if (this.hidden) {
|
|
2080
|
+
this.hidden = false;
|
|
2081
|
+
this.options.output.write(ENTER_SCREEN);
|
|
2082
|
+
this.pasteOn = false;
|
|
2083
|
+
this.writer.invalidate();
|
|
2084
|
+
}
|
|
2085
|
+
this.view = "split";
|
|
2086
|
+
this.dismiss();
|
|
2087
|
+
this.roster.select(entry);
|
|
2088
|
+
this.fit();
|
|
2089
|
+
const size = this.paneSize(entry);
|
|
2090
|
+
this.options.local?.session.attach(size.cols, size.rows);
|
|
2091
|
+
this.startShown();
|
|
2092
|
+
this.router.enterNavigate();
|
|
2093
|
+
this.persist();
|
|
2094
|
+
this.requestRender();
|
|
2095
|
+
}
|
|
2096
|
+
/** Hands the terminal to the running conversation: leaves the alternate screen and lets it repaint. */
|
|
2097
|
+
openNative() {
|
|
2098
|
+
const local = this.options.local;
|
|
2099
|
+
const entry = this.localEntry;
|
|
2100
|
+
if (this.hidden || !local || !entry) return;
|
|
2101
|
+
this.roster.select(entry);
|
|
2102
|
+
this.hidden = true;
|
|
2103
|
+
this.view = "split";
|
|
2104
|
+
this.dismiss();
|
|
2105
|
+
this.router.focus();
|
|
2106
|
+
this.pending?.();
|
|
2107
|
+
this.pending = void 0;
|
|
2108
|
+
this.options.output.write(LEAVE_TO_NATIVE);
|
|
2109
|
+
this.pasteOn = false;
|
|
2110
|
+
local.session.detach();
|
|
2111
|
+
}
|
|
2112
|
+
/**
|
|
2113
|
+
* The conversation is about to unmount: gives the main screen back and has the conversation print
|
|
2114
|
+
* its whole history there, so Ink's last frame lands on a screen that is already right. True when
|
|
2115
|
+
* the spaces screen was up and has been left.
|
|
2116
|
+
*/
|
|
2117
|
+
releaseTerminal() {
|
|
2118
|
+
if (this.closed || this.hidden || !this.localEntry || !this.options.local) return false;
|
|
2119
|
+
this.openNative();
|
|
2120
|
+
return true;
|
|
2121
|
+
}
|
|
2122
|
+
/** Moves the keyboard from a pane to the sidebar of the spaces screen. */
|
|
2123
|
+
focusSidebar() {
|
|
2124
|
+
if (this.closed || this.hidden || this.view === "full") return;
|
|
2125
|
+
this.router.enterNavigate();
|
|
2126
|
+
this.requestRender();
|
|
2127
|
+
}
|
|
2128
|
+
/** What a hosted session asked of the host through its terminal. */
|
|
2129
|
+
childSignal(entry, signal) {
|
|
2130
|
+
if (this.closed || this.hidden || signal !== "zoom-out") return;
|
|
2131
|
+
if (this.view === "full") {
|
|
2132
|
+
if (this.roster.selected !== entry) return;
|
|
2133
|
+
this.view = "split";
|
|
2134
|
+
this.fit();
|
|
2135
|
+
this.router.enterNavigate();
|
|
2136
|
+
this.writer.invalidate();
|
|
2137
|
+
this.requestRender();
|
|
2138
|
+
return;
|
|
2139
|
+
}
|
|
2140
|
+
if (this.roster.selected === entry && this.router.current === "terminal") {
|
|
2141
|
+
this.router.enterNavigate();
|
|
2142
|
+
this.requestRender();
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
// --- sessions --------------------------------------------------------------
|
|
2146
|
+
/** The first run: the current folder as a space with the session the command started. */
|
|
2147
|
+
fresh() {
|
|
2148
|
+
const space = this.roster.addSpace(this.options.folder.cwd, this.options.folder.name);
|
|
2149
|
+
const entry = this.newTabIn(space);
|
|
2150
|
+
entry.first = true;
|
|
2151
|
+
for (const listed of this.options.listed ?? []) {
|
|
2152
|
+
const other = this.roster.addSpace(listed.cwd, listed.name);
|
|
2153
|
+
for (let i = 0; i < listed.sessions; i++) this.newTabIn(other);
|
|
2154
|
+
}
|
|
2155
|
+
return entry;
|
|
2156
|
+
}
|
|
2157
|
+
/**
|
|
2158
|
+
* Brings back the previous run's spaces, tabs and panes, none of them started.
|
|
2159
|
+
* The one shown is where focus was, unless the command carries its own options
|
|
2160
|
+
* or its folder is new, which start a fresh session of their own.
|
|
2161
|
+
*/
|
|
2162
|
+
restore(layout) {
|
|
2163
|
+
this.restoreSpaces(layout);
|
|
2164
|
+
const folder = this.roster.spaces.find((s) => s.cwd === this.options.folder.cwd);
|
|
2165
|
+
if (this.options.freshFirst || !folder) {
|
|
2166
|
+
const space = folder ?? this.roster.addSpace(this.options.folder.cwd, this.options.folder.name);
|
|
2167
|
+
const entry = this.newTabIn(space);
|
|
2168
|
+
entry.first = true;
|
|
2169
|
+
return entry;
|
|
2170
|
+
}
|
|
2171
|
+
const focused = layout.focus !== void 0 ? this.roster.spaces[layout.focus.space]?.activeTab?.focus : void 0;
|
|
2172
|
+
return focused ?? folder.activeTab?.focus ?? this.newTabIn(folder);
|
|
2173
|
+
}
|
|
2174
|
+
restoreSpaces(layout) {
|
|
2175
|
+
const isDirectory = this.options.isDirectory ?? defaultIsDirectory;
|
|
2176
|
+
for (const saved of layout.spaces) {
|
|
2177
|
+
const space = this.roster.addSpace(saved.cwd, saved.name);
|
|
2178
|
+
const found = isDirectory(saved.cwd);
|
|
2179
|
+
if (saved.lastAccount) space.lastAccount = saved.lastAccount;
|
|
2180
|
+
for (const savedTab of saved.tabs) this.restoreTab(space, savedTab, found);
|
|
2181
|
+
const active = saved.activeTab !== void 0 ? space.tabs[saved.activeTab] : void 0;
|
|
2182
|
+
space.activeTab = active ?? space.tabs[0];
|
|
2183
|
+
}
|
|
2184
|
+
}
|
|
2185
|
+
restoreTab(space, saved, found) {
|
|
2186
|
+
const build = /* @__PURE__ */ __name((node) => {
|
|
2187
|
+
if (!("session" in node))
|
|
2188
|
+
return {
|
|
2189
|
+
kind: "split",
|
|
2190
|
+
dir: node.split,
|
|
2191
|
+
ratio: node.ratio,
|
|
2192
|
+
a: build(node.a),
|
|
2193
|
+
b: build(node.b)
|
|
2194
|
+
};
|
|
2195
|
+
const item = node.session;
|
|
2196
|
+
const entry = this.addEntry(space, item.label);
|
|
2197
|
+
if (item.conversationId) {
|
|
2198
|
+
entry.conversationId = item.conversationId;
|
|
2199
|
+
entry.resume = item.conversationId;
|
|
2200
|
+
}
|
|
2201
|
+
entry.verifyFolder = true;
|
|
2202
|
+
entry.folderMissing = !found;
|
|
2203
|
+
if (item.account) entry.account = item.account;
|
|
2204
|
+
if (item.pickedAccount) entry.pickedAccount = item.pickedAccount;
|
|
2205
|
+
return leaf(entry);
|
|
2206
|
+
}, "build");
|
|
2207
|
+
const root = build(saved.tree);
|
|
2208
|
+
const panes = leaves(root);
|
|
2209
|
+
this.roster.addTree(
|
|
2210
|
+
space,
|
|
2211
|
+
root,
|
|
2212
|
+
panes[saved.focus ?? 0] ?? panes[0],
|
|
2213
|
+
saved.name,
|
|
2214
|
+
saved.zoomed === true
|
|
2215
|
+
);
|
|
2216
|
+
}
|
|
2217
|
+
addEntry(space, label) {
|
|
2218
|
+
const entry = this.roster.addSession(space, this.options.newSlot?.() ?? randomUUID(), label);
|
|
2219
|
+
this.persist();
|
|
2220
|
+
return entry;
|
|
2221
|
+
}
|
|
2222
|
+
/** A session in a tab of its own, after the space's other tabs. */
|
|
2223
|
+
newTabIn(space) {
|
|
2224
|
+
const entry = this.addEntry(space);
|
|
2225
|
+
this.roster.addTab(space, entry);
|
|
2226
|
+
return entry;
|
|
2227
|
+
}
|
|
2228
|
+
layout() {
|
|
2229
|
+
const { columns, rows } = this.options.output;
|
|
2230
|
+
if (this.view === "full") {
|
|
2231
|
+
const whole = { x: 0, y: 0, width: columns, height: rows };
|
|
2232
|
+
return {
|
|
2233
|
+
sidebar: void 0,
|
|
2234
|
+
rail: false,
|
|
2235
|
+
rule: void 0,
|
|
2236
|
+
main: whole,
|
|
2237
|
+
tabBar: { ...whole, height: 1 },
|
|
2238
|
+
panes: whole
|
|
2239
|
+
};
|
|
2240
|
+
}
|
|
2241
|
+
return computeLayout(columns, rows, this.sidebar);
|
|
2242
|
+
}
|
|
2243
|
+
/** The sidebar's view of the host: what it needs to draw and to find what a click lands on. */
|
|
2244
|
+
sidebarModel(rail) {
|
|
2245
|
+
return {
|
|
2246
|
+
roster: this.roster,
|
|
2247
|
+
mode: this.router.current === "navigate" ? "navigate" : "terminal",
|
|
2248
|
+
foot: [],
|
|
2249
|
+
scroll: this.sidebarScroll,
|
|
2250
|
+
palette: this.palette,
|
|
2251
|
+
git: /* @__PURE__ */ __name((cwd) => this.git.get(cwd), "git"),
|
|
2252
|
+
order: this.order,
|
|
2253
|
+
split: this.split,
|
|
2254
|
+
rail
|
|
2255
|
+
};
|
|
2256
|
+
}
|
|
2257
|
+
/** Where the shown tab's panes are. */
|
|
2258
|
+
placement() {
|
|
2259
|
+
const tab = this.roster.shownTab;
|
|
2260
|
+
const selected = this.roster.selected;
|
|
2261
|
+
if (this.view === "full" && selected) {
|
|
2262
|
+
const whole = this.layout().panes;
|
|
2263
|
+
return {
|
|
2264
|
+
panes: [{ entry: selected, outer: whole, inner: whole }],
|
|
2265
|
+
dividers: [],
|
|
2266
|
+
bordered: false
|
|
2267
|
+
};
|
|
2268
|
+
}
|
|
2269
|
+
return tab ? placeTab(tab, this.layout().panes) : void 0;
|
|
2270
|
+
}
|
|
2271
|
+
/** What a session's terminal is given: its pane's inside, or the whole pane area for one that is not shown. */
|
|
2272
|
+
paneSize(entry) {
|
|
2273
|
+
const pane = this.placement()?.panes.find((p) => p.entry === entry);
|
|
2274
|
+
const rect = pane?.inner ?? this.layout().panes;
|
|
2275
|
+
return { cols: Math.max(1, rect.width), rows: Math.max(1, rect.height) };
|
|
2276
|
+
}
|
|
2277
|
+
/** Gives each pane's terminal the size of its pane. */
|
|
2278
|
+
fit() {
|
|
2279
|
+
for (const pane of this.placement()?.panes ?? [])
|
|
2280
|
+
pane.entry.child?.resize(Math.max(1, pane.inner.width), Math.max(1, pane.inner.height));
|
|
2281
|
+
}
|
|
2282
|
+
/** Starts the entry's terminal if it has none yet. */
|
|
2283
|
+
ensureStarted(entry) {
|
|
2284
|
+
if (entry.child || this.closed || entry.checking) return;
|
|
2285
|
+
if (entry.verifyFolder) {
|
|
2286
|
+
const found = (this.options.isDirectory ?? defaultIsDirectory)(this.roster.spaceOf(entry).cwd);
|
|
2287
|
+
if (entry.folderMissing === found) {
|
|
2288
|
+
entry.folderMissing = !found;
|
|
2289
|
+
this.requestRender();
|
|
2290
|
+
}
|
|
2291
|
+
if (!found) return;
|
|
2292
|
+
}
|
|
2293
|
+
const guard = this.options.inUseElsewhere;
|
|
2294
|
+
if (entry.resume && guard) {
|
|
2295
|
+
entry.checking = true;
|
|
2296
|
+
const space = this.roster.spaceOf(entry);
|
|
2297
|
+
void guard({ cwd: space.cwd, conversationId: entry.resume }).catch(() => false).then((busy) => {
|
|
2298
|
+
entry.checking = false;
|
|
2299
|
+
if (this.closed || !this.roster.entries.includes(entry)) return;
|
|
2300
|
+
entry.openElsewhere = busy;
|
|
2301
|
+
if (!busy) this.spawn(entry);
|
|
2302
|
+
this.requestRender();
|
|
2303
|
+
});
|
|
2304
|
+
this.requestRender();
|
|
2305
|
+
return;
|
|
2306
|
+
}
|
|
2307
|
+
this.spawn(entry);
|
|
2308
|
+
}
|
|
2309
|
+
spawn(entry) {
|
|
2310
|
+
if (entry.child || this.closed) return;
|
|
2311
|
+
const space = this.roster.spaceOf(entry);
|
|
2312
|
+
const spec = this.options.spec({
|
|
2313
|
+
cwd: space.cwd,
|
|
2314
|
+
slot: entry.slot,
|
|
2315
|
+
first: entry.first,
|
|
2316
|
+
...entry.pickedAccount ? { account: entry.pickedAccount } : {},
|
|
2317
|
+
...entry.account ? { accountLabel: entry.account } : {},
|
|
2318
|
+
...entry.resume ? { resume: entry.resume } : {}
|
|
2319
|
+
});
|
|
2320
|
+
entry.first = false;
|
|
2321
|
+
entry.resume = void 0;
|
|
2322
|
+
const child = new ChildSession(
|
|
2323
|
+
entry.label,
|
|
2324
|
+
spec,
|
|
2325
|
+
this.paneSize(entry),
|
|
2326
|
+
() => this.childChanged(entry),
|
|
2327
|
+
this.options.kill,
|
|
2328
|
+
(signal) => this.childSignal(entry, signal)
|
|
2329
|
+
);
|
|
2330
|
+
entry.child = child;
|
|
2331
|
+
child.start(this.options.binding);
|
|
2332
|
+
this.roster.update(entry);
|
|
2333
|
+
}
|
|
2334
|
+
/** Shows a session and starts the panes of its tab that have not been opened before. */
|
|
2335
|
+
open(entry) {
|
|
2336
|
+
this.show(entry);
|
|
2337
|
+
const tab = this.roster.tabOf(entry);
|
|
2338
|
+
for (const pane of tab ? leaves(tab.root) : [entry]) this.ensureStarted(pane);
|
|
2339
|
+
this.router.focus();
|
|
2340
|
+
this.requestRender();
|
|
2341
|
+
}
|
|
2342
|
+
/** Shows a session without starting it. */
|
|
2343
|
+
show(entry) {
|
|
2344
|
+
if (this.view === "full" && entry.child?.local) this.view = "split";
|
|
2345
|
+
this.roster.select(entry);
|
|
2346
|
+
if (this.gitStarted) this.git.refresh(this.roster.spaceOf(entry).cwd, GIT_STALE_MS);
|
|
2347
|
+
this.fit();
|
|
2348
|
+
this.revealSelected();
|
|
2349
|
+
this.persist();
|
|
2350
|
+
}
|
|
2351
|
+
childChanged(entry) {
|
|
2352
|
+
this.roster.update(entry);
|
|
2353
|
+
for (let i = this.leaving.length - 1; i >= 0; i--) {
|
|
2354
|
+
const gone = this.leaving[i];
|
|
2355
|
+
if (gone?.status === "exited") {
|
|
2356
|
+
gone.dispose();
|
|
2357
|
+
this.leaving.splice(i, 1);
|
|
2358
|
+
}
|
|
2359
|
+
}
|
|
2360
|
+
if (this.view === "full" && !this.hidden && this.roster.selected === entry && entry.child?.status === "exited") {
|
|
2361
|
+
this.view = "split";
|
|
2362
|
+
this.fit();
|
|
2363
|
+
this.router.enterNavigate();
|
|
2364
|
+
this.writer.invalidate();
|
|
2365
|
+
}
|
|
2366
|
+
if (this.quitting && this.everyChild().every((c) => c.status === "exited")) this.close();
|
|
2367
|
+
else this.requestRender();
|
|
2368
|
+
}
|
|
2369
|
+
everyChild() {
|
|
2370
|
+
const own = this.roster.entries.flatMap((e) => e.child ? [e.child] : []);
|
|
2371
|
+
return [...own, ...this.leaving];
|
|
2372
|
+
}
|
|
2373
|
+
relayout() {
|
|
2374
|
+
if (this.closed) return;
|
|
2375
|
+
this.fit();
|
|
2376
|
+
if (this.hidden) return;
|
|
2377
|
+
this.writer.invalidate();
|
|
2378
|
+
this.requestRender();
|
|
2379
|
+
}
|
|
2380
|
+
// --- status feed -----------------------------------------------------------
|
|
2381
|
+
armPoll() {
|
|
2382
|
+
if (!this.options.peers || this.closed) return;
|
|
2383
|
+
this.cancelPoll = this.schedule(() => {
|
|
2384
|
+
this.readStatus();
|
|
2385
|
+
this.armPoll();
|
|
2386
|
+
}, POLL_MS);
|
|
2387
|
+
}
|
|
2388
|
+
armReconcile() {
|
|
2389
|
+
if (!this.options.peers || this.closed) return;
|
|
2390
|
+
this.cancelReconcile = this.schedule(() => {
|
|
2391
|
+
void this.reconcile().finally(() => this.armReconcile());
|
|
2392
|
+
}, RECONCILE_MS);
|
|
2393
|
+
}
|
|
2394
|
+
/** Takes what each session's terminal last wrote about itself. */
|
|
2395
|
+
readStatus() {
|
|
2396
|
+
const peers = this.options.peers;
|
|
2397
|
+
if (!peers || this.closed) return;
|
|
2398
|
+
let records;
|
|
2399
|
+
try {
|
|
2400
|
+
records = peers.records();
|
|
2401
|
+
} catch {
|
|
2402
|
+
return;
|
|
2403
|
+
}
|
|
2404
|
+
let changed = false;
|
|
2405
|
+
for (const entry of this.roster.entries) {
|
|
2406
|
+
if (!entry.child || entry.child.status === "exited") continue;
|
|
2407
|
+
const record = entry.child.local ? recordForPid(records, entry.child.pid) : recordForSlot(records, entry.slot, entry.child.pid);
|
|
2408
|
+
if (!record) continue;
|
|
2409
|
+
if (entry.reported !== record.state) changed = true;
|
|
2410
|
+
entry.reported = record.state;
|
|
2411
|
+
if (entry.account !== record.account) {
|
|
2412
|
+
changed = true;
|
|
2413
|
+
this.rememberAccount(entry, record.account);
|
|
2414
|
+
}
|
|
2415
|
+
entry.account = record.account;
|
|
2416
|
+
if (entry.limited !== (record.limited === true)) changed = true;
|
|
2417
|
+
entry.limited = record.limited === true;
|
|
2418
|
+
entry.limitedUntil = record.limited === true ? record.limitedUntil : void 0;
|
|
2419
|
+
if (record.conversationId && entry.conversationId !== record.conversationId) {
|
|
2420
|
+
entry.conversationId = record.conversationId;
|
|
2421
|
+
this.persist();
|
|
2422
|
+
}
|
|
2423
|
+
this.roster.update(entry);
|
|
2424
|
+
}
|
|
2425
|
+
if (changed) {
|
|
2426
|
+
this.persist();
|
|
2427
|
+
this.requestRender();
|
|
2428
|
+
}
|
|
2429
|
+
}
|
|
2430
|
+
/** A session that moved to another account makes that account the one its space offers first. */
|
|
2431
|
+
rememberAccount(entry, label) {
|
|
2432
|
+
const space = this.roster.spaceOf(entry);
|
|
2433
|
+
const matches = (this.options.accounts?.() ?? []).filter((a) => a.label === label);
|
|
2434
|
+
const found = label !== void 0 && matches.length === 1 ? matches[0] : void 0;
|
|
2435
|
+
entry.pickedAccount = found?.id;
|
|
2436
|
+
if (label === void 0) delete space.lastAccount;
|
|
2437
|
+
else if (found) space.lastAccount = found.id;
|
|
2438
|
+
}
|
|
2439
|
+
/** Asks each terminal its state directly, so a change that was never written is still seen. */
|
|
2440
|
+
async reconcile() {
|
|
2441
|
+
const peers = this.options.peers;
|
|
2442
|
+
if (!peers || this.closed || this.reconciling) return;
|
|
2443
|
+
this.reconciling = true;
|
|
2444
|
+
try {
|
|
2445
|
+
let records;
|
|
2446
|
+
try {
|
|
2447
|
+
records = peers.records();
|
|
2448
|
+
} catch {
|
|
2449
|
+
return;
|
|
2450
|
+
}
|
|
2451
|
+
const asks = this.roster.entries.flatMap((entry) => {
|
|
2452
|
+
if (!entry.child || entry.child.status === "exited") return [];
|
|
2453
|
+
const record = entry.child.local ? recordForPid(records, entry.child.pid) : recordForSlot(records, entry.slot, entry.child.pid);
|
|
2454
|
+
return record ? [{ entry, record }] : [];
|
|
2455
|
+
});
|
|
2456
|
+
await Promise.all(
|
|
2457
|
+
asks.map(async ({ entry, record }) => {
|
|
2458
|
+
const state = await peers.ping(record);
|
|
2459
|
+
if (state === void 0 || this.closed) return;
|
|
2460
|
+
if (!this.roster.entries.includes(entry) || entry.reported === state) return;
|
|
2461
|
+
entry.reported = state;
|
|
2462
|
+
this.roster.update(entry);
|
|
2463
|
+
this.requestRender();
|
|
2464
|
+
})
|
|
2465
|
+
);
|
|
2466
|
+
} finally {
|
|
2467
|
+
this.reconciling = false;
|
|
2468
|
+
}
|
|
2469
|
+
}
|
|
2470
|
+
// --- input -----------------------------------------------------------------
|
|
2471
|
+
/** Called with what the keyboard sent. */
|
|
2472
|
+
handleInput(chunk) {
|
|
2473
|
+
if (this.closed || this.hidden) return;
|
|
2474
|
+
for (const action of this.router.feed(chunk)) {
|
|
2475
|
+
if (action.type === "write") this.writeToSelected(action.data);
|
|
2476
|
+
else if (action.type === "mode") {
|
|
2477
|
+
if (action.mode === "terminal" && !this.captured()) this.startShown();
|
|
2478
|
+
this.requestRender();
|
|
2479
|
+
} else if (action.type === "mouse") this.mouse(action.mouse);
|
|
2480
|
+
else this.key(action.from, action.key);
|
|
2481
|
+
}
|
|
2482
|
+
}
|
|
2483
|
+
/** Starts the panes of the shown tab that have not been opened before. */
|
|
2484
|
+
startShown() {
|
|
2485
|
+
const tab = this.roster.shownTab;
|
|
2486
|
+
for (const pane of tab ? leaves(tab.root) : []) this.ensureStarted(pane);
|
|
2487
|
+
}
|
|
2488
|
+
writeToSelected(data) {
|
|
2489
|
+
const entry = this.roster.selected;
|
|
2490
|
+
if (!entry) return;
|
|
2491
|
+
this.ensureStarted(entry);
|
|
2492
|
+
entry.scrollBack = 0;
|
|
2493
|
+
entry.child?.write(data);
|
|
2494
|
+
}
|
|
2495
|
+
/** A key the host reads: an answer, a name being typed, a mode's key, or the key after the prefix. */
|
|
2496
|
+
key(from, key) {
|
|
2497
|
+
this.notice = void 0;
|
|
2498
|
+
if (this.context) this.contextKey(key);
|
|
2499
|
+
else if (this.menu) this.menuKey(key);
|
|
2500
|
+
else if (this.help) this.helpKey(key);
|
|
2501
|
+
else if (this.accountList) this.accountsKey(key);
|
|
2502
|
+
else if (this.goto) this.gotoKey(key);
|
|
2503
|
+
else if (this.picker) this.pickerKey(key);
|
|
2504
|
+
else if (this.prompt) this.promptKey(key);
|
|
2505
|
+
else if (this.confirm) this.confirmKey(key);
|
|
2506
|
+
else if (from === "prefix") this.command(key);
|
|
2507
|
+
else if (from === "resize") this.resizeKey(key);
|
|
2508
|
+
else if (from === "navigate") this.navigateKey(key);
|
|
2509
|
+
this.router.capture(this.captured());
|
|
2510
|
+
this.requestRender();
|
|
2511
|
+
}
|
|
2512
|
+
/** The key after the prefix: whatever the key map binds it to. */
|
|
2513
|
+
command(key) {
|
|
2514
|
+
const binding = bindingFor(key);
|
|
2515
|
+
if (binding) this.run(binding.action, key);
|
|
2516
|
+
}
|
|
2517
|
+
run(action, key) {
|
|
2518
|
+
const entry = this.roster.selected;
|
|
2519
|
+
if (!entry) return;
|
|
2520
|
+
switch (action) {
|
|
2521
|
+
case "help":
|
|
2522
|
+
this.help = { scroll: 0 };
|
|
2523
|
+
return;
|
|
2524
|
+
case "menu":
|
|
2525
|
+
this.openMenu();
|
|
2526
|
+
return;
|
|
2527
|
+
case "goto": {
|
|
2528
|
+
const rows = gotoRows(this.roster);
|
|
2529
|
+
this.goto = { query: "", index: currentRow(rows, entry), scroll: 0 };
|
|
2530
|
+
return;
|
|
2531
|
+
}
|
|
2532
|
+
case "quit":
|
|
2533
|
+
this.askQuit();
|
|
2534
|
+
return;
|
|
2535
|
+
case "new-space":
|
|
2536
|
+
this.prompt = { kind: "new-space", value: this.roster.spaceOf(entry).cwd };
|
|
2537
|
+
return;
|
|
2538
|
+
case "open-folder":
|
|
2539
|
+
this.askFolder();
|
|
2540
|
+
return;
|
|
2541
|
+
case "rename-space":
|
|
2542
|
+
this.askName("rename-space", this.roster.spaceOf(entry).name);
|
|
2543
|
+
return;
|
|
2544
|
+
case "close-space":
|
|
2545
|
+
this.confirm = "close-space";
|
|
2546
|
+
return;
|
|
2547
|
+
// The router starts these two modes itself; there is nothing more to do.
|
|
2548
|
+
case "space-mode":
|
|
2549
|
+
case "resize-mode":
|
|
2550
|
+
return;
|
|
2551
|
+
case "sidebar":
|
|
2552
|
+
this.toggleSidebar();
|
|
2553
|
+
return;
|
|
2554
|
+
case "new-tab":
|
|
2555
|
+
this.newTab();
|
|
2556
|
+
return;
|
|
2557
|
+
case "rename-tab":
|
|
2558
|
+
this.askName("rename-tab", this.shownTabLabel());
|
|
2559
|
+
return;
|
|
2560
|
+
case "close-tab":
|
|
2561
|
+
this.closeTab();
|
|
2562
|
+
return;
|
|
2563
|
+
case "prev-tab":
|
|
2564
|
+
this.stepTab(-1);
|
|
2565
|
+
return;
|
|
2566
|
+
case "next-tab":
|
|
2567
|
+
this.stepTab(1);
|
|
2568
|
+
return;
|
|
2569
|
+
case "tab-number":
|
|
2570
|
+
if (key?.kind === "char") this.gotoTab(Number(key.char) - 1);
|
|
2571
|
+
return;
|
|
2572
|
+
case "split-side":
|
|
2573
|
+
this.splitFocused("side");
|
|
2574
|
+
return;
|
|
2575
|
+
case "split-stack":
|
|
2576
|
+
this.splitFocused("stack");
|
|
2577
|
+
return;
|
|
2578
|
+
case "focus-left":
|
|
2579
|
+
this.moveFocus("left");
|
|
2580
|
+
return;
|
|
2581
|
+
case "focus-down":
|
|
2582
|
+
this.moveFocus("down");
|
|
2583
|
+
return;
|
|
2584
|
+
case "focus-up":
|
|
2585
|
+
this.moveFocus("up");
|
|
2586
|
+
return;
|
|
2587
|
+
case "focus-right":
|
|
2588
|
+
this.moveFocus("right");
|
|
2589
|
+
return;
|
|
2590
|
+
case "swap-left":
|
|
2591
|
+
this.swapFocused("left");
|
|
2592
|
+
return;
|
|
2593
|
+
case "swap-down":
|
|
2594
|
+
this.swapFocused("down");
|
|
2595
|
+
return;
|
|
2596
|
+
case "swap-up":
|
|
2597
|
+
this.swapFocused("up");
|
|
2598
|
+
return;
|
|
2599
|
+
case "swap-right":
|
|
2600
|
+
this.swapFocused("right");
|
|
2601
|
+
return;
|
|
2602
|
+
case "next-pane":
|
|
2603
|
+
this.cyclePane(1);
|
|
2604
|
+
return;
|
|
2605
|
+
case "prev-pane":
|
|
2606
|
+
this.cyclePane(-1);
|
|
2607
|
+
return;
|
|
2608
|
+
case "close-pane":
|
|
2609
|
+
this.closePane();
|
|
2610
|
+
return;
|
|
2611
|
+
case "zoom":
|
|
2612
|
+
this.toggleZoom();
|
|
2613
|
+
return;
|
|
2614
|
+
case "rename-pane":
|
|
2615
|
+
this.askName("rename-session", entry.label);
|
|
2616
|
+
return;
|
|
2617
|
+
default: {
|
|
2618
|
+
const unhandled = action;
|
|
2619
|
+
void unhandled;
|
|
2620
|
+
}
|
|
2621
|
+
}
|
|
2622
|
+
}
|
|
2623
|
+
/** The name the shown tab was given; a tab without one has none to edit. */
|
|
2624
|
+
shownTabLabel() {
|
|
2625
|
+
return this.roster.shownTab?.name ?? "";
|
|
2626
|
+
}
|
|
2627
|
+
/**
|
|
2628
|
+
* The running conversation is about to end (`/exit`, ctrl+c twice). With no other session
|
|
2629
|
+
* mid-turn it may go at once; otherwise the spaces screen comes up with the quit question
|
|
2630
|
+
* and the answer decides.
|
|
2631
|
+
*/
|
|
2632
|
+
askLocalExit() {
|
|
2633
|
+
const busy = this.roster.entries.some((e) => {
|
|
2634
|
+
if (!e.child || e.child.local || e.child.status === "exited") return false;
|
|
2635
|
+
const activity = e.activity();
|
|
2636
|
+
return activity === "working" || activity === "needs-approval";
|
|
2637
|
+
});
|
|
2638
|
+
if (this.closed || this.quitting || !this.localEntry || !busy) return Promise.resolve(true);
|
|
2639
|
+
this.exitGate?.(false);
|
|
2640
|
+
return new Promise((resolve2) => {
|
|
2641
|
+
if (this.hidden) this.openSpaces();
|
|
2642
|
+
else this.dismiss();
|
|
2643
|
+
this.exitGate = resolve2;
|
|
2644
|
+
this.confirm = "quit";
|
|
2645
|
+
this.router.capture(true);
|
|
2646
|
+
this.requestRender();
|
|
2647
|
+
});
|
|
2648
|
+
}
|
|
2649
|
+
askQuit() {
|
|
2650
|
+
if (this.everyChild().every((s) => s.status === "exited")) this.quit();
|
|
2651
|
+
else this.confirm = "quit";
|
|
2652
|
+
}
|
|
2653
|
+
toggleSidebar() {
|
|
2654
|
+
this.sidebar = { ...this.sidebar, collapsed: !this.sidebar.collapsed };
|
|
2655
|
+
this.relayout();
|
|
2656
|
+
this.persist();
|
|
2657
|
+
}
|
|
2658
|
+
/** A space in the focused pane's folder, started on the same account. */
|
|
2659
|
+
newSpaceHere() {
|
|
2660
|
+
const entry = this.roster.selected;
|
|
2661
|
+
const cwd = entry ? this.roster.spaceOf(entry).cwd : this.options.folder.cwd;
|
|
2662
|
+
this.newSpaceIn(cwd);
|
|
2663
|
+
}
|
|
2664
|
+
/** A new space in a folder, its first session on the account the focused pane runs on. */
|
|
2665
|
+
newSpaceIn(cwd) {
|
|
2666
|
+
const entry = this.roster.selected;
|
|
2667
|
+
const space = this.roster.addSpace(cwd, basename(cwd) || cwd);
|
|
2668
|
+
const created = this.newTabIn(space);
|
|
2669
|
+
if (entry?.pickedAccount) created.pickedAccount = entry.pickedAccount;
|
|
2670
|
+
this.open(created);
|
|
2671
|
+
}
|
|
2672
|
+
captured() {
|
|
2673
|
+
return this.prompt !== void 0 || this.picker !== void 0 || this.confirm !== void 0 || this.menu !== void 0 || this.help !== void 0 || this.goto !== void 0 || this.accountList !== void 0 || this.context !== void 0;
|
|
2674
|
+
}
|
|
2675
|
+
/** Closes whatever overlay is open without doing what it asked. */
|
|
2676
|
+
dismiss() {
|
|
2677
|
+
this.settleExit(false);
|
|
2678
|
+
this.prompt = void 0;
|
|
2679
|
+
this.picker = void 0;
|
|
2680
|
+
this.confirm = void 0;
|
|
2681
|
+
this.menu = void 0;
|
|
2682
|
+
this.help = void 0;
|
|
2683
|
+
this.goto = void 0;
|
|
2684
|
+
this.accountList = void 0;
|
|
2685
|
+
this.context = void 0;
|
|
2686
|
+
this.router.capture(false);
|
|
2687
|
+
}
|
|
2688
|
+
openMenu() {
|
|
2689
|
+
this.menu = { index: 0 };
|
|
2690
|
+
this.router.capture(true);
|
|
2691
|
+
}
|
|
2692
|
+
chooseMenu(index) {
|
|
2693
|
+
this.menu = void 0;
|
|
2694
|
+
const item = MENU_ITEMS[index];
|
|
2695
|
+
if (item === "keybinds") this.help = { scroll: 0 };
|
|
2696
|
+
else if (item === "accounts") this.accountList = { scroll: 0 };
|
|
2697
|
+
else if (item === "add account") this.addAccount();
|
|
2698
|
+
else if (item === "sidebar") this.toggleSidebar();
|
|
2699
|
+
else this.askQuit();
|
|
2700
|
+
this.router.capture(this.captured());
|
|
2701
|
+
}
|
|
2702
|
+
/** A session in a new tab on the usual sign-in, where the `/auth` command adds the account. */
|
|
2703
|
+
addAccount() {
|
|
2704
|
+
const entry = this.roster.selected;
|
|
2705
|
+
if (!entry) return;
|
|
2706
|
+
this.startIn(this.roster.spaceOf(entry), void 0, false);
|
|
2707
|
+
this.notice = "Type /auth in this session to add an account.";
|
|
2708
|
+
}
|
|
2709
|
+
menuKey(key) {
|
|
2710
|
+
const menu = this.menu;
|
|
2711
|
+
if (!menu) return;
|
|
2712
|
+
const last = MENU_ITEMS.length - 1;
|
|
2713
|
+
if (key.kind === "escape") this.menu = void 0;
|
|
2714
|
+
else if (key.kind === "up" || key.kind === "char" && key.char === "k")
|
|
2715
|
+
menu.index = Math.max(0, menu.index - 1);
|
|
2716
|
+
else if (key.kind === "down" || key.kind === "char" && key.char === "j")
|
|
2717
|
+
menu.index = Math.min(last, menu.index + 1);
|
|
2718
|
+
else if (key.kind === "enter") this.chooseMenu(menu.index);
|
|
2719
|
+
}
|
|
2720
|
+
helpKey(key) {
|
|
2721
|
+
const help = this.help;
|
|
2722
|
+
if (!help) return;
|
|
2723
|
+
const page = this.helpLayout()?.capacity ?? 10;
|
|
2724
|
+
if (key.kind === "up" || key.kind === "char" && key.char === "k")
|
|
2725
|
+
help.scroll = Math.max(0, help.scroll - 1);
|
|
2726
|
+
else if (key.kind === "down" || key.kind === "char" && key.char === "j") help.scroll += 1;
|
|
2727
|
+
else if (key.kind === "tab") help.scroll += page;
|
|
2728
|
+
else if (key.kind === "backtab") help.scroll = Math.max(0, help.scroll - page);
|
|
2729
|
+
else if (key.kind === "escape" || key.kind === "enter" || key.kind === "char" && (key.char === "?" || key.char === "q"))
|
|
2730
|
+
this.help = void 0;
|
|
2731
|
+
const layout = this.helpLayout();
|
|
2732
|
+
if (this.help && layout) this.help.scroll = layout.top;
|
|
2733
|
+
}
|
|
2734
|
+
accountsKey(key) {
|
|
2735
|
+
const list = this.accountList;
|
|
2736
|
+
if (!list) return;
|
|
2737
|
+
if (key.kind === "up" || key.kind === "char" && key.char === "k")
|
|
2738
|
+
list.scroll = Math.max(0, list.scroll - 1);
|
|
2739
|
+
else if (key.kind === "down" || key.kind === "char" && key.char === "j") list.scroll += 1;
|
|
2740
|
+
else if (key.kind === "enter" || key.kind === "escape") this.accountList = void 0;
|
|
2741
|
+
const layout = this.accountsLayout();
|
|
2742
|
+
if (this.accountList && layout) this.accountList.scroll = layout.top;
|
|
2743
|
+
}
|
|
2744
|
+
gotoKey(key) {
|
|
2745
|
+
const goto = this.goto;
|
|
2746
|
+
if (!goto) return;
|
|
2747
|
+
const rows = this.gotoVisible();
|
|
2748
|
+
const last = rows.length - 1;
|
|
2749
|
+
if (key.kind === "escape") this.goto = void 0;
|
|
2750
|
+
else if (key.kind === "up" || key.kind === "backtab") goto.index = Math.max(0, goto.index - 1);
|
|
2751
|
+
else if (key.kind === "down" || key.kind === "tab") goto.index = Math.min(last, goto.index + 1);
|
|
2752
|
+
else if (key.kind === "enter") this.chooseGoto(rows[goto.index]);
|
|
2753
|
+
else if (key.kind === "backspace") {
|
|
2754
|
+
goto.query = goto.query.slice(0, -1);
|
|
2755
|
+
goto.index = 0;
|
|
2756
|
+
} else if (key.kind === "char") {
|
|
2757
|
+
if (key.char === CLEAR) goto.query = "";
|
|
2758
|
+
else goto.query += key.char;
|
|
2759
|
+
goto.index = 0;
|
|
2760
|
+
}
|
|
2761
|
+
const layout = this.gotoLayout();
|
|
2762
|
+
if (this.goto && layout) this.goto.scroll = layout.top;
|
|
2763
|
+
}
|
|
2764
|
+
/** Focuses what a row of the go-to tree names. */
|
|
2765
|
+
chooseGoto(row) {
|
|
2766
|
+
this.goto = void 0;
|
|
2767
|
+
this.router.capture(false);
|
|
2768
|
+
if (!row) return;
|
|
2769
|
+
const { target } = row;
|
|
2770
|
+
if (target.kind === "pane") this.open(target.entry);
|
|
2771
|
+
else if (target.kind === "tab") this.open(target.tab.focus);
|
|
2772
|
+
else {
|
|
2773
|
+
const entry = target.space.activeTab?.focus ?? this.roster.entriesOf(target.space)[0];
|
|
2774
|
+
if (entry) this.open(entry);
|
|
2775
|
+
}
|
|
2776
|
+
}
|
|
2777
|
+
confirmKey(key) {
|
|
2778
|
+
const confirmed = this.confirm;
|
|
2779
|
+
if (!confirmed) return;
|
|
2780
|
+
this.confirm = void 0;
|
|
2781
|
+
const yes = key.kind === "enter" || key.kind === "char" && key.char === "y";
|
|
2782
|
+
if (this.exitGate) {
|
|
2783
|
+
this.settleExit(yes);
|
|
2784
|
+
this.router.capture(this.captured());
|
|
2785
|
+
return;
|
|
2786
|
+
}
|
|
2787
|
+
if (yes) this.perform(confirmed);
|
|
2788
|
+
}
|
|
2789
|
+
settleExit(leave) {
|
|
2790
|
+
const gate = this.exitGate;
|
|
2791
|
+
this.exitGate = void 0;
|
|
2792
|
+
gate?.(leave);
|
|
2793
|
+
}
|
|
2794
|
+
contextKey(key) {
|
|
2795
|
+
const context = this.context;
|
|
2796
|
+
if (!context) return;
|
|
2797
|
+
const items = CONTEXT_ITEMS[context.target.kind];
|
|
2798
|
+
if (key.kind === "escape") this.context = void 0;
|
|
2799
|
+
else if (key.kind === "up" || key.kind === "char" && key.char === "k")
|
|
2800
|
+
context.index = Math.max(0, context.index - 1);
|
|
2801
|
+
else if (key.kind === "down" || key.kind === "char" && key.char === "j")
|
|
2802
|
+
context.index = Math.min(items.length - 1, context.index + 1);
|
|
2803
|
+
else if (key.kind === "enter") this.chooseContext(context.index);
|
|
2804
|
+
}
|
|
2805
|
+
/** Shows what a right-click was on, then does the chosen item to it. */
|
|
2806
|
+
chooseContext(index) {
|
|
2807
|
+
const context = this.context;
|
|
2808
|
+
this.context = void 0;
|
|
2809
|
+
if (!context) return;
|
|
2810
|
+
const item = CONTEXT_ITEMS[context.target.kind][index];
|
|
2811
|
+
const { target } = context;
|
|
2812
|
+
const entry = target.kind === "pane" ? target.entry : target.kind === "tab" ? target.tab.focus : target.space.activeTab?.focus ?? this.roster.entriesOf(target.space)[0];
|
|
2813
|
+
if (!entry || !item) return;
|
|
2814
|
+
this.show(entry);
|
|
2815
|
+
const shown = this.roster.spaceOf(entry);
|
|
2816
|
+
if (item === "Rename") {
|
|
2817
|
+
if (target.kind === "space") this.askName("rename-space", shown.name);
|
|
2818
|
+
else if (target.kind === "tab") this.askName("rename-tab", this.shownTabLabel());
|
|
2819
|
+
else this.askName("rename-session", entry.label);
|
|
2820
|
+
} else if (item === "New tab") this.newTab();
|
|
2821
|
+
else if (item === "Split right") this.splitFocused("side");
|
|
2822
|
+
else if (item === "Split down") this.splitFocused("stack");
|
|
2823
|
+
else if (item === "Zoom") this.toggleZoom();
|
|
2824
|
+
else if (target.kind === "space") this.confirm = "close-space";
|
|
2825
|
+
else if (target.kind === "tab") this.closeTabOrSpace();
|
|
2826
|
+
else this.closePane();
|
|
2827
|
+
this.router.capture(this.captured());
|
|
2828
|
+
}
|
|
2829
|
+
resizeKey(key) {
|
|
2830
|
+
const entry = this.roster.selected;
|
|
2831
|
+
const tab = this.roster.shownTab;
|
|
2832
|
+
if (!entry || !tab) return;
|
|
2833
|
+
let axis;
|
|
2834
|
+
let forward = false;
|
|
2835
|
+
const c = key.kind === "char" ? key.char : "";
|
|
2836
|
+
if (c === "h" || key.kind === "left") [axis, forward] = ["side", false];
|
|
2837
|
+
else if (c === "l" || key.kind === "right") [axis, forward] = ["side", true];
|
|
2838
|
+
else if (c === "j" || key.kind === "down") [axis, forward] = ["stack", true];
|
|
2839
|
+
else if (c === "k" || key.kind === "up") [axis, forward] = ["stack", false];
|
|
2840
|
+
if (axis && resizeAt(tab.root, entry, axis, forward)) {
|
|
2841
|
+
this.fit();
|
|
2842
|
+
this.persist();
|
|
2843
|
+
}
|
|
2844
|
+
}
|
|
2845
|
+
navigateKey(key) {
|
|
2846
|
+
const c = key.kind === "char" ? key.char : "";
|
|
2847
|
+
if (key.kind === "up" || c === "k") this.stepSession(-1);
|
|
2848
|
+
else if (key.kind === "down" || c === "j") this.stepSession(1);
|
|
2849
|
+
else if (key.kind === "right" || c === "l") this.openFull();
|
|
2850
|
+
else if (key.kind === "tab") this.cyclePane(1);
|
|
2851
|
+
else if (key.kind === "backtab") this.cyclePane(-1);
|
|
2852
|
+
else if (c === CLEAR) this.askQuit();
|
|
2853
|
+
}
|
|
2854
|
+
/** Moves the selection through the sessions in the order the sidebar lists them; the space and its tab follow. */
|
|
2855
|
+
stepSession(delta) {
|
|
2856
|
+
const entry = this.roster.selected;
|
|
2857
|
+
if (!entry) return;
|
|
2858
|
+
const list = agentList(this.roster, this.order);
|
|
2859
|
+
const at = list.indexOf(entry);
|
|
2860
|
+
const next = list[Math.max(0, Math.min(list.length - 1, at + delta))];
|
|
2861
|
+
if (!next || next === entry) return;
|
|
2862
|
+
this.show(next);
|
|
2863
|
+
if (this.options.local) this.startShown();
|
|
2864
|
+
this.requestRender();
|
|
2865
|
+
}
|
|
2866
|
+
/** Opens the selected session full screen: the running conversation natively, a child on the whole terminal. */
|
|
2867
|
+
openFull() {
|
|
2868
|
+
const entry = this.roster.selected;
|
|
2869
|
+
if (!entry) return;
|
|
2870
|
+
if (entry.child?.local) {
|
|
2871
|
+
this.openNative();
|
|
2872
|
+
return;
|
|
2873
|
+
}
|
|
2874
|
+
this.ensureStarted(entry);
|
|
2875
|
+
if (!entry.child) return;
|
|
2876
|
+
this.view = "full";
|
|
2877
|
+
this.router.focus();
|
|
2878
|
+
this.fit();
|
|
2879
|
+
this.writer.invalidate();
|
|
2880
|
+
}
|
|
2881
|
+
// --- panes and tabs --------------------------------------------------------
|
|
2882
|
+
/** The shown tab's panes as they would sit with nothing zoomed, which is what a direction is measured on. */
|
|
2883
|
+
flatPanes() {
|
|
2884
|
+
const tab = this.roster.shownTab;
|
|
2885
|
+
return tab ? placeTab({ ...tab, zoomed: false }, this.layout().panes).panes : [];
|
|
2886
|
+
}
|
|
2887
|
+
/** Splits the focused pane; the new pane is a session in the same folder, on the same account. */
|
|
2888
|
+
splitFocused(dir) {
|
|
2889
|
+
const entry = this.roster.selected;
|
|
2890
|
+
const tab = this.roster.shownTab;
|
|
2891
|
+
if (!entry || !tab) return;
|
|
2892
|
+
const outer = this.flatPanes().find((p) => p.entry === entry)?.outer;
|
|
2893
|
+
const room = dir === "side" ? outer?.width ?? 0 : outer?.height ?? 0;
|
|
2894
|
+
const least = dir === "side" ? MIN_PANE_WIDTH : MIN_PANE_HEIGHT;
|
|
2895
|
+
if (room < least * 2) {
|
|
2896
|
+
this.notice = "There is not enough room to split this pane.";
|
|
2897
|
+
return;
|
|
2898
|
+
}
|
|
2899
|
+
const created = this.addEntry(this.roster.spaceOf(entry));
|
|
2900
|
+
if (entry.pickedAccount) created.pickedAccount = entry.pickedAccount;
|
|
2901
|
+
this.roster.splitBeside(entry, created, dir);
|
|
2902
|
+
this.open(created);
|
|
2903
|
+
}
|
|
2904
|
+
moveFocus(direction) {
|
|
2905
|
+
const entry = this.roster.selected;
|
|
2906
|
+
if (!entry) return;
|
|
2907
|
+
const target = neighbour(this.flatPanes(), entry, direction);
|
|
2908
|
+
if (target) this.open(target);
|
|
2909
|
+
}
|
|
2910
|
+
swapFocused(direction) {
|
|
2911
|
+
const entry = this.roster.selected;
|
|
2912
|
+
const tab = this.roster.shownTab;
|
|
2913
|
+
if (!entry || !tab) return;
|
|
2914
|
+
const target = neighbour(this.flatPanes(), entry, direction);
|
|
2915
|
+
if (!target) return;
|
|
2916
|
+
swapLeaves(tab.root, entry, target);
|
|
2917
|
+
this.fit();
|
|
2918
|
+
this.persist();
|
|
2919
|
+
}
|
|
2920
|
+
cyclePane(delta) {
|
|
2921
|
+
const entry = this.roster.selected;
|
|
2922
|
+
const tab = this.roster.shownTab;
|
|
2923
|
+
if (!entry || !tab) return;
|
|
2924
|
+
const panes = leaves(tab.root);
|
|
2925
|
+
const next = panes[(panes.indexOf(entry) + delta + panes.length) % panes.length];
|
|
2926
|
+
if (next && next !== entry) this.open(next);
|
|
2927
|
+
}
|
|
2928
|
+
toggleZoom() {
|
|
2929
|
+
const tab = this.roster.shownTab;
|
|
2930
|
+
if (!tab || leaves(tab.root).length < 2) return;
|
|
2931
|
+
tab.zoomed = !tab.zoomed;
|
|
2932
|
+
this.fit();
|
|
2933
|
+
this.persist();
|
|
2934
|
+
}
|
|
2935
|
+
stepTab(delta) {
|
|
2936
|
+
const entry = this.roster.selected;
|
|
2937
|
+
if (!entry) return;
|
|
2938
|
+
const space = this.roster.spaceOf(entry);
|
|
2939
|
+
const at = space.activeTab ? space.tabs.indexOf(space.activeTab) : 0;
|
|
2940
|
+
this.gotoTab((at + delta + space.tabs.length) % space.tabs.length);
|
|
2941
|
+
}
|
|
2942
|
+
gotoTab(index) {
|
|
2943
|
+
const entry = this.roster.selected;
|
|
2944
|
+
if (!entry) return;
|
|
2945
|
+
const tab = this.roster.spaceOf(entry).tabs[index];
|
|
2946
|
+
if (tab) this.open(tab.focus);
|
|
2947
|
+
}
|
|
2948
|
+
/** Closes the focused pane; the last pane of a tab closes the tab, and of a space's only tab asks to close the space. */
|
|
2949
|
+
closePane() {
|
|
2950
|
+
const entry = this.roster.selected;
|
|
2951
|
+
const tab = this.roster.shownTab;
|
|
2952
|
+
if (!entry || !tab) return;
|
|
2953
|
+
if (leaves(tab.root).length > 1 || this.roster.spaceOf(entry).tabs.length > 1) {
|
|
2954
|
+
this.closeEntries([entry]);
|
|
2955
|
+
return;
|
|
2956
|
+
}
|
|
2957
|
+
this.confirm = "close-space";
|
|
2958
|
+
}
|
|
2959
|
+
/** Closes a tab; a space's only tab closes the space, after asking. */
|
|
2960
|
+
closeTabOrSpace() {
|
|
2961
|
+
const entry = this.roster.selected;
|
|
2962
|
+
if (entry && this.roster.spaceOf(entry).tabs.length > 1) this.closeTab();
|
|
2963
|
+
else this.confirm = "close-space";
|
|
2964
|
+
}
|
|
2965
|
+
closeTab() {
|
|
2966
|
+
const entry = this.roster.selected;
|
|
2967
|
+
const tab = this.roster.shownTab;
|
|
2968
|
+
if (!entry || !tab) return;
|
|
2969
|
+
if (this.roster.spaceOf(entry).tabs.length <= 1) {
|
|
2970
|
+
this.notice = "A space keeps at least one tab.";
|
|
2971
|
+
return;
|
|
2972
|
+
}
|
|
2973
|
+
this.closeEntries(leaves(tab.root));
|
|
2974
|
+
}
|
|
2975
|
+
/** Starts a session in a new tab of the shown space, asking which account first when there is a choice. */
|
|
2976
|
+
newTab() {
|
|
2977
|
+
const entry = this.roster.selected;
|
|
2978
|
+
if (!entry) return;
|
|
2979
|
+
const space = this.roster.spaceOf(entry);
|
|
2980
|
+
let accounts = [];
|
|
2981
|
+
try {
|
|
2982
|
+
accounts = (this.options.accounts?.() ?? []).filter((a) => a.label !== "default");
|
|
2983
|
+
} catch {
|
|
2984
|
+
accounts = [];
|
|
2985
|
+
}
|
|
2986
|
+
if (accounts.length === 0) {
|
|
2987
|
+
this.startIn(space, void 0);
|
|
2988
|
+
return;
|
|
2989
|
+
}
|
|
2990
|
+
const choices = [
|
|
2991
|
+
{ id: void 0, text: "Usual sign-in" },
|
|
2992
|
+
...accounts.map((a) => ({
|
|
2993
|
+
id: a.id,
|
|
2994
|
+
text: `${a.label} ${a.provider}`
|
|
2995
|
+
}))
|
|
2996
|
+
];
|
|
2997
|
+
const remembered = choices.findIndex((c) => c.id !== void 0 && c.id === space.lastAccount);
|
|
2998
|
+
this.picker = { space, choices, index: Math.max(0, remembered) };
|
|
2999
|
+
}
|
|
3000
|
+
startIn(space, account, ask = true) {
|
|
3001
|
+
if (account === void 0) delete space.lastAccount;
|
|
3002
|
+
else space.lastAccount = account;
|
|
3003
|
+
const created = this.newTabIn(space);
|
|
3004
|
+
if (account !== void 0) created.pickedAccount = account;
|
|
3005
|
+
this.open(created);
|
|
3006
|
+
if (ask) {
|
|
3007
|
+
this.prompt = { kind: "rename-tab", value: "", fresh: true };
|
|
3008
|
+
this.router.capture(true);
|
|
3009
|
+
}
|
|
3010
|
+
}
|
|
3011
|
+
/** Moves among the spaces, showing each one's tab without starting what it holds. */
|
|
3012
|
+
stepSpace(delta) {
|
|
3013
|
+
const entry = this.roster.selected;
|
|
3014
|
+
if (!entry) return;
|
|
3015
|
+
const index = this.roster.spaces.indexOf(this.roster.spaceOf(entry)) + delta;
|
|
3016
|
+
const space = this.roster.spaces[index];
|
|
3017
|
+
const target = space?.activeTab?.focus;
|
|
3018
|
+
if (target) this.show(target);
|
|
3019
|
+
}
|
|
3020
|
+
gotoSpace(index) {
|
|
3021
|
+
const target = this.roster.spaces[index]?.activeTab?.focus;
|
|
3022
|
+
if (target) this.show(target);
|
|
3023
|
+
}
|
|
3024
|
+
pickerKey(key) {
|
|
3025
|
+
const picker = this.picker;
|
|
3026
|
+
if (!picker) return;
|
|
3027
|
+
const last = picker.choices.length - 1;
|
|
3028
|
+
if (key.kind === "escape") this.picker = void 0;
|
|
3029
|
+
else if (key.kind === "up" || key.kind === "char" && key.char === "k")
|
|
3030
|
+
picker.index = Math.max(0, picker.index - 1);
|
|
3031
|
+
else if (key.kind === "down" || key.kind === "char" && key.char === "j")
|
|
3032
|
+
picker.index = Math.min(last, picker.index + 1);
|
|
3033
|
+
else if (key.kind === "enter") {
|
|
3034
|
+
this.picker = void 0;
|
|
3035
|
+
this.router.capture(false);
|
|
3036
|
+
this.startIn(picker.space, picker.choices[picker.index]?.id);
|
|
3037
|
+
}
|
|
3038
|
+
}
|
|
3039
|
+
askFolder() {
|
|
3040
|
+
this.prompt = { kind: "folder", value: "" };
|
|
3041
|
+
}
|
|
3042
|
+
askName(kind, value) {
|
|
3043
|
+
this.prompt = { kind, value };
|
|
3044
|
+
}
|
|
3045
|
+
promptKey(key) {
|
|
3046
|
+
const prompt = this.prompt;
|
|
3047
|
+
if (!prompt) return;
|
|
3048
|
+
if (key.kind === "escape") {
|
|
3049
|
+
this.endPrompt();
|
|
3050
|
+
return;
|
|
3051
|
+
}
|
|
3052
|
+
if (key.kind === "backspace") {
|
|
3053
|
+
prompt.value = prompt.value.slice(0, -1);
|
|
3054
|
+
delete prompt.error;
|
|
3055
|
+
return;
|
|
3056
|
+
}
|
|
3057
|
+
if (key.kind === "char") {
|
|
3058
|
+
if (key.char === CLEAR) prompt.value = "";
|
|
3059
|
+
else prompt.value += key.char;
|
|
3060
|
+
delete prompt.error;
|
|
3061
|
+
return;
|
|
3062
|
+
}
|
|
3063
|
+
if (key.kind !== "enter") return;
|
|
3064
|
+
const value = prompt.value.trim();
|
|
3065
|
+
if (prompt.kind === "folder" || prompt.kind === "new-space") {
|
|
3066
|
+
if (value === "") {
|
|
3067
|
+
this.endPrompt();
|
|
3068
|
+
return;
|
|
3069
|
+
}
|
|
3070
|
+
const path = this.expand(value);
|
|
3071
|
+
if (!(this.options.isDirectory ?? defaultIsDirectory)(path)) {
|
|
3072
|
+
prompt.error = "No such folder.";
|
|
3073
|
+
return;
|
|
3074
|
+
}
|
|
3075
|
+
this.endPrompt();
|
|
3076
|
+
if (prompt.kind === "new-space") this.newSpaceIn(path);
|
|
3077
|
+
else this.openFolder(path);
|
|
3078
|
+
return;
|
|
3079
|
+
}
|
|
3080
|
+
const entry = this.roster.selected;
|
|
3081
|
+
const tab = this.roster.shownTab;
|
|
3082
|
+
if (entry) {
|
|
3083
|
+
if (prompt.kind === "rename-session" && value !== "") entry.label = value;
|
|
3084
|
+
else if (prompt.kind === "rename-space" && value !== "")
|
|
3085
|
+
this.roster.spaceOf(entry).name = value;
|
|
3086
|
+
else if (prompt.kind === "rename-tab" && tab) {
|
|
3087
|
+
if (value === "") delete tab.name;
|
|
3088
|
+
else tab.name = value;
|
|
3089
|
+
}
|
|
3090
|
+
this.persist();
|
|
3091
|
+
}
|
|
3092
|
+
this.endPrompt();
|
|
3093
|
+
}
|
|
3094
|
+
endPrompt() {
|
|
3095
|
+
this.prompt = void 0;
|
|
3096
|
+
this.router.capture(false);
|
|
3097
|
+
}
|
|
3098
|
+
expand(value) {
|
|
3099
|
+
const home = this.options.homeDirectory ?? homedir();
|
|
3100
|
+
const full = value === "~" ? home : value.startsWith("~/") ? join(home, value.slice(2)) : value;
|
|
3101
|
+
const base = this.roster.selected ? this.roster.spaceOf(this.roster.selected).cwd : this.options.folder.cwd;
|
|
3102
|
+
return isAbsolute(full) ? resolve(full) : resolve(base, full);
|
|
3103
|
+
}
|
|
3104
|
+
/** Opens a folder as a space, or shows the space it already is. */
|
|
3105
|
+
openFolder(path) {
|
|
3106
|
+
const known = this.roster.spaces.find((s) => s.cwd === path);
|
|
3107
|
+
if (known) {
|
|
3108
|
+
const entry = known.activeTab?.focus ?? this.roster.entriesOf(known)[0];
|
|
3109
|
+
if (entry) this.open(entry);
|
|
3110
|
+
return;
|
|
3111
|
+
}
|
|
3112
|
+
const space = this.roster.addSpace(path, basename(path) || path);
|
|
3113
|
+
this.open(this.newTabIn(space));
|
|
3114
|
+
}
|
|
3115
|
+
perform(what) {
|
|
3116
|
+
const entry = this.roster.selected;
|
|
3117
|
+
if (what === "quit") {
|
|
3118
|
+
this.quit();
|
|
3119
|
+
return;
|
|
3120
|
+
}
|
|
3121
|
+
if (!entry) return;
|
|
3122
|
+
this.closeEntries(this.roster.entriesOf(this.roster.spaceOf(entry)));
|
|
3123
|
+
}
|
|
3124
|
+
/** Ends the sessions and takes their panes away; closing the last one leaves nothing to bring back and quits. */
|
|
3125
|
+
closeEntries(doomed) {
|
|
3126
|
+
if (doomed.length < this.roster.entries.length && doomed.some((entry) => entry.child?.local)) {
|
|
3127
|
+
this.notice = "This is the session you started from. End it with /exit.";
|
|
3128
|
+
return;
|
|
3129
|
+
}
|
|
3130
|
+
if (doomed.length === this.roster.entries.length) {
|
|
3131
|
+
this.forgetAll = true;
|
|
3132
|
+
this.quit();
|
|
3133
|
+
return;
|
|
3134
|
+
}
|
|
3135
|
+
for (const item of doomed) {
|
|
3136
|
+
if (item.child && item.child.status !== "exited") {
|
|
3137
|
+
this.leaving.push(item.child);
|
|
3138
|
+
item.child.stop("SIGHUP");
|
|
3139
|
+
} else item.child?.dispose();
|
|
3140
|
+
this.roster.removeEntry(item);
|
|
3141
|
+
}
|
|
3142
|
+
this.persist();
|
|
3143
|
+
const next = this.roster.selected;
|
|
3144
|
+
if (next) this.show(next);
|
|
3145
|
+
}
|
|
3146
|
+
// --- mouse -----------------------------------------------------------------
|
|
3147
|
+
mouse(event) {
|
|
3148
|
+
if (event.kind === "release") this.endDrags();
|
|
3149
|
+
if (this.captured()) {
|
|
3150
|
+
this.overlayMouse(event);
|
|
3151
|
+
return;
|
|
3152
|
+
}
|
|
3153
|
+
const layout = this.layout();
|
|
3154
|
+
if (this.view === "full") {
|
|
3155
|
+
const entry = this.roster.selected;
|
|
3156
|
+
if (entry && (event.kind === "wheel-up" || event.kind === "wheel-down")) {
|
|
3157
|
+
const size = entry.child?.screen.scrollbackSize() ?? 0;
|
|
3158
|
+
const direction = event.kind === "wheel-up" ? -1 : 1;
|
|
3159
|
+
entry.scrollBack = Math.max(0, Math.min(size, entry.scrollBack - direction * WHEEL_ROWS));
|
|
3160
|
+
this.requestRender();
|
|
3161
|
+
}
|
|
3162
|
+
return;
|
|
3163
|
+
}
|
|
3164
|
+
const inSidebar = layout.sidebar !== void 0 && event.x < layout.sidebar.width;
|
|
3165
|
+
if (event.kind === "wheel-up" || event.kind === "wheel-down") {
|
|
3166
|
+
const direction = event.kind === "wheel-up" ? -1 : 1;
|
|
3167
|
+
if (inSidebar && layout.sidebar) {
|
|
3168
|
+
const model = this.sidebarModel(layout.rail);
|
|
3169
|
+
const region = regionAt(model, layout.sidebar.height, event.y);
|
|
3170
|
+
if (region)
|
|
3171
|
+
this.sidebarScroll = clampScroll(
|
|
3172
|
+
{
|
|
3173
|
+
...this.sidebarScroll,
|
|
3174
|
+
[region]: this.sidebarScroll[region] + direction * WHEEL_ROWS
|
|
3175
|
+
},
|
|
3176
|
+
model,
|
|
3177
|
+
layout.sidebar.height
|
|
3178
|
+
);
|
|
3179
|
+
} else {
|
|
3180
|
+
const entry = this.placement()?.panes.find(
|
|
3181
|
+
(p) => paneAt([p], event.x, event.y) !== void 0
|
|
3182
|
+
)?.entry;
|
|
3183
|
+
const size = entry?.child?.screen.scrollbackSize() ?? 0;
|
|
3184
|
+
if (entry)
|
|
3185
|
+
entry.scrollBack = Math.max(0, Math.min(size, entry.scrollBack - direction * WHEEL_ROWS));
|
|
3186
|
+
}
|
|
3187
|
+
this.requestRender();
|
|
3188
|
+
return;
|
|
3189
|
+
}
|
|
3190
|
+
if (event.kind === "drag") {
|
|
3191
|
+
if (this.reorder) this.dragSpace(layout, event);
|
|
3192
|
+
else if (this.sidebarDrag) this.dragSidebar(event);
|
|
3193
|
+
else this.dragBorder(event);
|
|
3194
|
+
return;
|
|
3195
|
+
}
|
|
3196
|
+
if (event.kind === "release") return;
|
|
3197
|
+
if (event.kind === "context") {
|
|
3198
|
+
this.openContext(layout, event);
|
|
3199
|
+
return;
|
|
3200
|
+
}
|
|
3201
|
+
if (event.kind !== "press") return;
|
|
3202
|
+
if (inSidebar && layout.sidebar) {
|
|
3203
|
+
this.sidebarPress(layout.sidebar, layout.rail, event);
|
|
3204
|
+
return;
|
|
3205
|
+
}
|
|
3206
|
+
if (layout.rule && event.x === layout.rule.x) {
|
|
3207
|
+
this.edgePress(layout.rail);
|
|
3208
|
+
return;
|
|
3209
|
+
}
|
|
3210
|
+
if (this.router.current !== "terminal") this.router.focus();
|
|
3211
|
+
this.workspacePress(event);
|
|
3212
|
+
this.requestRender();
|
|
3213
|
+
}
|
|
3214
|
+
/** A press on the line between the sidebar and the session: a second one soon after resets the width. */
|
|
3215
|
+
edgePress(rail) {
|
|
3216
|
+
if (rail) return;
|
|
3217
|
+
const at = (this.options.now ?? Date.now)();
|
|
3218
|
+
if (this.lastEdgePress !== void 0 && at - this.lastEdgePress <= DOUBLE_CLICK_MS) {
|
|
3219
|
+
this.lastEdgePress = void 0;
|
|
3220
|
+
this.sidebar = { ...this.sidebar, width: SIDEBAR_DEFAULT };
|
|
3221
|
+
this.relayout();
|
|
3222
|
+
this.persist();
|
|
3223
|
+
return;
|
|
3224
|
+
}
|
|
3225
|
+
this.lastEdgePress = at;
|
|
3226
|
+
this.sidebarDrag = "width";
|
|
3227
|
+
}
|
|
3228
|
+
/** Moves the sidebar's edge, or the rule between its sections, to follow the pointer. */
|
|
3229
|
+
dragSidebar(event) {
|
|
3230
|
+
if (this.sidebarDrag === "width") {
|
|
3231
|
+
const width = clampSidebarWidth(event.x + 1);
|
|
3232
|
+
if (width === this.sidebar.width) return;
|
|
3233
|
+
this.sidebar = { ...this.sidebar, width };
|
|
3234
|
+
this.relayout();
|
|
3235
|
+
return;
|
|
3236
|
+
}
|
|
3237
|
+
const height = this.options.output.rows;
|
|
3238
|
+
const split = Math.max(0.1, Math.min(0.9, event.y / height));
|
|
3239
|
+
this.split = ruleRow(height, split) / height;
|
|
3240
|
+
this.requestRender();
|
|
3241
|
+
}
|
|
3242
|
+
sidebarPress(sidebar, rail, event) {
|
|
3243
|
+
const target = hitTest(this.sidebarModel(rail), sidebar.width, sidebar.height, event.x, event.y);
|
|
3244
|
+
if (target?.kind === "agent") this.open(target.entry);
|
|
3245
|
+
else if (target?.kind === "space") {
|
|
3246
|
+
this.reorder = { space: target.space, to: this.roster.spaces.indexOf(target.space) };
|
|
3247
|
+
this.gotoSpace(this.roster.spaces.indexOf(target.space));
|
|
3248
|
+
const shown = this.roster.selected;
|
|
3249
|
+
if (shown) this.open(shown);
|
|
3250
|
+
} else if (target?.kind === "new") this.newSpaceHere();
|
|
3251
|
+
else if (target?.kind === "menu") this.openMenu();
|
|
3252
|
+
else if (target?.kind === "collapse") this.toggleSidebar();
|
|
3253
|
+
else if (target?.kind === "split") this.sidebarDrag = "split";
|
|
3254
|
+
else if (target?.kind === "order") {
|
|
3255
|
+
this.order = this.order === "grouped" ? "priority" : "grouped";
|
|
3256
|
+
this.sidebarScroll = { ...this.sidebarScroll, agents: 0 };
|
|
3257
|
+
this.persist();
|
|
3258
|
+
}
|
|
3259
|
+
this.requestRender();
|
|
3260
|
+
}
|
|
3261
|
+
/** A pointer button went up: a drag of a border, the sidebar or a space ends, and a moved space lands. */
|
|
3262
|
+
endDrags() {
|
|
3263
|
+
const moved = this.reorder;
|
|
3264
|
+
if (moved && this.roster.moveSpace(moved.space, moved.to)) {
|
|
3265
|
+
this.revealSelected();
|
|
3266
|
+
this.persist();
|
|
3267
|
+
}
|
|
3268
|
+
if (this.drag || this.sidebarDrag) this.persist();
|
|
3269
|
+
this.reorder = void 0;
|
|
3270
|
+
this.drag = void 0;
|
|
3271
|
+
this.sidebarDrag = void 0;
|
|
3272
|
+
this.requestRender();
|
|
3273
|
+
}
|
|
3274
|
+
/** While a space is dragged: the place it would land is the space row under the pointer. */
|
|
3275
|
+
dragSpace(layout, event) {
|
|
3276
|
+
const drag = this.reorder;
|
|
3277
|
+
if (!drag || !layout.sidebar) return;
|
|
3278
|
+
const target = hitTest(
|
|
3279
|
+
this.sidebarModel(layout.rail),
|
|
3280
|
+
layout.sidebar.width,
|
|
3281
|
+
layout.sidebar.height,
|
|
3282
|
+
Math.min(event.x, layout.sidebar.width - 1),
|
|
3283
|
+
event.y
|
|
3284
|
+
);
|
|
3285
|
+
if (target?.kind === "space") drag.to = this.roster.spaces.indexOf(target.space);
|
|
3286
|
+
else if (!target) {
|
|
3287
|
+
const geo = geometry(
|
|
3288
|
+
layout.sidebar.height,
|
|
3289
|
+
this.sidebarModel(layout.rail).foot.length,
|
|
3290
|
+
this.split,
|
|
3291
|
+
layout.rail
|
|
3292
|
+
);
|
|
3293
|
+
const shown = this.roster.spaces.length - this.sidebarScroll.spaces;
|
|
3294
|
+
if (event.y >= geo.spaceTop + shown * geo.spaceStep && event.y < (geo.footerY ?? geo.ruleY))
|
|
3295
|
+
drag.to = this.roster.spaces.length - 1;
|
|
3296
|
+
}
|
|
3297
|
+
this.requestRender();
|
|
3298
|
+
}
|
|
3299
|
+
/** A right-click: a menu for the space, tab or pane under the pointer. */
|
|
3300
|
+
openContext(layout, event) {
|
|
3301
|
+
let target;
|
|
3302
|
+
if (layout.sidebar && event.x < layout.sidebar.width) {
|
|
3303
|
+
const hit = hitTest(
|
|
3304
|
+
this.sidebarModel(layout.rail),
|
|
3305
|
+
layout.sidebar.width,
|
|
3306
|
+
layout.sidebar.height,
|
|
3307
|
+
event.x,
|
|
3308
|
+
event.y
|
|
3309
|
+
);
|
|
3310
|
+
if (hit?.kind === "space") target = { kind: "space", space: hit.space };
|
|
3311
|
+
else if (hit?.kind === "agent") target = { kind: "pane", entry: hit.entry };
|
|
3312
|
+
} else if (event.y === layout.tabBar.y) {
|
|
3313
|
+
const entry = this.roster.selected;
|
|
3314
|
+
const hit = entry ? tabBarTarget(layoutTabBar(this.roster.spaceOf(entry), layout.tabBar), event.x, event.y) : void 0;
|
|
3315
|
+
if (hit?.kind === "tab") target = { kind: "tab", tab: hit.tab };
|
|
3316
|
+
} else {
|
|
3317
|
+
const placement = this.placement();
|
|
3318
|
+
const pane = placement ? paneAt(placement.panes, event.x, event.y) : void 0;
|
|
3319
|
+
if (pane) target = { kind: "pane", entry: pane.entry };
|
|
3320
|
+
}
|
|
3321
|
+
if (!target) return;
|
|
3322
|
+
this.context = { target, at: { x: event.x, y: event.y }, index: 0 };
|
|
3323
|
+
this.router.capture(true);
|
|
3324
|
+
this.requestRender();
|
|
3325
|
+
}
|
|
3326
|
+
screen() {
|
|
3327
|
+
return { cols: this.options.output.columns, rows: this.options.output.rows };
|
|
3328
|
+
}
|
|
3329
|
+
/** Where the open overlay is, for finding what a press lands on. */
|
|
3330
|
+
overlaySurface() {
|
|
3331
|
+
const screen = this.screen();
|
|
3332
|
+
if (this.context)
|
|
3333
|
+
return layoutPopup(screen, this.context.at, CONTEXT_ITEMS[this.context.target.kind]);
|
|
3334
|
+
if (this.menu) return this.menuSurface();
|
|
3335
|
+
const modal = this.modalSpec();
|
|
3336
|
+
if (modal) return layoutModal(screen, modal);
|
|
3337
|
+
return this.listLayout();
|
|
3338
|
+
}
|
|
3339
|
+
listSpec() {
|
|
3340
|
+
if (this.picker) return this.pickerSpec(this.picker);
|
|
3341
|
+
if (this.help) return this.helpSpec(this.help);
|
|
3342
|
+
if (this.goto) return this.gotoSpec(this.goto);
|
|
3343
|
+
if (this.accountList) return this.accountsSpec(this.accountList);
|
|
3344
|
+
return void 0;
|
|
3345
|
+
}
|
|
3346
|
+
listLayout() {
|
|
3347
|
+
const spec = this.listSpec();
|
|
3348
|
+
return spec ? layoutList(this.screen(), spec) : void 0;
|
|
3349
|
+
}
|
|
3350
|
+
helpLayout() {
|
|
3351
|
+
return this.help ? layoutList(this.screen(), this.helpSpec(this.help)) : void 0;
|
|
3352
|
+
}
|
|
3353
|
+
accountsLayout() {
|
|
3354
|
+
return this.accountList ? layoutList(this.screen(), this.accountsSpec(this.accountList)) : void 0;
|
|
3355
|
+
}
|
|
3356
|
+
gotoLayout() {
|
|
3357
|
+
return this.goto ? layoutList(this.screen(), this.gotoSpec(this.goto)) : void 0;
|
|
3358
|
+
}
|
|
3359
|
+
gotoVisible() {
|
|
3360
|
+
return this.goto ? filterGoto(gotoRows(this.roster), this.goto.query) : [];
|
|
3361
|
+
}
|
|
3362
|
+
/** While an overlay is open a press picks inside it, and anywhere else closes it. */
|
|
3363
|
+
overlayMouse(event) {
|
|
3364
|
+
if (event.kind === "wheel-up" || event.kind === "wheel-down") {
|
|
3365
|
+
const step = event.kind === "wheel-up" ? -1 : 1;
|
|
3366
|
+
if (this.help) this.help.scroll = Math.max(0, this.help.scroll + step * WHEEL_ROWS);
|
|
3367
|
+
else if (this.accountList)
|
|
3368
|
+
this.accountList.scroll = Math.max(0, this.accountList.scroll + step * WHEEL_ROWS);
|
|
3369
|
+
else if (this.goto) {
|
|
3370
|
+
const last = Math.max(0, this.gotoVisible().length - 1);
|
|
3371
|
+
this.goto.index = Math.max(0, Math.min(last, this.goto.index + step));
|
|
3372
|
+
}
|
|
3373
|
+
this.requestRender();
|
|
3374
|
+
return;
|
|
3375
|
+
}
|
|
3376
|
+
if (event.kind !== "press" && event.kind !== "context") return;
|
|
3377
|
+
const surface = this.overlaySurface();
|
|
3378
|
+
const hit = surface ? hitSurface(surface, event.x, event.y) : { kind: "outside" };
|
|
3379
|
+
if (hit.kind === "outside") this.dismiss();
|
|
3380
|
+
else if (event.kind === "press") this.pressOverlay(hit);
|
|
3381
|
+
this.router.capture(this.captured());
|
|
3382
|
+
this.requestRender();
|
|
3383
|
+
}
|
|
3384
|
+
pressOverlay(hit) {
|
|
3385
|
+
if (this.context && hit.kind === "row") this.chooseContext(hit.index);
|
|
3386
|
+
else if (this.menu && hit.kind === "row") this.chooseMenu(hit.index);
|
|
3387
|
+
else if (this.goto && hit.kind === "row") {
|
|
3388
|
+
this.goto.index = hit.index;
|
|
3389
|
+
this.chooseGoto(this.gotoVisible()[hit.index]);
|
|
3390
|
+
} else if (this.picker && hit.kind === "row") {
|
|
3391
|
+
this.picker.index = hit.index;
|
|
3392
|
+
this.pickerKey({ kind: "enter" });
|
|
3393
|
+
} else if (this.prompt && hit.kind === "button") {
|
|
3394
|
+
if (hit.action === "confirm") this.promptKey({ kind: "enter" });
|
|
3395
|
+
else if (hit.action === "clear") this.promptKey({ kind: "char", char: CLEAR });
|
|
3396
|
+
else this.dismiss();
|
|
3397
|
+
} else if (this.confirm && hit.kind === "button") {
|
|
3398
|
+
if (hit.action === "confirm") this.confirmKey({ kind: "enter" });
|
|
3399
|
+
else this.dismiss();
|
|
3400
|
+
}
|
|
3401
|
+
}
|
|
3402
|
+
/** A press in the workspace area: a tab, the "+", a border to drag, or a pane to focus. */
|
|
3403
|
+
workspacePress(event) {
|
|
3404
|
+
const layout = this.layout();
|
|
3405
|
+
const entry = this.roster.selected;
|
|
3406
|
+
if (!entry) return;
|
|
3407
|
+
if (event.y === layout.tabBar.y) {
|
|
3408
|
+
const bar = layoutTabBar(this.roster.spaceOf(entry), layout.tabBar);
|
|
3409
|
+
const target = tabBarTarget(bar, event.x, event.y);
|
|
3410
|
+
if (target?.kind === "new") this.newTab();
|
|
3411
|
+
else if (target?.kind === "tab") this.open(target.tab.focus);
|
|
3412
|
+
return;
|
|
3413
|
+
}
|
|
3414
|
+
const placement = this.placement();
|
|
3415
|
+
if (!placement) return;
|
|
3416
|
+
const divider = dividerAt(placement.dividers, event.x, event.y);
|
|
3417
|
+
if (divider) {
|
|
3418
|
+
const pointer = divider.split.dir === "side" ? event.x : event.y;
|
|
3419
|
+
this.drag = { split: divider.split, offset: pointer - divider.at };
|
|
3420
|
+
return;
|
|
3421
|
+
}
|
|
3422
|
+
const pane = paneAt(placement.panes, event.x, event.y);
|
|
3423
|
+
if (pane) this.open(pane.entry);
|
|
3424
|
+
}
|
|
3425
|
+
/** Moves the border being dragged to follow the pointer. */
|
|
3426
|
+
dragBorder(event) {
|
|
3427
|
+
const drag = this.drag;
|
|
3428
|
+
const placement = this.placement();
|
|
3429
|
+
if (!drag || !placement) return;
|
|
3430
|
+
const divider = placement.dividers.find((d) => d.split === drag.split);
|
|
3431
|
+
if (!divider) {
|
|
3432
|
+
this.drag = void 0;
|
|
3433
|
+
return;
|
|
3434
|
+
}
|
|
3435
|
+
const at = (drag.split.dir === "side" ? event.x : event.y) - drag.offset;
|
|
3436
|
+
const ratio = ratioFor(divider, at);
|
|
3437
|
+
if (ratio === drag.split.ratio) return;
|
|
3438
|
+
drag.split.ratio = ratio;
|
|
3439
|
+
this.fit();
|
|
3440
|
+
this.requestRender();
|
|
3441
|
+
}
|
|
3442
|
+
revealSelected() {
|
|
3443
|
+
const layout = this.layout();
|
|
3444
|
+
const height = layout.sidebar?.height;
|
|
3445
|
+
if (height === void 0) return;
|
|
3446
|
+
this.sidebarScroll = clampScroll(
|
|
3447
|
+
this.sidebarScroll,
|
|
3448
|
+
this.sidebarModel(layout.rail),
|
|
3449
|
+
height,
|
|
3450
|
+
true
|
|
3451
|
+
);
|
|
3452
|
+
}
|
|
3453
|
+
// --- drawing ---------------------------------------------------------------
|
|
3454
|
+
/** The question or name field a modal shows, if one is open. */
|
|
3455
|
+
modalSpec() {
|
|
3456
|
+
const entry = this.roster.selected;
|
|
3457
|
+
const prompt = this.prompt;
|
|
3458
|
+
if (prompt) {
|
|
3459
|
+
const titles = {
|
|
3460
|
+
folder: "open folder",
|
|
3461
|
+
"new-space": "new space",
|
|
3462
|
+
"rename-session": "rename pane",
|
|
3463
|
+
"rename-space": "rename space",
|
|
3464
|
+
"rename-tab": prompt.fresh ? "new tab" : "rename tab"
|
|
3465
|
+
};
|
|
3466
|
+
const create = prompt.kind === "folder" || prompt.kind === "new-space" || prompt.fresh;
|
|
3467
|
+
return {
|
|
3468
|
+
title: titles[prompt.kind],
|
|
3469
|
+
input: { value: prompt.value },
|
|
3470
|
+
...prompt.error ? { error: prompt.error } : {},
|
|
3471
|
+
buttons: [
|
|
3472
|
+
{ label: create ? "\u21B2 open" : "\u21B2 save", action: "confirm", primary: true },
|
|
3473
|
+
{ label: "^c clear", action: "clear" },
|
|
3474
|
+
{ label: "esc cancel", action: "cancel" }
|
|
3475
|
+
]
|
|
3476
|
+
};
|
|
3477
|
+
}
|
|
3478
|
+
if (this.confirm === "quit")
|
|
3479
|
+
return {
|
|
3480
|
+
title: "Quit all sessions?",
|
|
3481
|
+
danger: true,
|
|
3482
|
+
lines: ["Every session is hung up. The layout is kept for next time."],
|
|
3483
|
+
buttons: [
|
|
3484
|
+
{ label: "\u21B2 quit", action: "confirm", primary: true },
|
|
3485
|
+
{ label: "esc cancel", action: "cancel" }
|
|
3486
|
+
]
|
|
3487
|
+
};
|
|
3488
|
+
if (this.confirm && entry) {
|
|
3489
|
+
const space = this.roster.spaceOf(entry);
|
|
3490
|
+
const count = this.roster.entriesOf(space).length;
|
|
3491
|
+
return {
|
|
3492
|
+
title: "Close space?",
|
|
3493
|
+
danger: true,
|
|
3494
|
+
lines: [`${space.name} \u2014 ${count} ${count === 1 ? "pane" : "panes"}`],
|
|
3495
|
+
buttons: [
|
|
3496
|
+
{ label: "\u21B2 confirm", action: "confirm", primary: true },
|
|
3497
|
+
{ label: "esc cancel", action: "cancel" }
|
|
3498
|
+
]
|
|
3499
|
+
};
|
|
3500
|
+
}
|
|
3501
|
+
return void 0;
|
|
3502
|
+
}
|
|
3503
|
+
pickerSpec(picker) {
|
|
3504
|
+
return {
|
|
3505
|
+
title: `Start a session in ${picker.space.name} on`,
|
|
3506
|
+
rows: picker.choices.map((c) => ({ text: c.text })),
|
|
3507
|
+
index: picker.index,
|
|
3508
|
+
scroll: 0,
|
|
3509
|
+
footer: "j/k pick \u21B2 start esc cancel",
|
|
3510
|
+
width: 52
|
|
3511
|
+
};
|
|
3512
|
+
}
|
|
3513
|
+
helpSpec(help) {
|
|
3514
|
+
return {
|
|
3515
|
+
title: "keybinds",
|
|
3516
|
+
rows: helpRows(this.options.prefix.name).map(
|
|
3517
|
+
(r) => r.heading !== void 0 ? { text: r.heading, heading: true } : { text: r.label ?? "", ...r.keys !== void 0 ? { keys: r.keys } : {} }
|
|
3518
|
+
),
|
|
3519
|
+
index: -1,
|
|
3520
|
+
scroll: help.scroll,
|
|
3521
|
+
footer: "\u2191/\u2193 scroll esc close",
|
|
3522
|
+
width: 58
|
|
3523
|
+
};
|
|
3524
|
+
}
|
|
3525
|
+
gotoSpec(goto) {
|
|
3526
|
+
const rows = this.gotoVisible();
|
|
3527
|
+
return {
|
|
3528
|
+
title: "go to",
|
|
3529
|
+
input: { value: goto.query },
|
|
3530
|
+
rows: rows.length === 0 ? [{ text: "nothing matches", muted: true }] : rows.map((r) => {
|
|
3531
|
+
const dot = dotStyle(r.dot, this.palette);
|
|
3532
|
+
return { text: r.text, indent: r.depth * 2, dot, heading: false };
|
|
3533
|
+
}),
|
|
3534
|
+
index: rows.length === 0 ? -1 : Math.min(goto.index, rows.length - 1),
|
|
3535
|
+
scroll: goto.scroll,
|
|
3536
|
+
footer: "type to filter \u2191/\u2193 move \u21B2 go esc close",
|
|
3537
|
+
width: 64
|
|
3538
|
+
};
|
|
3539
|
+
}
|
|
3540
|
+
accountsSpec(list) {
|
|
3541
|
+
let accounts = [];
|
|
3542
|
+
try {
|
|
3543
|
+
accounts = (this.options.accounts?.() ?? []).filter((a) => a.label !== "default");
|
|
3544
|
+
} catch {
|
|
3545
|
+
accounts = [];
|
|
3546
|
+
}
|
|
3547
|
+
const rows = [
|
|
3548
|
+
{ text: "Usual sign-in", muted: true },
|
|
3549
|
+
...accounts.map((a) => ({ text: `${a.label} ${a.provider}` })),
|
|
3550
|
+
{ text: accounts.length === 0 ? "No other accounts yet." : "", muted: true },
|
|
3551
|
+
{ text: "Add one with /auth in any session.", muted: true }
|
|
3552
|
+
];
|
|
3553
|
+
return {
|
|
3554
|
+
title: "accounts",
|
|
3555
|
+
rows,
|
|
3556
|
+
index: -1,
|
|
3557
|
+
scroll: list.scroll,
|
|
3558
|
+
footer: "\u2191/\u2193 scroll esc close",
|
|
3559
|
+
width: 52
|
|
3560
|
+
};
|
|
3561
|
+
}
|
|
3562
|
+
/** The menu popup: above the "new / menu" row at the sidebar's left, or at the top of the main area when there is no sidebar. */
|
|
3563
|
+
menuSurface() {
|
|
3564
|
+
const layout = this.layout();
|
|
3565
|
+
const items = MENU_ITEMS;
|
|
3566
|
+
const height = items.length + 2;
|
|
3567
|
+
if (!layout.sidebar || layout.rail)
|
|
3568
|
+
return layoutPopup(this.screen(), { x: layout.main.x + 1, y: layout.main.y + 1 }, items);
|
|
3569
|
+
const geo = geometry(layout.sidebar.height, 0, this.split, false);
|
|
3570
|
+
return layoutPopup(
|
|
3571
|
+
this.screen(),
|
|
3572
|
+
{ x: 1, y: Math.max(0, (geo.footerY ?? 0) - height) },
|
|
3573
|
+
items,
|
|
3574
|
+
Math.min(layout.sidebar.width - 2, 18)
|
|
3575
|
+
);
|
|
3576
|
+
}
|
|
3577
|
+
/** What the bottom bar says in a mode: a chip, then keys and what they do. */
|
|
3578
|
+
modeBar(mode) {
|
|
3579
|
+
const prefix = this.options.prefix.name;
|
|
3580
|
+
if (mode === "resize")
|
|
3581
|
+
return {
|
|
3582
|
+
chip: "RESIZE",
|
|
3583
|
+
chipBg: this.palette.mauve,
|
|
3584
|
+
hints: [
|
|
3585
|
+
["esc", "done"],
|
|
3586
|
+
["h/l", "width"],
|
|
3587
|
+
["j/k", "height"]
|
|
3588
|
+
]
|
|
3589
|
+
};
|
|
3590
|
+
if (mode === "navigate")
|
|
3591
|
+
return {
|
|
3592
|
+
chip: "NAVIGATE",
|
|
3593
|
+
chipBg: this.palette.accent,
|
|
3594
|
+
hints: [
|
|
3595
|
+
["\u2191/\u2193", "session"],
|
|
3596
|
+
["\u2192", "open"],
|
|
3597
|
+
["enter", "type"],
|
|
3598
|
+
["tab", "pane"]
|
|
3599
|
+
]
|
|
3600
|
+
};
|
|
3601
|
+
return {
|
|
3602
|
+
chip: "PREFIX",
|
|
3603
|
+
chipBg: this.palette.accent,
|
|
3604
|
+
hints: [
|
|
3605
|
+
["esc", "cancel"],
|
|
3606
|
+
[prefix, "send prefix"],
|
|
3607
|
+
["w", "space nav"],
|
|
3608
|
+
["?", "keybinds"]
|
|
3609
|
+
]
|
|
3610
|
+
};
|
|
3611
|
+
}
|
|
3612
|
+
drawModeBar(frame, area, mode) {
|
|
3613
|
+
const { palette } = this;
|
|
3614
|
+
const bar = this.modeBar(mode);
|
|
3615
|
+
frame.fillRect(area, { bg: palette.panelBg });
|
|
3616
|
+
let x = 0;
|
|
3617
|
+
const put = /* @__PURE__ */ __name((text, style) => {
|
|
3618
|
+
x += frame.writeText({ ...area, x: area.x + x, width: area.width - x }, 0, text, style);
|
|
3619
|
+
}, "put");
|
|
3620
|
+
put(` ${bar.chip} `, {
|
|
3621
|
+
fg: palette.panelBg,
|
|
3622
|
+
bg: bar.chipBg,
|
|
3623
|
+
attrs: ATTR_BOLD
|
|
3624
|
+
});
|
|
3625
|
+
put(" ", { fg: palette.dim, bg: palette.panelBg });
|
|
3626
|
+
for (const [key, what] of bar.hints) {
|
|
3627
|
+
put(key, { fg: palette.accent, bg: palette.panelBg, attrs: ATTR_BOLD });
|
|
3628
|
+
put(` ${what} `, { fg: palette.dim, bg: palette.panelBg });
|
|
3629
|
+
}
|
|
3630
|
+
}
|
|
3631
|
+
requestRender() {
|
|
3632
|
+
if (this.closed || this.hidden || this.pending) return;
|
|
3633
|
+
const cancel = this.schedule(() => {
|
|
3634
|
+
this.pending = void 0;
|
|
3635
|
+
void this.render();
|
|
3636
|
+
}, FRAME_MS);
|
|
3637
|
+
this.pending = cancel;
|
|
3638
|
+
}
|
|
3639
|
+
/** Paints the current state now, after the emulator has taken all output received so far. */
|
|
3640
|
+
render() {
|
|
3641
|
+
this.rendering = this.rendering.then(() => this.paint()).then(
|
|
3642
|
+
() => {
|
|
3643
|
+
this.paintFailures = 0;
|
|
3644
|
+
},
|
|
3645
|
+
() => this.paintFailed()
|
|
3646
|
+
);
|
|
3647
|
+
return this.rendering;
|
|
3648
|
+
}
|
|
3649
|
+
/** A drawing error never ends the chain; repeated ones close the host so the terminal is restored. */
|
|
3650
|
+
paintFailed() {
|
|
3651
|
+
this.paintFailures++;
|
|
3652
|
+
if (this.paintFailures >= MAX_PAINT_FAILURES) {
|
|
3653
|
+
this.quit();
|
|
3654
|
+
return;
|
|
3655
|
+
}
|
|
3656
|
+
this.notice = "Could not redraw the screen.";
|
|
3657
|
+
this.requestRender();
|
|
3658
|
+
}
|
|
3659
|
+
async paint() {
|
|
3660
|
+
if (this.closed || this.hidden) return;
|
|
3661
|
+
const entry = this.roster.selected;
|
|
3662
|
+
const placement = this.placement();
|
|
3663
|
+
const panes = placement?.panes ?? [];
|
|
3664
|
+
await Promise.all(panes.map((p) => p.entry.child?.screen.settled()));
|
|
3665
|
+
if (this.closed || this.hidden) return;
|
|
3666
|
+
const { output } = this.options;
|
|
3667
|
+
const frame = new Frame(output.columns, output.rows);
|
|
3668
|
+
const layout = this.layout();
|
|
3669
|
+
if (layout.sidebar) {
|
|
3670
|
+
const model = this.sidebarModel(layout.rail);
|
|
3671
|
+
this.sidebarScroll = clampScroll(this.sidebarScroll, model, layout.sidebar.height);
|
|
3672
|
+
drawSidebar(frame, layout.sidebar, {
|
|
3673
|
+
...model,
|
|
3674
|
+
scroll: this.sidebarScroll
|
|
3675
|
+
});
|
|
3676
|
+
}
|
|
3677
|
+
if (layout.rule) drawRule(frame, layout.rule, this.palette);
|
|
3678
|
+
if (entry && this.view === "split")
|
|
3679
|
+
drawTabBar(frame, layout.tabBar, this.roster.spaceOf(entry), this.palette);
|
|
3680
|
+
const ordered = [...panes].sort((a, b) => Number(a.entry === entry) - Number(b.entry === entry));
|
|
3681
|
+
for (const pane of ordered)
|
|
3682
|
+
this.drawPane(frame, pane, pane.entry === entry, placement?.bordered ?? false);
|
|
3683
|
+
if (this.reorder) this.drawDrop(frame, layout);
|
|
3684
|
+
const area = {
|
|
3685
|
+
...layout.main,
|
|
3686
|
+
y: layout.main.y + layout.main.height - 1,
|
|
3687
|
+
height: 1
|
|
3688
|
+
};
|
|
3689
|
+
const mode = this.router.current;
|
|
3690
|
+
const asking = this.captured();
|
|
3691
|
+
if (mode !== "terminal" && !asking) this.drawModeBar(frame, area, mode);
|
|
3692
|
+
else if (this.notice && !asking) {
|
|
3693
|
+
frame.fillRect(area, { bg: this.palette.panelBg });
|
|
3694
|
+
frame.writeText(area, 0, ` ${this.notice}`, {
|
|
3695
|
+
fg: this.palette.yellow,
|
|
3696
|
+
bg: this.palette.panelBg
|
|
3697
|
+
});
|
|
3698
|
+
}
|
|
3699
|
+
this.drawOverlay(frame);
|
|
3700
|
+
if (mode !== "terminal" || asking)
|
|
3701
|
+
frame.setCursor({ x: frame.cursor.x, y: frame.cursor.y, visible: false });
|
|
3702
|
+
let out = "";
|
|
3703
|
+
const wantPaste = entry?.child?.screen.bracketedPaste() ?? false;
|
|
3704
|
+
if (wantPaste !== this.pasteOn) {
|
|
3705
|
+
this.pasteOn = wantPaste;
|
|
3706
|
+
out += wantPaste ? "\x1B[?2004h" : "\x1B[?2004l";
|
|
3707
|
+
}
|
|
3708
|
+
out += this.writer.render(frame);
|
|
3709
|
+
if (out !== "") output.write(out);
|
|
3710
|
+
if (!this.gitStarted) {
|
|
3711
|
+
this.gitStarted = true;
|
|
3712
|
+
this.armGit(true);
|
|
3713
|
+
}
|
|
3714
|
+
}
|
|
3715
|
+
/** Reads every space's branch now and then again on a timer. */
|
|
3716
|
+
armGit(now = false) {
|
|
3717
|
+
if (this.closed) return;
|
|
3718
|
+
if (now) this.git.refreshAll(this.roster.spaces.map((s) => s.cwd));
|
|
3719
|
+
this.cancelGit = this.schedule(() => {
|
|
3720
|
+
this.git.refreshAll(this.roster.spaces.map((s) => s.cwd));
|
|
3721
|
+
this.armGit();
|
|
3722
|
+
}, GIT_MS);
|
|
3723
|
+
}
|
|
3724
|
+
/** Draws the open overlay on top; a modal first dims everything under it. */
|
|
3725
|
+
drawOverlay(frame) {
|
|
3726
|
+
const { palette } = this;
|
|
3727
|
+
const screen = this.screen();
|
|
3728
|
+
if (this.context) {
|
|
3729
|
+
const items = CONTEXT_ITEMS[this.context.target.kind];
|
|
3730
|
+
drawPopup(
|
|
3731
|
+
frame,
|
|
3732
|
+
layoutPopup(screen, this.context.at, items),
|
|
3733
|
+
items,
|
|
3734
|
+
this.context.index,
|
|
3735
|
+
palette
|
|
3736
|
+
);
|
|
3737
|
+
return;
|
|
3738
|
+
}
|
|
3739
|
+
if (this.menu) {
|
|
3740
|
+
drawPopup(frame, this.menuSurface(), MENU_ITEMS, this.menu.index, palette);
|
|
3741
|
+
return;
|
|
3742
|
+
}
|
|
3743
|
+
const modal = this.modalSpec();
|
|
3744
|
+
const list = this.listSpec();
|
|
3745
|
+
if (!modal && !list) return;
|
|
3746
|
+
dimFrame(frame);
|
|
3747
|
+
if (modal) drawModal(frame, layoutModal(screen, modal), modal, palette);
|
|
3748
|
+
else if (list) drawList(frame, layoutList(screen, list), list, palette);
|
|
3749
|
+
}
|
|
3750
|
+
/** The line a dragged space would land at: under the row above the place it would take. */
|
|
3751
|
+
drawDrop(frame, layout) {
|
|
3752
|
+
const drag = this.reorder;
|
|
3753
|
+
const sidebar = layout.sidebar;
|
|
3754
|
+
if (!drag || !sidebar) return;
|
|
3755
|
+
const from = this.roster.spaces.indexOf(drag.space);
|
|
3756
|
+
if (drag.to === from) return;
|
|
3757
|
+
const geo = geometry(sidebar.height, 0, this.split, layout.rail);
|
|
3758
|
+
const shown = drag.to - this.sidebarScroll.spaces;
|
|
3759
|
+
if (shown < 0 || shown >= geo.spaceCap) return;
|
|
3760
|
+
const top = geo.spaceTop + shown * geo.spaceStep;
|
|
3761
|
+
const y = (drag.to < from ? top : top + geo.spaceStep) - 1;
|
|
3762
|
+
for (let x = 0; x < sidebar.width; x++) {
|
|
3763
|
+
const cell = frame.cellAt(x, y);
|
|
3764
|
+
if (!cell) continue;
|
|
3765
|
+
frame.set(x, y, {
|
|
3766
|
+
...cell,
|
|
3767
|
+
fg: cell.ch === " " ? this.palette.accent : cell.fg,
|
|
3768
|
+
attrs: cell.attrs | ATTR_UNDERLINE
|
|
3769
|
+
});
|
|
3770
|
+
}
|
|
3771
|
+
}
|
|
3772
|
+
/** One pane: its border (the focused one in the accent colour), then its session or what stands in for it. */
|
|
3773
|
+
drawPane(frame, pane, focused, bordered) {
|
|
3774
|
+
const { entry, outer, inner } = pane;
|
|
3775
|
+
if (bordered) drawBox(frame, outer, focused ? this.palette.accent : this.palette.dim);
|
|
3776
|
+
const child = entry.child;
|
|
3777
|
+
if (child) {
|
|
3778
|
+
frame.blit(child.screen.cells(entry.scrollBack), inner);
|
|
3779
|
+
const last = { ...inner, y: inner.y + inner.height - 1, height: 1 };
|
|
3780
|
+
if (child.status === "exited") {
|
|
3781
|
+
frame.fillRect(last, { attrs: ATTR_INVERSE });
|
|
3782
|
+
frame.writeText(last, 0, ` ${endedMessage(child.ending, this.options.prefix.name)}`, {
|
|
3783
|
+
attrs: ATTR_INVERSE
|
|
3784
|
+
});
|
|
3785
|
+
if (focused) frame.setCursor({ x: 0, y: 0, visible: false });
|
|
3786
|
+
} else if (entry.scrollBack > 0) {
|
|
3787
|
+
frame.fillRect(last, { attrs: ATTR_INVERSE });
|
|
3788
|
+
frame.writeText(last, 0, " Scrolled back. Scroll down or type to return.", {
|
|
3789
|
+
attrs: ATTR_INVERSE
|
|
3790
|
+
});
|
|
3791
|
+
}
|
|
3792
|
+
return;
|
|
3793
|
+
}
|
|
3794
|
+
const space = this.roster.spaceOf(entry);
|
|
3795
|
+
const say = /* @__PURE__ */ __name((row, text) => void frame.writeText(inner, row, text), "say");
|
|
3796
|
+
if (entry.folderMissing) {
|
|
3797
|
+
say(1, ` The folder for "${entry.label}" was not found.`);
|
|
3798
|
+
say(2, ` ${space.cwd}`);
|
|
3799
|
+
say(3, " Put it back or remove this space, then press enter to try again.");
|
|
3800
|
+
} else if (entry.openElsewhere) {
|
|
3801
|
+
say(1, ` "${entry.label}" is open in another terminal.`);
|
|
3802
|
+
say(2, " Close it there, then press enter to open it here.");
|
|
3803
|
+
} else if (entry.checking) say(1, ` Opening "${entry.label}"...`);
|
|
3804
|
+
else {
|
|
3805
|
+
say(1, ` "${entry.label}" in ${space.name} has not started yet.`);
|
|
3806
|
+
say(2, " Press enter or click it to open it.");
|
|
3807
|
+
}
|
|
3808
|
+
}
|
|
3809
|
+
// --- remembering the layout ------------------------------------------------
|
|
3810
|
+
/** What is written between runs: spaces with their tabs and pane trees, and where focus is. */
|
|
3811
|
+
snapshot() {
|
|
3812
|
+
const selected = this.roster.selected;
|
|
3813
|
+
const saveNode = /* @__PURE__ */ __name((node) => {
|
|
3814
|
+
if (node.kind === "split")
|
|
3815
|
+
return {
|
|
3816
|
+
split: node.dir,
|
|
3817
|
+
ratio: node.ratio,
|
|
3818
|
+
a: saveNode(node.a),
|
|
3819
|
+
b: saveNode(node.b)
|
|
3820
|
+
};
|
|
3821
|
+
const entry = node.entry;
|
|
3822
|
+
const conversationId = entry.conversationId ?? entry.resume;
|
|
3823
|
+
return {
|
|
3824
|
+
session: {
|
|
3825
|
+
label: entry.label,
|
|
3826
|
+
...conversationId ? { conversationId } : {},
|
|
3827
|
+
...entry.account ? { account: entry.account } : {},
|
|
3828
|
+
...entry.pickedAccount ? { pickedAccount: entry.pickedAccount } : {}
|
|
3829
|
+
}
|
|
3830
|
+
};
|
|
3831
|
+
}, "saveNode");
|
|
3832
|
+
const saveTab = /* @__PURE__ */ __name((tab) => {
|
|
3833
|
+
const focus = leaves(tab.root).indexOf(tab.focus);
|
|
3834
|
+
return {
|
|
3835
|
+
...tab.name ? { name: tab.name } : {},
|
|
3836
|
+
tree: saveNode(tab.root),
|
|
3837
|
+
...focus > 0 ? { focus } : {},
|
|
3838
|
+
...tab.zoomed ? { zoomed: true } : {}
|
|
3839
|
+
};
|
|
3840
|
+
}, "saveTab");
|
|
3841
|
+
const spaces = this.roster.spaces.map((space2) => {
|
|
3842
|
+
const active = space2.activeTab ? space2.tabs.indexOf(space2.activeTab) : 0;
|
|
3843
|
+
return {
|
|
3844
|
+
name: space2.name,
|
|
3845
|
+
cwd: space2.cwd,
|
|
3846
|
+
...space2.lastAccount ? { lastAccount: space2.lastAccount } : {},
|
|
3847
|
+
tabs: space2.tabs.map(saveTab),
|
|
3848
|
+
...active > 0 ? { activeTab: active } : {}
|
|
3849
|
+
};
|
|
3850
|
+
});
|
|
3851
|
+
const space = selected ? this.roster.spaces.indexOf(this.roster.spaceOf(selected)) : -1;
|
|
3852
|
+
const sidebar = {
|
|
3853
|
+
...this.sidebar.collapsed ? { collapsed: true } : {},
|
|
3854
|
+
...this.sidebar.width !== SIDEBAR_DEFAULT ? { width: this.sidebar.width } : {},
|
|
3855
|
+
...this.split !== 0.5 ? { split: this.split } : {},
|
|
3856
|
+
...this.order !== "grouped" ? { order: this.order } : {}
|
|
3857
|
+
};
|
|
3858
|
+
return {
|
|
3859
|
+
version: 2,
|
|
3860
|
+
spaces,
|
|
3861
|
+
...space >= 0 ? { focus: { space } } : {},
|
|
3862
|
+
...Object.keys(sidebar).length > 0 ? { sidebar } : {}
|
|
3863
|
+
};
|
|
3864
|
+
}
|
|
3865
|
+
/** Writes the layout soon; a burst of changes becomes one write. */
|
|
3866
|
+
persist() {
|
|
3867
|
+
if (!this.options.store || this.closed || this.cancelSave) return;
|
|
3868
|
+
this.cancelSave = this.schedule(() => {
|
|
3869
|
+
this.cancelSave = void 0;
|
|
3870
|
+
this.writeLayout();
|
|
3871
|
+
}, SAVE_MS);
|
|
3872
|
+
}
|
|
3873
|
+
writeLayout() {
|
|
3874
|
+
const store = this.options.store;
|
|
3875
|
+
if (!store) return;
|
|
3876
|
+
try {
|
|
3877
|
+
store.save(this.forgetAll ? { version: 2, spaces: [] } : this.snapshot());
|
|
3878
|
+
} catch {
|
|
3879
|
+
}
|
|
3880
|
+
}
|
|
3881
|
+
/** Ends every session, then leaves the terminal as it was found. */
|
|
3882
|
+
quit() {
|
|
3883
|
+
if (this.quitting || this.closed) return;
|
|
3884
|
+
this.quitting = true;
|
|
3885
|
+
const live = this.everyChild().filter((s) => s.status !== "exited");
|
|
3886
|
+
if (live.length === 0) {
|
|
3887
|
+
this.close();
|
|
3888
|
+
return;
|
|
3889
|
+
}
|
|
3890
|
+
for (const session of live) session.stop("SIGHUP");
|
|
3891
|
+
this.cancelKill = this.schedule(() => {
|
|
3892
|
+
for (const session of live) session.stop("SIGKILL");
|
|
3893
|
+
this.close();
|
|
3894
|
+
}, QUIT_GRACE_MS);
|
|
3895
|
+
}
|
|
3896
|
+
close() {
|
|
3897
|
+
if (this.closed) return;
|
|
3898
|
+
this.cancelSave?.();
|
|
3899
|
+
this.cancelSave = void 0;
|
|
3900
|
+
this.writeLayout();
|
|
3901
|
+
this.closed = true;
|
|
3902
|
+
this.settleExit(true);
|
|
3903
|
+
this.cancelKill?.();
|
|
3904
|
+
this.cancelPoll?.();
|
|
3905
|
+
this.cancelReconcile?.();
|
|
3906
|
+
this.cancelGit?.();
|
|
3907
|
+
this.stopWatching?.();
|
|
3908
|
+
this.pending?.();
|
|
3909
|
+
const { input, output } = this.options;
|
|
3910
|
+
input.off("data", this.onData);
|
|
3911
|
+
output.off("resize", this.onResize);
|
|
3912
|
+
process.off("exit", this.onProcessExit);
|
|
3913
|
+
input.setRawMode?.(false);
|
|
3914
|
+
input.pause?.();
|
|
3915
|
+
if (!this.hidden) output.write(LEAVE_SCREEN);
|
|
3916
|
+
for (const child of this.everyChild()) child.dispose();
|
|
3917
|
+
this.finish(0);
|
|
3918
|
+
}
|
|
3919
|
+
};
|
|
3920
|
+
|
|
3921
|
+
export {
|
|
3922
|
+
realSchedule,
|
|
3923
|
+
SpacesHost
|
|
3924
|
+
};
|
|
3925
|
+
//# sourceMappingURL=chunk-PIVHVYCN.js.map
|