diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..034854c --- /dev/null +++ b/Makefile @@ -0,0 +1,60 @@ +.PHONY: build test run clean lint fmt vet test-verbose test-coverage install build-full all + +INSTALL_DIR ?= /usr/local/bin + +BINARY_NAME=loom +BUILD_DIR=bin + +build: + go build -o $(BUILD_DIR)/$(BINARY_NAME) . + +build-full: + @echo "Building with version information..." + @VERSION=$$(git describe --tags --abbrev=0 2>/dev/null || echo "dev"); \ + COMMIT=$$(git rev-parse --short HEAD 2>/dev/null || echo "unknown"); \ + DATE=$$(date -u +%Y-%m-%dT%H:%M:%SZ); \ + echo "Version: $$VERSION"; \ + echo "Commit: $$COMMIT"; \ + echo "Date: $$DATE"; \ + go build -trimpath -ldflags="-s -w -X 'main.version=$$VERSION' -X 'main.commit=$$COMMIT' -X 'main.date=$$DATE'" -o $(BUILD_DIR)/$(BINARY_NAME) . + +install: + @echo "Building and installing $(BINARY_NAME)..." + @EXISTING=$$(which $(BINARY_NAME) 2>/dev/null); \ + DEST=$$([ -n "$$EXISTING" ] && dirname "$$EXISTING" || echo "$(INSTALL_DIR)"); \ + VERSION=$$([ -n "$(VERSION)" ] && echo "$(VERSION)" || git describe --tags --abbrev=0 2>/dev/null || echo "dev"); \ + COMMIT=$$(git rev-parse --short HEAD 2>/dev/null || echo "unknown"); \ + DATE=$$(date -u +%Y-%m-%dT%H:%M:%SZ); \ + echo "Version: $$VERSION"; \ + echo "Commit: $$COMMIT"; \ + echo "Date: $$DATE"; \ + go build -trimpath -ldflags="-s -w -X 'main.version=$$VERSION' -X 'main.commit=$$COMMIT' -X 'main.date=$$DATE'" -o $(BUILD_DIR)/$(BINARY_NAME) .; \ + install -m 755 $(BUILD_DIR)/$(BINARY_NAME) "$$DEST/$(BINARY_NAME)"; \ + echo "Installed to $$DEST/$(BINARY_NAME)" + +run: + go run . + +test: + go test ./... + +test-verbose: + go test -v ./... + +test-coverage: + go test -coverprofile=coverage.out ./... + go tool cover -html=coverage.out -o coverage.html + +clean: + rm -rf $(BUILD_DIR) + rm -f coverage.out coverage.html + +fmt: + go fmt ./... + +vet: + go vet ./... + +lint: fmt vet + +all: lint test build diff --git a/commit.go b/commit.go index 2076bb4..5951975 100644 --- a/commit.go +++ b/commit.go @@ -7,8 +7,8 @@ import ( "strings" "time" - tea "charm.land/bubbletea/v2" "charm.land/bubbles/v2/viewport" + tea "charm.land/bubbletea/v2" "charm.land/lipgloss/v2" ) @@ -345,7 +345,6 @@ func (m *commitModel) View() tea.View { sections = append(sections, footer) content := lipgloss.JoinVertical(lipgloss.Left, sections...) - v := tea.NewView(content) v.AltScreen = true return v diff --git a/diffview.go b/diffview.go index 6f2f8c8..fb0adbf 100644 --- a/diffview.go +++ b/diffview.go @@ -116,15 +116,15 @@ func funcRule() hlRule { } func goStringRule() hlRule { - return mustRule("`[^`]*`" + `|"(?:\\.|[^"\\])*"` + `|'(?:\\.|[^'\\])*'`, tokString) + return mustRule("`[^`]*`"+`|"(?:\\.|[^"\\])*"`+`|'(?:\\.|[^'\\])*'`, tokString) } func jsStringRule() hlRule { - return mustRule("`(?:\\.|[^`\\])*`" + `|"(?:\\.|[^"\\])*"` + `|'(?:\\.|[^'\\])*'`, tokString) + return mustRule("`(?:\\.|[^`\\])*`"+`|"(?:\\.|[^"\\])*"`+`|'(?:\\.|[^'\\])*'`, tokString) } func pyStringRule() hlRule { - return mustRule(`"""[\s\S]*?"""|'''[\s\S]*?'''` + `|"(?:\\.|[^"\\])*"` + `|'(?:\\.|[^'\\])*'`, tokString) + return mustRule(`"""[\s\S]*?"""|'''[\s\S]*?'''`+`|"(?:\\.|[^"\\])*"`+`|'(?:\\.|[^'\\])*'`, tokString) } func languageRules(lang string) []hlRule { @@ -369,12 +369,6 @@ func langFromPath(path string) string { return normalizeLang(ext) } -// detectLangFromPath returns a language hint for syntax highlighting from -// a file path. Returns "" for unknown/unsupported extensions. -func detectLangFromPath(path string) string { - return langFromPath(path) -} - // --- ANSI reset rewriting (from matcha) --- var resetRe = regexp.MustCompile(`\x1b\[0*m`) @@ -644,10 +638,8 @@ func parseUnifiedDiff(diff string) []diffFileChange { if curHunk != nil { curHunk.lines = append(curHunk.lines, diffLine{kind: diffContext, text: line[1:]}) } - case strings.HasPrefix(line, "\\"): - // "\ No newline at end of file" — skip default: - // skip other lines (index, mode, etc.) + // skip other lines (index, mode, "\ No newline", etc.) } } diff --git a/editor.go b/editor.go index 235973d..2704bb7 100644 --- a/editor.go +++ b/editor.go @@ -5,8 +5,8 @@ import ( "strings" "unicode/utf8" - tea "charm.land/bubbletea/v2" "charm.land/bubbles/v2/viewport" + tea "charm.land/bubbletea/v2" "charm.land/lipgloss/v2" "github.com/floatpane/bubble-overlay" ) @@ -73,9 +73,6 @@ func (e *editor) ensureVisible() { e.vp.EnsureVisible(e.row, e.col, e.col+1) } -func (e *editor) line() int { return e.row } -func (e *editor) column() int { return e.col } - // --- Editing operations --- func (e *editor) insertRune(r rune) { @@ -522,7 +519,6 @@ func insertCursorInColored(s string, col int) string { b.WriteString(currentSGR.String()) } i += size - visible++ // Copy the rest b.WriteString(s[i:]) return b.String() diff --git a/rebase.go b/rebase.go index 0439f54..8eb68f6 100644 --- a/rebase.go +++ b/rebase.go @@ -8,8 +8,8 @@ import ( "strings" "time" - tea "charm.land/bubbletea/v2" "charm.land/bubbles/v2/viewport" + tea "charm.land/bubbletea/v2" "charm.land/lipgloss/v2" ) @@ -22,17 +22,17 @@ type rebaseItem struct { } type rebaseModel struct { - path string - items []rebaseItem - cursor int - width int - height int - saved bool - err error - expanded int // -1 = no item expanded, otherwise index into items - diff string - diffErr error - diffVP viewport.Model + path string + items []rebaseItem + cursor int + width int + height int + saved bool + err error + expanded int // -1 = no item expanded, otherwise index into items + diff string + diffErr error + diffVP viewport.Model diffReady bool } @@ -50,7 +50,7 @@ func (m *rebaseModel) load() { m.err = err return } - defer f.Close() + defer func() { _ = f.Close() }() scanner := bufio.NewScanner(f) for scanner.Scan() { @@ -353,7 +353,7 @@ func (m *rebaseModel) View() tea.View { action := actionStyle(it.action).Render(it.action) hash := lipgloss.NewStyle().Foreground(lipgloss.Color("243")).Render(it.hash) - msg := it.msg + var msg string if m.expanded == i { msg = lipgloss.NewStyle().Bold(true).Render(it.msg) } else { diff --git a/suggest.go b/suggest.go index d611720..5765f3a 100644 --- a/suggest.go +++ b/suggest.go @@ -204,8 +204,10 @@ func (ps *peopleStore) save() { if err != nil { return } - os.MkdirAll(filepath.Dir(ps.filePath), 0755) - os.WriteFile(ps.filePath, data, 0644) + if err := os.MkdirAll(filepath.Dir(ps.filePath), 0755); err != nil { + return + } + _ = os.WriteFile(ps.filePath, data, 0644) } // addPerson adds a person to the store if not already present. @@ -289,7 +291,7 @@ func loadCoAuthors() []coAuthor { ps := newPeopleStore() result := make([]coAuthor, len(ps.people)) for i, p := range ps.people { - result[i] = coAuthor{name: p.name, email: p.email} + result[i] = coAuthor(p) } return result }