Display a row of text

This commit is contained in:
Timothy Warren 2021-03-30 18:00:06 -04:00
parent c455562703
commit b34c146aba
5 changed files with 38 additions and 18 deletions

View File

@ -27,6 +27,7 @@ func (e *editor) RefreshScreen() {
func (e *editor) drawRows(ab *buffer) {
for y :=0; y < e.screen.Rows; y += 1 {
if y >= e.screen.Rows {
if y == e.screen.Rows / 3 {
welcome := fmt.Sprintf("Gilo editor -- version %s", KiloVersion)
if len(welcome) > e.screen.Cols {
@ -48,6 +49,10 @@ func (e *editor) drawRows(ab *buffer) {
} else {
ab.appendRune('~')
}
} else {
ab.append(string(e.rows[0].chars))
}
ab.append(terminal.ClearLine)

View File

@ -27,6 +27,10 @@ func New() *editor {
return &editor{screen, cursor, rows }
}
func (e *editor) Open() {
e.rows = append(e.rows, NewRow("Hello, world!"))
}
func (e *editor) ProcessKeypress() bool {
var str string

View File

@ -1,7 +1,9 @@
// Helper functions
package editor
import "strings"
// Truncate a string to a length
func truncateString(s string, length int) string {
if length < 1 {
return ""
@ -22,10 +24,12 @@ func truncateString(s string, length int) string {
return buf.String()
}
// Is this an ASCII character?
func isAscii(char rune) bool {
return char < 0x80
}
// Is this an ASCII ctrl character?
func isCtrl(char rune) bool {
if !isAscii(char) {
return false

View File

@ -4,8 +4,14 @@ type row struct {
chars []rune
}
func NewRow() *row {
return &row {}
func NewRow(s string) *row {
var chars []rune
for _, ch := range s {
chars = append(chars, ch)
}
return &row {chars}
}
func (r *row) Size() int {

View File

@ -22,6 +22,7 @@ func main() {
defer cleanup(oldState)
e := editor.New()
e.Open()
// The input loop
for {