ソースを参照

Start layout system stuff, + further plans

Johan Rong 1 ヶ月 前
コミット
01794bc8df
3 ファイル変更53 行追加0 行削除
  1. 7 0
      internal/buffer/buffer.go
  2. 3 0
      internal/editor/model.go
  3. 43 0
      internal/layout/layout.go

+ 7 - 0
internal/buffer/buffer.go

@@ -17,6 +17,13 @@ func (bm *BufferManager) Current() *Buffer {
 	return &bm.Buffers[bm.CurrentIdx]
 	return &bm.Buffers[bm.CurrentIdx]
 }
 }
 
 
+// TODO: implement BufferType (BufferNormal, BufferVisual, BufferInteractive).
+// BufferVisual (completely readonly) and BufferInteractive (readonly for user) will only be navigable the Visual mode.
+// The visual mode will have abilities to modify the buffer, through managed functions which eg. a extension has defined.
+// For example pressing space to check or uncheck a radio button.
+// BufferVisual may be redundant, just use BufferInteractive without any defined functionality? Rename BufferInteractive to BufferVisual?
+// Used for interactive things: file explorer (like emacs dired), ...
+
 type Buffer struct {
 type Buffer struct {
 	Rope    *rope.Node
 	Rope    *rope.Node
 	LI      *LineIndex
 	LI      *LineIndex

+ 3 - 0
internal/editor/model.go

@@ -2,6 +2,7 @@ package editor
 
 
 import (
 import (
 	"moose/internal/buffer"
 	"moose/internal/buffer"
+	"moose/internal/layout"
 	"github.com/gdamore/tcell/v3"
 	"github.com/gdamore/tcell/v3"
 )
 )
 
 
@@ -11,6 +12,7 @@ type Model struct {
 	Mode 	   Mode
 	Mode 	   Mode
 	BM		   buffer.BufferManager
 	BM		   buffer.BufferManager
 	AM         ActionManager
 	AM         ActionManager
+	LM		   layout.LayoutManager
 	ShouldQuit bool
 	ShouldQuit bool
 	DebugLog   string
 	DebugLog   string
 }
 }
@@ -26,6 +28,7 @@ func NewModel(screen tcell.Screen, style tcell.Style) Model {
 			PaletteBuffer: buffer.NewBuffer(),
 			PaletteBuffer: buffer.NewBuffer(),
 		},
 		},
 		AM:            DefaultActionManager(),
 		AM:            DefaultActionManager(),
+		LM:			   layout.NewLayoutManager(),
 		ShouldQuit:    false,
 		ShouldQuit:    false,
 	}
 	}
 
 

+ 43 - 0
internal/layout/layout.go

@@ -0,0 +1,43 @@
+package layout
+
+type LayoutManager struct {
+	Workspaces []Workspace
+}
+
+type Workspace struct {
+	RootContainer Container[[]int]
+}
+
+type SplitType int
+const (
+	SplitHorizontal SplitType = iota
+	SplitVertical
+)
+
+type ContainerNode interface {
+	[]int | Container[[]int]
+}
+
+type Container[T ContainerNode] struct {
+	Children [2]any
+	Split  SplitType
+}
+
+func NewLayoutManager() LayoutManager {
+	return LayoutManager{
+		Workspaces: []Workspace{NewWorkspace()},
+	}
+}
+
+func NewWorkspace() Workspace {
+	return Workspace{
+		RootContainer: NewContainerEmpty(),
+	}
+}
+
+func NewContainerEmpty() Container[[]int] {
+	return Container[[]int]{
+		Children: [2]any{},
+		Split:	  SplitHorizontal,
+	}
+}