Compare commits
2 Commits
0b8aeca688
...
1bb6c16786
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1bb6c16786 | ||
|
|
bd179ccc99 |
@ -149,21 +149,36 @@ func (m Model) View() string {
|
||||
|
||||
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 {
|
||||
if i >= contentHeight {
|
||||
break
|
||||
}
|
||||
|
||||
lineNum := fmt.Sprintf("%*d ", lineNumWidth, i+1)
|
||||
|
||||
if i == m.row {
|
||||
if m.col == 0 {
|
||||
b.WriteString("█" + line + "\n")
|
||||
b.WriteString(lineNum + "█" + line + "\n")
|
||||
} else if m.col >= len(line) {
|
||||
b.WriteString(line + "█\n")
|
||||
b.WriteString(lineNum + line + "█\n")
|
||||
} else {
|
||||
b.WriteString(line[:m.col] + "█" + line[m.col:] + "\n")
|
||||
b.WriteString(lineNum + line[:m.col] + "█" + line[m.col:] + "\n")
|
||||
}
|
||||
} 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()
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user