Compare commits

...

2 Commits

Author SHA1 Message Date
Keiran
1bb6c16786 add line numbers 2025-08-06 10:11:05 +01:00
Keiran
bd179ccc99 use a proper status bar (just row:col for now) 2025-08-06 10:09:33 +01:00

View File

@ -149,21 +149,36 @@ func (m Model) View() string {
b.WriteString("Text Editor (Ctrl+C or Esc to quit)\n\n") b.WriteString("Text Editor (Ctrl+C or Esc to quit)\n\n")
contentHeight := m.height - 4
lineNumWidth := len(fmt.Sprintf("%d", len(m.lines))) + 1
for i, line := range m.lines { for i, line := range m.lines {
if i >= contentHeight {
break
}
lineNum := fmt.Sprintf("%*d ", lineNumWidth, i+1)
if i == m.row { if i == m.row {
if m.col == 0 { if m.col == 0 {
b.WriteString("█" + line + "\n") b.WriteString(lineNum + "█" + line + "\n")
} else if m.col >= len(line) { } else if m.col >= len(line) {
b.WriteString(line + "█\n") b.WriteString(lineNum + line + "█\n")
} else { } else {
b.WriteString(line[:m.col] + "█" + line[m.col:] + "\n") b.WriteString(lineNum + line[:m.col] + "█" + line[m.col:] + "\n")
} }
} else { } else {
b.WriteString(line + "\n") b.WriteString(lineNum + line + "\n")
} }
} }
b.WriteString(fmt.Sprintf("\nRow: %d, Col: %d", m.row+1, m.col+1)) for i := len(m.lines); i < contentHeight; i++ {
b.WriteString("\n")
}
statusBar := fmt.Sprintf("%d:%d", m.row+1, m.col+1)
padding := strings.Repeat(" ", m.width-len(statusBar))
b.WriteString(padding + statusBar)
return b.String() return b.String()
} }