diff --git a/internal/action/window.go b/internal/action/window.go index 553cdaa..783ebc5 100644 --- a/internal/action/window.go +++ b/internal/action/window.go @@ -1,5 +1,9 @@ package action +import ( + "strings" +) + // TODO: No more global settings, window-wide settings type WinOptions struct { // Number bool @@ -83,8 +87,56 @@ func (w *Window) AdjustScroll() { // ================================================== // View methods // ================================================== -func (w *Window) View() { +// Window.View ... +func (w *Window) View(m Model) string { + buf := w.Buffer + + viewport := w.Height - 2 // command bar (1) + status line (1) + start := w.ScrollY + end := w.ScrollY + viewport + + var view strings.Builder + + for i := start; i < end; i++ { + // past the file, just draw the '~' + if i >= buf.LineCount() { + // TODO: Handle gutter and line numbers + view.WriteString("~") + view.WriteString("\n") + continue + } + + line := w.drawLine(m, buf.Line(i), i) + view.WriteString(line) + + // Break to next line + view.WriteString("\n") + } + + return view.String() +} + +// TODO: Only pass what we need from the model, not the entire model. +func (w *Window) drawLine(m Model, line string, lineNum int) string { + chars := []rune(line) + + for col := 0; col <= len(chars); col++ { + // Currently on the cursor + if w.Cursor.Line == lineNum && w.Cursor.Col == col { + if col < len(chars) { + return m.Styles().CursorStyle(m.Mode()).Render(string(chars[col])) + } else { + return m.Styles().CursorStyle(m.Mode()).Render(" ") + } + } + } + + return "" +} + +func (w *Window) drawGutter() string { + return "" } // ================================================== diff --git a/internal/editor/view.go b/internal/editor/view.go index ea58a0f..abde91f 100644 --- a/internal/editor/view.go +++ b/internal/editor/view.go @@ -61,6 +61,8 @@ func posIsAnchor(m Model, col, line int) bool { func (m Model) View() string { win := m.ActiveWindow() + return win.View(m) + buf := m.ActiveBuffer() var view strings.Builder