Ver Fonte

Finish transition to tcell

Johan Rong há 1 mês atrás
pai
commit
066f78d35b
8 ficheiros alterados com 31 adições e 141 exclusões
  1. 10 1
      Makefile
  2. 0 14
      go.mod
  3. 0 34
      go.sum
  4. 0 1
      internal/buffer/buffer.go
  5. 0 5
      internal/editor/action.go
  6. 6 16
      internal/editor/model.go
  7. 0 50
      internal/editor/update.go
  8. 15 20
      main.go

+ 10 - 1
Makefile

@@ -1,6 +1,15 @@
+.PHONY: build release run clean
+
 build:
 	@mkdir -p build
 	go build -o build/moose .
 
+release:
+	@mkdir -p build
+	env CGO_ENABLED=0 go build -ldflags="-s -w" -trimpath -o build/moose .
+
 run:
-	go run .
+	go run .
+
+clean:
+	rm -rf build/

+ 0 - 14
go.mod

@@ -3,29 +3,15 @@ module moose
 go 1.26.4
 
 require (
-	charm.land/bubbles/v2 v2.1.1
-	charm.land/bubbletea/v2 v2.0.8
 	github.com/gdamore/tcell/v3 v3.4.0
 	github.com/zyedidia/rope v0.0.0-20210616205215-37fbf22eab3a
 )
 
 require (
-	charm.land/lipgloss/v2 v2.0.4 // indirect
-	github.com/charmbracelet/colorprofile v0.4.3 // indirect
-	github.com/charmbracelet/ultraviolet v0.0.0-20260703014108-f5a850f9c2b7 // indirect
-	github.com/charmbracelet/x/ansi v0.11.7 // indirect
-	github.com/charmbracelet/x/term v0.2.2 // indirect
-	github.com/charmbracelet/x/termios v0.1.1 // indirect
-	github.com/charmbracelet/x/windows v0.2.2 // indirect
 	github.com/clipperhouse/displaywidth v0.11.0 // indirect
 	github.com/clipperhouse/uax29/v2 v2.7.0 // indirect
 	github.com/gdamore/encoding v1.0.1 // indirect
 	github.com/lucasb-eyer/go-colorful v1.4.0 // indirect
-	github.com/mattn/go-runewidth v0.0.24 // indirect
-	github.com/muesli/cancelreader v0.2.2 // indirect
-	github.com/rivo/uniseg v0.4.7 // indirect
-	github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
-	golang.org/x/sync v0.21.0 // indirect
 	golang.org/x/sys v0.46.0 // indirect
 	golang.org/x/term v0.43.0 // indirect
 	golang.org/x/text v0.37.0 // indirect

+ 0 - 34
go.sum

@@ -1,25 +1,3 @@
-charm.land/bubbles/v2 v2.1.1 h1:7r55WzBxpo/R3z98hGmY7KKPd3ET6vsf0Fb9sDHOV60=
-charm.land/bubbles/v2 v2.1.1/go.mod h1:GE6M31gaWZVXzGw73OeuTTgy4lX+OtkH0E5ymnNsHxo=
-charm.land/bubbletea/v2 v2.0.8 h1:SxTJMhCAI3lbPmy4SgX5LWZ24AdINr4I6UEqzZvYJuY=
-charm.land/bubbletea/v2 v2.0.8/go.mod h1:2SkdgoTXluXJHOUwAoRlRXF/28vklb1rFl6GcgV1/ss=
-charm.land/lipgloss/v2 v2.0.4 h1:lcPeVtcp23SNra7lHy8iYE4UC2aIipVQ47sbGyyxR5Q=
-charm.land/lipgloss/v2 v2.0.4/go.mod h1:0653x8epbZSzdDfO/XPS1a/uYPOBeSsCssOpJOqDzik=
-github.com/aymanbagabas/go-udiff v0.4.1 h1:OEIrQ8maEeDBXQDoGCbbTTXYJMYRCRO1fnodZ12Gv5o=
-github.com/aymanbagabas/go-udiff v0.4.1/go.mod h1:0L9PGwj20lrtmEMeyw4WKJ/TMyDtvAoK9bf2u/mNo3w=
-github.com/charmbracelet/colorprofile v0.4.3 h1:QPa1IWkYI+AOB+fE+mg/5/4HRMZcaXex9t5KX76i20Q=
-github.com/charmbracelet/colorprofile v0.4.3/go.mod h1:/zT4BhpD5aGFpqQQqw7a+VtHCzu+zrQtt1zhMt9mR4Q=
-github.com/charmbracelet/ultraviolet v0.0.0-20260703014108-f5a850f9c2b7 h1:3FmWoGNWK4STvqg0O0Aeav2T7rodWJAPeF0QpH+8gFw=
-github.com/charmbracelet/ultraviolet v0.0.0-20260703014108-f5a850f9c2b7/go.mod h1:f/jRa757WUmaOZrbPspXymbg/GnbF+rwe4OLsG7aXYo=
-github.com/charmbracelet/x/ansi v0.11.7 h1:kzv1kJvjg2S3r9KHo8hDdHFQLEqn4RBCb39dAYC84jI=
-github.com/charmbracelet/x/ansi v0.11.7/go.mod h1:9qGpnAVYz+8ACONkZBUWPtL7lulP9No6p1epAihUZwQ=
-github.com/charmbracelet/x/exp/golden v0.0.0-20250806222409-83e3a29d542f h1:pk6gmGpCE7F3FcjaOEKYriCvpmIN4+6OS/RD0vm4uIA=
-github.com/charmbracelet/x/exp/golden v0.0.0-20250806222409-83e3a29d542f/go.mod h1:IfZAMTHB6XkZSeXUqriemErjAWCCzT0LwjKFYCZyw0I=
-github.com/charmbracelet/x/term v0.2.2 h1:xVRT/S2ZcKdhhOuSP4t5cLi5o+JxklsoEObBSgfgZRk=
-github.com/charmbracelet/x/term v0.2.2/go.mod h1:kF8CY5RddLWrsgVwpw4kAa6TESp6EB5y3uxGLeCqzAI=
-github.com/charmbracelet/x/termios v0.1.1 h1:o3Q2bT8eqzGnGPOYheoYS8eEleT5ZVNYNy8JawjaNZY=
-github.com/charmbracelet/x/termios v0.1.1/go.mod h1:rB7fnv1TgOPOyyKRJ9o+AsTU/vK5WHJ2ivHeut/Pcwo=
-github.com/charmbracelet/x/windows v0.2.2 h1:IofanmuvaxnKHuV04sC0eBy/smG6kIKrWG2/jYn2GuM=
-github.com/charmbracelet/x/windows v0.2.2/go.mod h1:/8XtdKZzedat74NQFn0NGlGL4soHB0YQZrETF96h75k=
 github.com/clipperhouse/displaywidth v0.11.0 h1:lBc6kY44VFw+TDx4I8opi/EtL9m20WSEFgwIwO+UVM8=
 github.com/clipperhouse/displaywidth v0.11.0/go.mod h1:bkrFNkf81G8HyVqmKGxsPufD3JhNl3dSqnGhOoSD/o0=
 github.com/clipperhouse/uax29/v2 v2.7.0 h1:+gs4oBZ2gPfVrKPthwbMzWZDaAFPGYK72F0NJv2v7Vk=
@@ -30,21 +8,11 @@ github.com/gdamore/tcell/v3 v3.4.0 h1:VUym1HQZiYodA5PGQrqLxF7QwqQndcAUwQD7G7XUy5
 github.com/gdamore/tcell/v3 v3.4.0/go.mod h1:fjKxNiIFwbzTxDU+i+AAMz+xPOgXVaZq5tbShsKseHc=
 github.com/lucasb-eyer/go-colorful v1.4.0 h1:UtrWVfLdarDgc44HcS7pYloGHJUjHV/4FwW4TvVgFr4=
 github.com/lucasb-eyer/go-colorful v1.4.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
-github.com/mattn/go-runewidth v0.0.24 h1:cpokDiIn0MGnhdHwuWnJBITySJ20QyNGnY2kR/ay2DU=
-github.com/mattn/go-runewidth v0.0.24/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs=
-github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
-github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
-github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
-github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
-github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
-github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
 github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
 github.com/zyedidia/rope v0.0.0-20210616205215-37fbf22eab3a h1:+VbuFCNAjzVffErUlm0TIAZClFxFZwJ1il6qtWrnIg8=
 github.com/zyedidia/rope v0.0.0-20210616205215-37fbf22eab3a/go.mod h1:IKo1js3O2gdESAUH9F3B33wlrRBnpJMJR/gXyY0a3ho=
 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
 golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
-golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
-golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
 golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
 golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
 golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
@@ -54,8 +22,6 @@ golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
 golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
-golang.org/x/sync v0.21.0 h1:HLII4xRRTtCRkxYp4HNFF0Js/Og6q2i++KXbg0gHCwM=
-golang.org/x/sync v0.21.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
 golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

+ 0 - 1
internal/buffer/buffer.go

@@ -3,7 +3,6 @@ package buffer
 import (
 	"slices"
 	"unicode/utf8"
-
 	"github.com/zyedidia/rope"
 )
 

+ 0 - 5
internal/editor/action.go

@@ -1,10 +1,5 @@
 package editor
 
-import (
-	//"charm.land/bubbles/v2/key"
-	//tea "charm.land/bubbletea/v2"
-)
-
 type Action = struct {
 	Binding  string
 	Command  string

+ 6 - 16
internal/editor/model.go

@@ -2,6 +2,10 @@ package editor
 
 import (
 	"moose/internal/buffer"
+	"github.com/zyedidia/rope"
+
+	"unicode/utf8"
+	"strings"
 )
 
 type Model struct {
@@ -15,7 +19,7 @@ type Model struct {
 
 func NewModel() Model {
 	initialBuf := buffer.Buffer{
-		Rope: nil,
+		Rope: rope.New([]byte{}),
 		CM: buffer.CursorManager{
 			Cursors:    []buffer.Cursor{{Offset: 0, Goal: 0}},
 			PrimaryIdx: 0,
@@ -38,19 +42,7 @@ func (m *Model) Quit() {
 	m.ShouldQuit = true
 }
 
-/*
-func (m Model) Init() tea.Cmd {
-	return nil
-}
-
-func (m Model) View() tea.View {
-	v := tea.NewView(m.Viewport.View())
-	v.AltScreen = true
-	v.MouseMode = tea.MouseModeCellMotion
-	return v
-}
-
-func (m Model) renderedContent() string {
+func (m Model) ToString() string {
 	content := []byte(m.Buffer.String())
 
 	cursorMap := make(map[int]bool)
@@ -101,5 +93,3 @@ func (m Model) renderedContent() string {
 
 	return out.String()
 }
-
-*/

+ 0 - 50
internal/editor/update.go

@@ -1,50 +0,0 @@
-package editor
-
-import (
-	//"fmt"
-	//"github.com/gdamore/tcell"
-
-)
-
-/*func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
-	switch msg := msg.(type) {
-	case tea.WindowSizeMsg:
-		m.Width = msg.Width
-		m.Height = msg.Height
-		m.Viewport.SetWidth(msg.Width)
-
-		h := msg.Height - 2
-		if h < 0 {
-			h = 0
-		}
-		m.Viewport.SetHeight(h)
-		return m, nil
-	case tea.MouseWheelMsg:
-		return m, nil
-	case tea.KeyPressMsg:
-		for i := range m.Actions {
-			action := m.Actions[i]
-
-			if key.Matches(msg, action.Binding) {
-				//fmt.Println(msg, action.Binding)
-				cmd := action.Callback(&m, []string{})
-
-				m.Viewport.SetContent(m.renderedContent())
-				return m, cmd
-			}
-		}
-
-		key := msg.Key()
-		if key.Text != "" {
-			for _, r := range key.Text {
-				m.Buffer.Insert(r)
-			}
-		}
-
-		m.Viewport.SetContent(m.renderedContent())
-		return m, nil
-	}
-
-	return m, nil
-}
-*/

+ 15 - 20
main.go

@@ -3,14 +3,10 @@ package main
 import (
 	"fmt"
 	"os"
-
+	"moose/internal/buffer"
 	"moose/internal/editor"
-
-	//"unicode/utf8"
 	"strings"
 	"github.com/gdamore/tcell/v3"
-
-	//tea "charm.land/bubbletea/v2"
 )
 
 func main() {
@@ -45,12 +41,12 @@ func main() {
 		s.Clear()
 
 		if m.ShouldQuit {
-			s.PutStrStyled(0, 2, "tried to quit", defStyle)
 			return
 		}
 
 		ev := <-s.EventQ()
 
+		outer:
 		switch ev := ev.(type) {
 		case *tcell.EventResize:
 			s.Sync()
@@ -59,29 +55,28 @@ func main() {
 				action := m.Actions[i]
 
 				if strings.ToLower(ev.Name()) == strings.ToLower(action.Binding) {
-					s.PutStrStyled(0, 1, "found match", defStyle)
 					action.Callback(&m, []string{})
-					break
+					break outer
 				}
 			}
 
-			//if utf8.RuneCountInString(ev.Name()) == 1 {
-			if ev.Name() != "" {
-				for _, r := range ev.Name() {
+			if ev.Key() == tcell.KeyRune {
+				for _, r := range ev.Str() {
 					m.Buffer.Insert(r)
 				}
 			}
+		}
 
-			s.PutStrStyled(0, 0, strings.ToLower(ev.Name()), defStyle)
+		table := strings.SplitAfter(m.Buffer.String(), "\n")
+		for i, line := range table {
+			s.PutStrStyled(0, i, line, defStyle)
 		}
+
+		for _, cur := range m.Buffer.CM.Cursors {
+			line, col := buffer.LineCol(m.Buffer.Rope, cur.Offset)
+			s.SetContent(col, line, ' ', nil, tcell.StyleDefault.Reverse(true))
+		}
+
 		s.Show()
 	}
-
-	//model := editor.NewModel()
-//
-	//p := tea.NewProgram(model)
-	//if _, err := p.Run(); err != nil {
-	//	fmt.Printf("moose: error: %v", err)
-	//	os.Exit(1)
-	//}
 }