TUI IDE multiplexer?!
golang tui ide
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add glob-matching for sub bus

kettek 312529a7 664d67cb

+38 -14
+6 -2
app.go
··· 56 56 Rune: 'q', 57 57 Command: CMD_QUIT, 58 58 }) 59 + bus.Register(CMD_QUIT) 59 60 bus.Subscribe(CMD_QUIT, func(v ...any) { 60 - if err := app.Conn.Object(app.dbusID, dbus.ObjectPath("/app")).Call("Quit", dbus.FlagNoAutoStart, v...).Store(); err != nil { 61 + if err := app.Conn.Object(app.dbusID, dbus.ObjectPath("/app")).Call("Quit", dbus.FlagNoAutoStart).Store(); err != nil { 61 62 panic(err) 62 63 } 63 64 }) ··· 68 69 Rune: 'r', 69 70 Command: CMD_RESTART, 70 71 }) 72 + bus.Register(CMD_RESTART) 71 73 bus.Subscribe(CMD_RESTART, func(v ...any) { 72 - if err := app.Conn.Object(app.dbusID, dbus.ObjectPath("/app")).Call("Restart", dbus.FlagNoAutoStart, v...).Store(); err != nil { 74 + if err := app.Conn.Object(app.dbusID, dbus.ObjectPath("/app")).Call("Restart", dbus.FlagNoAutoStart).Store(); err != nil { 73 75 panic(err) 74 76 } 75 77 }) ··· 105 107 Rune: rune(48 + i), 106 108 Command: CMD_FOCUS_PANEL, 107 109 }) 110 + bus.Register(CMD_FOCUS_PANEL) 108 111 bus.Subscribe(CMD_FOCUS_PANEL, func(v ...any) { 109 112 if hk, ok := v[0].(Hotkey); ok { 110 113 if panelId := getPanelPath(int(hk.Rune) - 48 - 1); panelId != "" { ··· 122 125 Key: tcell.KeyCtrlSpace, // ` 123 126 Command: CMD_TOGGLE_SHELL_FOCUS, 124 127 }) 128 + bus.Register(CMD_TOGGLE_SHELL_FOCUS) 125 129 bus.Subscribe(CMD_TOGGLE_SHELL_FOCUS, func(v ...any) { 126 130 if err := app.Conn.Object(app.dbusID, dbus.ObjectPath("/ui")).Call("ToggleShellFocus", dbus.FlagNoAutoStart).Store(); err != nil { 127 131 panic(err)
+30 -12
bus.go
··· 1 1 package main 2 2 3 + import ( 4 + "regexp" 5 + "strings" 6 + ) 7 + 3 8 // Bus provides a basic pubsub modelo via callbacks. 4 9 type Bus struct { 5 10 // subscribers 6 11 topics map[string]*Topic 12 + topID int 7 13 } 8 14 9 15 func (b *Bus) Register(name string) *Topic { 16 + if t, ok := b.topics[name]; ok { 17 + return t 18 + } 10 19 b.topics[name] = &Topic{ 11 20 name: name, 12 21 } ··· 27 36 28 37 // Subscribe subscribes the func to the given topic and returns a non-zero ID if it was added. 29 38 func (b *Bus) Subscribe(topic string, cb func(...any)) (id int) { 30 - t, ok := b.topics[topic] 31 - 32 - // Eh... just auto-register if it doesn't exist. 33 - if !ok { 34 - t = b.Register(topic) 39 + // Check if topic is registered and if not, return 0 (failure) 40 + if _, ok := b.topics[topic]; !ok { 41 + return 0 35 42 } 36 43 37 - t.topID++ 38 - id = t.topID 39 - t.subscriptions = append(t.subscriptions, Subscription{ 40 - id: id, 41 - callback: cb, 42 - }) 44 + // Yeah, yeah, this is inefficient. We're just escaping "." and converting "*" to match any/all non-'.' rune. 45 + pattern := "^" + strings.ReplaceAll(strings.ReplaceAll(topic, ".", "\\."), "*", "([^.]*)") + "$" 46 + 47 + // Crummy regex to subbie. 48 + var foundMatch bool 49 + for k, t := range b.topics { 50 + if match, _ := regexp.Match(pattern, []byte(k)); match { 51 + if !foundMatch { 52 + b.topID++ 53 + foundMatch = true 54 + } 55 + t.subscriptions = append(t.subscriptions, Subscription{ 56 + id: b.topID, 57 + callback: cb, 58 + }) 59 + } 60 + } 43 61 44 - return id 62 + return b.topID 45 63 } 46 64 47 65 // Unsubscribes removes a subscription for a topic using the given id. Returns true on success, false if the topic or id was not found.
+2
resizable.go
··· 75 75 } 76 76 77 77 // Hook into global bus for convenient program-wide handling. 78 + // eh... register as well. 79 + bus.Register(UI_CANCEL) 78 80 r.subscription = bus.Subscribe(UI_CANCEL, func(v ...any) { 79 81 if r.heldGripper != nil { 80 82 r.heldGripper.isHeld = false