TUI IDE multiplexer?!
golang tui ide
0
fork

Configure Feed

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

Add dubious resizable panel automatic save/load

kettek 00b9b729 312529a7

+107 -5
+2 -2
app.go
··· 220 220 return err 221 221 } 222 222 223 - shellAndEditors := NewResizable(true) 223 + shellAndEditors := NewResizable("shellAndEditors", true) 224 224 shellAndEditors.AddItem(&a.editors, 0, true) 225 225 shellAndEditors.AddItem(&a.shells, 0, false) 226 226 227 - fmAndSE := NewResizable(false) 227 + fmAndSE := NewResizable("fmAndSE", false) 228 228 fmAndSE.AddItem(a.fm, 0, false) 229 229 fmAndSE.AddItem(shellAndEditors, 0, true) 230 230
+82 -1
econfig.go
··· 1 1 package main 2 2 3 + import ( 4 + "encoding/json" 5 + "errors" 6 + "os" 7 + "path/filepath" 8 + "time" 9 + ) 10 + 3 11 // EmphemeralConfig reprsents values that are not crucially defined by the user, such as current panel sizings and positions. 4 12 type EphemeralConfig struct { 5 - panelSizes map[string]int 13 + PanelSizes map[string]map[int]int 14 + saving bool 15 + path string 16 + cancel chan bool 17 + } 18 + 19 + func (c *EphemeralConfig) Save() error { 20 + if c.path == "" { 21 + return errors.New("ephemeral config save path not defined") 22 + } 23 + 24 + // TODO: Make this... "debounce" 25 + if c.saving { 26 + c.cancel <- true 27 + } 28 + 29 + c.saving = true 30 + go func() { 31 + select { 32 + case <-c.cancel: 33 + case <-time.After(time.Second * 1): 34 + b, err := json.Marshal(c) 35 + if err != nil { 36 + panic(err) 37 + } 38 + 39 + if err := os.WriteFile(c.path, b, 0644); err != nil { 40 + panic(err) 41 + } 42 + c.saving = false 43 + } 44 + }() 45 + 46 + return nil 47 + } 48 + 49 + func (c *EphemeralConfig) Load() error { 50 + if c.path == "" { 51 + return errors.New("ephemeral config load path not defined") 52 + } 53 + 54 + b, err := os.ReadFile(c.path) 55 + if err != nil { 56 + return err 57 + } 58 + 59 + if err := json.Unmarshal(b, c); err != nil { 60 + return err 61 + } 62 + return nil 63 + } 64 + 65 + var econfig EphemeralConfig 66 + 67 + func init() { 68 + user, err := os.UserConfigDir() 69 + if err != nil { 70 + panic(err) 71 + } 72 + 73 + dirpath := filepath.Join(user, "aight") 74 + 75 + if err := os.MkdirAll(dirpath, 0755); err != nil { 76 + panic(err) 77 + } 78 + 79 + econfig.path = filepath.Join(dirpath, "ephemeral.json") 80 + econfig.cancel = make(chan bool) 81 + econfig.PanelSizes = make(map[string]map[int]int) 82 + 83 + // TODO: Move to an app init func. 84 + if err := econfig.Load(); err != nil { 85 + panic(err) 86 + } 6 87 }
+22 -1
resizable.go
··· 54 54 lastX, lastY int 55 55 isVertical bool 56 56 subscription int 57 + id string 57 58 } 58 59 59 60 type ResizableItem struct { ··· 63 64 preferResize bool 64 65 } 65 66 66 - func NewResizable(isVertical bool) *Resizable { 67 + func NewResizable(id string, isVertical bool) *Resizable { 67 68 r := &Resizable{ 69 + id: id, 68 70 Flex: tview.NewFlex(), 69 71 isVertical: isVertical, 70 72 } ··· 91 93 bus.Unsubscribe(UI_CANCEL, r.subscription) 92 94 } 93 95 96 + func (r *Resizable) Restore() { 97 + if ps, ok := econfig.PanelSizes[r.id]; ok { 98 + for index, size := range ps { 99 + if index < len(r.items) { 100 + r.Flex.ResizeItem(r.items[index].item, size, r.items[index].proportion) 101 + } 102 + } 103 + } 104 + } 105 + 94 106 func (r *Resizable) AddItem(item tview.Primitive, size int, preferResize bool) { 95 107 ritem := ResizableItem{item: item, proportion: 1000, size: size, preferResize: preferResize} 96 108 r.items = append(r.items, ritem) ··· 101 113 r.grippers = append(r.grippers, gripper) 102 114 } 103 115 r.Flex.AddItem(ritem.item, ritem.size, ritem.proportion, true) 116 + 117 + // FIXME: Inefficient... 118 + r.Restore() 104 119 } 105 120 106 121 func (r *Resizable) Draw(screen tcell.Screen) { ··· 153 168 } 154 169 r.items[which].size = rsize - delta 155 170 r.Flex.ResizeItem(r.items[which].item, r.items[which].size, r.items[which].proportion) 171 + 172 + if _, ok := econfig.PanelSizes[r.id]; !ok { 173 + econfig.PanelSizes[r.id] = make(map[int]int) 174 + } 175 + econfig.PanelSizes[r.id][which] = r.items[which].size 176 + econfig.Save() 156 177 157 178 r.lastX, r.lastY = x, y 158 179 } else if action == tview.MouseLeftUp || action == tview.MouseLeftClick || action == tview.MouseLeftDoubleClick {
+1 -1
shells.go
··· 21 21 22 22 func (s *Shells) Setup() error { 23 23 // UI 24 - s.Resizable = NewResizable(false) 24 + s.Resizable = NewResizable("shells", false) 25 25 26 26 // D-Bus 27 27 if err := app.Conn.ExportMethodTable(map[string]any{