···6677 "github.com/gdamore/tcell/v2"
88 "github.com/godbus/dbus/v5"
99+ "github.com/godbus/dbus/v5/introspect"
910 "github.com/rivo/tview"
1011)
1112···2425 status *Status
2526 // focusedPanel *Term
2627 lastFocusedEditor int
2828+ shellLastFocused bool
2729}
28302931func NewApp() *App {
···3133 Application: *tview.NewApplication(),
3234 }
33353636+ // Hotkey and bus handling for quitting.
3737+ hotkeys.Add(Hotkey{
3838+ Modifiers: tcell.ModAlt,
3939+ Rune: 'q',
4040+ Command: CMD_QUIT,
4141+ })
4242+ bus.Subscribe(CMD_QUIT, func(v ...any) {
4343+ app.Stop()
4444+ })
4545+4646+ // Hotkey and bus handling for restarting.
4747+ hotkeys.Add(Hotkey{
4848+ Modifiers: tcell.ModAlt,
4949+ Rune: 'r',
5050+ Command: CMD_RESTART,
5151+ })
5252+ bus.Subscribe(CMD_RESTART, func(v ...any) {
5353+ app.Stop()
5454+ if err := restartProcess(); err != nil {
5555+ panic(err)
5656+ }
5757+ })
5858+5959+ // Hotkey and bus handling for focusing panels 0-9.
6060+ getPanelPath := func(num int) string {
6161+ var count int
6262+6363+ if num == 0 {
6464+ return "fm/active"
6565+ }
6666+ count++
6767+6868+ for i := range app.editors.editors {
6969+ if num == i+count {
7070+ return fmt.Sprintf("editor/%d", i)
7171+ }
7272+ }
7373+ count += len(app.editors.editors)
7474+ for i := range app.shells.shells {
7575+ if num == i+count {
7676+ return fmt.Sprintf("shell/%d", i)
7777+ }
7878+ }
7979+8080+ // Out of bounds, just return blank.
8181+ return ""
8282+ }
8383+8484+ for i := range 9 {
8585+ hotkeys.Add(Hotkey{
8686+ Modifiers: tcell.ModAlt,
8787+ Rune: rune(48 + i),
8888+ Command: CMD_FOCUS_PANEL,
8989+ })
9090+ bus.Subscribe(CMD_FOCUS_PANEL, func(v ...any) {
9191+ if hk, ok := v[0].(Hotkey); ok {
9292+ if panelId := getPanelPath(int(hk.Rune) - 48 - 1); panelId != "" {
9393+ if err := app.Conn.Object(app.dbusID, dbus.ObjectPath("/panels/"+panelId)).Call("SetFocus", dbus.FlagNoAutoStart).Store(); err != nil {
9494+ panic(err)
9595+ }
9696+ }
9797+ }
9898+ })
9999+ }
100100+101101+ // Hotkey and bus handling for last editor <-> last shell focus toggling.
102102+ hotkeys.Add(Hotkey{
103103+ Modifiers: tcell.ModCtrl,
104104+ Key: tcell.KeyCtrlSpace, // `
105105+ Command: CMD_TOGGLE_SHELL_FOCUS,
106106+ })
107107+ bus.Subscribe(CMD_TOGGLE_SHELL_FOCUS, func(v ...any) {
108108+ if app.shellLastFocused {
109109+ if err := app.Conn.Object(app.dbusID, dbus.ObjectPath("/panels/editor/active")).Call("SetFocus", dbus.FlagNoAutoStart).Store(); err != nil {
110110+ panic(err)
111111+ }
112112+ } else {
113113+ if err := app.Conn.Object(app.dbusID, dbus.ObjectPath("/panels/shell/active")).Call("SetFocus", dbus.FlagNoAutoStart).Store(); err != nil {
114114+ panic(err)
115115+ }
116116+ }
117117+ })
118118+34119 app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
35120 if event.Key() == tcell.KeyCtrlC {
36121 return tcell.NewEventKey(tcell.KeyCtrlC, 0, tcell.ModNone)
37122 } else if event.Key() == tcell.KeyEscape {
38123 bus.Publish(UI_CANCEL, event)
39124 }
4040- return event
125125+126126+ // Process hotkeys -- note that we could handle this logic in checkHotkeys itself but we should attempt to allow event key passthru.
127127+ passthru := true
128128+ if hks := hotkeys.CheckEventKey(event); hks != nil {
129129+ for _, hk := range hks {
130130+ if !hk.Passthru {
131131+ passthru = false
132132+ }
133133+ bus.Publish(hk.Command, hk)
134134+ }
135135+ }
136136+137137+ if passthru {
138138+ return event
139139+ }
140140+141141+ return nil
41142 })
4214343144 app.editors.env = &app.env
44145 app.editors.setFocusFunc = func(p tview.Primitive) {
45146 app.SetFocus(p)
147147+ app.shellLastFocused = false
46148 }
47149 app.shells.env = &app.env
48150 app.shells.setFocusFunc = func(p tview.Primitive) {
49151 app.SetFocus(p)
152152+ app.shellLastFocused = true
50153 }
51154 return app
52155}
···149252}
150253151254func (a *App) RunFM() error {
152152- a.fm = NewTerm("fm", cfg.FileManager)
255255+ a.fm = NewTerm("fm/0", cfg.FileManager)
153256154257 if err := app.Conn.ExportMethodTable(map[string]any{
155258 "SetFocus": func() *dbus.Error {
156259 a.SetFocus(a.fm)
157260 return nil
158261 },
159159- }, dbus.ObjectPath("/panels/fm"), "net.kettek.Aight.Panel"); err != nil {
262262+ "SendString": func(str string) *dbus.Error {
263263+ a.fm.SendString(str)
264264+ return nil
265265+ },
266266+ "SendBytes": func(b []byte) *dbus.Error {
267267+ a.fm.SendBytes(b)
268268+ return nil
269269+ },
270270+ }, dbus.ObjectPath("/panels/fm/active"), "net.kettek.Aight.Panel"); err != nil {
271271+ return err
272272+ }
273273+ if err := app.Conn.Export(introspect.Introspectable(termIntro), dbus.ObjectPath("/panels/fm/active"), "org.freedesktop.DBus.Introspectable"); err != nil {
160274 return err
161275 }
162276
+1-1
bus.go
···2020func (b *Bus) Publish(topic string, parts ...any) {
2121 if t, ok := b.topics[topic]; ok {
2222 for _, s := range t.subscriptions {
2323- s.callback(parts)
2323+ s.callback(parts...)
2424 }
2525 }
2626}