From 23977cfe9ee3fb4ee62d9cb09daf567357b58b1e Mon Sep 17 00:00:00 2001 From: Erik Winter Date: Sat, 14 Sep 2024 14:54:41 +0200 Subject: [PATCH] wip --- editor/command.go | 2 +- editor/document.go | 32 ++++++++++++++++++++++++++++++++ editor/editor.go | 33 --------------------------------- editor/gui.go | 33 ++++++--------------------------- editor/state.go | 7 +++++-- main.go | 5 ++++- 6 files changed, 48 insertions(+), 64 deletions(-) create mode 100644 editor/document.go delete mode 100644 editor/editor.go diff --git a/editor/command.go b/editor/command.go index e27cf05..052a53e 100644 --- a/editor/command.go +++ b/editor/command.go @@ -1,6 +1,6 @@ package editor type Command interface { - Do(s *State) + Do(lines []string) error //Undo(s *State) error } diff --git a/editor/document.go b/editor/document.go new file mode 100644 index 0000000..70dc017 --- /dev/null +++ b/editor/document.go @@ -0,0 +1,32 @@ +package editor + +type Document struct { + Title string + Lines []string + in chan Command + refresh chan bool +} + +func NewDocument(title string) *Document { + return &Document{ + Title: title, + Lines: make([]string, 0), + in: make(chan Command), + refresh: make(chan bool), + } +} + +func (d *Document) In() chan Command { + return d.in +} + +func (d *Document) Out() chan bool { + return d.refresh +} + +func (d *Document) Run() { + for cmd := range d.in { + cmd.Do(d.Lines) + d.refresh <- true + } +} diff --git a/editor/editor.go b/editor/editor.go deleted file mode 100644 index ce64eb8..0000000 --- a/editor/editor.go +++ /dev/null @@ -1,33 +0,0 @@ -package editor - -type Editor struct { - s *State - in chan Command - refresh chan bool -} - -func NewEditor(s *State) *Editor { - e := &Editor{ - s: s, - in: make(chan Command), - refresh: make(chan bool), - } - go e.Run() - - return e -} - -func (e *Editor) In() chan Command { - return e.in -} - -func (e *Editor) Out() chan bool { - return e.refresh -} - -func (e *Editor) Run() { - for cmd := range e.in { - cmd.Do(e.s) - e.refresh <- true - } -} diff --git a/editor/gui.go b/editor/gui.go index 9d771c4..36aee1a 100644 --- a/editor/gui.go +++ b/editor/gui.go @@ -1,31 +1,17 @@ package editor -import ( - "fyne.io/fyne/v2" - "fyne.io/fyne/v2/app" - "fyne.io/fyne/v2/container" - "fyne.io/fyne/v2/widget" -) - type GUI struct { - a fyne.App - w fyne.Window cmd chan Command refresh chan bool + s *State } -func NewGUI(refresh chan bool, cmd chan Command) *GUI { - a := app.New() - w := a.NewWindow("Narratio") - w.Resize(fyne.NewSize(800, 600)) - +func NewGUI(s *State, refresh chan bool, cmd chan Command) *GUI { g := &GUI{ - a: a, - w: w, refresh: refresh, cmd: cmd, + s: s, } - g.SetContent() return g } @@ -36,17 +22,10 @@ func (g *GUI) Run() { g.Update() } }() - g.w.ShowAndRun() } func (g *GUI) Update() { -} - -func (g *GUI) SetContent() { - input := widget.NewEntry() - input.SetPlaceHolder("Enter text...") - - grid := container.NewBorder(nil, nil, nil, nil, input) - - g.w.SetContent(grid) + content := []string{g.s.Document.Title} + content = append(content, g.s.Document.Lines...) + } diff --git a/editor/state.go b/editor/state.go index 5f5e653..776e7d8 100644 --- a/editor/state.go +++ b/editor/state.go @@ -1,9 +1,12 @@ package editor type State struct { - Err error + Err error + Document *Document } func NewState() *State { - return &State{} + return &State{ + Document: NewDocument("new doc"), + } } diff --git a/main.go b/main.go index 7c0538a..e5ddba1 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,9 @@ import ( func main() { s := editor.NewState() e := editor.NewEditor(s) - g := editor.NewGUI(e.Out(), e.In()) + g := editor.NewGUI(s, e.Out(), e.In()) + go func() { + e.Out() <- true + }() g.Run() }