src

Go monorepo.
Log | Files | Refs

commit 05de12b4b86cfcb2f855cfbdef432324b7e8ab01
parent 8ae64a9ef0bb29d7e78ec39614753908a1b752d3
Author: dwrz <dwrz@dwrz.net>
Date:   Fri, 16 Dec 2022 22:34:47 +0000

Refactor canvas writes

Diffstat:
Mpkg/editor/canvas/render.go | 16++++++++--------
Mpkg/editor/canvas/reset.go | 4++--
2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/pkg/editor/canvas/render.go b/pkg/editor/canvas/render.go @@ -29,12 +29,12 @@ func (c *Canvas) Render(b *buffer.Buffer, msg *message.Message) error { ) // Move the cursor to the top left. - c.buf.Write([]byte(terminal.CursorHide)) - c.buf.Write([]byte(terminal.CursorTopLeft)) + c.buf.WriteString(terminal.CursorHide) + c.buf.WriteString(terminal.CursorTopLeft) // Print each line. for _, line := range output.Lines { - c.buf.Write([]byte(terminal.EraseLine)) + c.buf.WriteString(terminal.EraseLine) c.buf.WriteString(line) c.buf.WriteString("\r\n") } @@ -46,10 +46,10 @@ func (c *Canvas) Render(b *buffer.Buffer, msg *message.Message) error { c.messageBar(msg, width) // Set the cursor. - c.buf.Write([]byte(fmt.Sprintf( + c.buf.WriteString(fmt.Sprintf( terminal.SetCursorFmt, output.Line, output.Glyph, - ))) - c.buf.Write([]byte(terminal.CursorShow)) + )) + c.buf.WriteString(terminal.CursorShow) c.out.Write(c.buf.Bytes()) @@ -59,7 +59,7 @@ func (c *Canvas) Render(b *buffer.Buffer, msg *message.Message) error { } func (c *Canvas) statusBar(b *buffer.Buffer, width, y, x int) { - c.buf.Write([]byte(terminal.EraseLine)) + c.buf.WriteString(terminal.EraseLine) c.buf.WriteString(color.Inverse) // Icon @@ -105,7 +105,7 @@ func (c *Canvas) statusBar(b *buffer.Buffer, width, y, x int) { // TODO: handle messages that are too long for one line. func (c *Canvas) messageBar(msg *message.Message, width int) { - c.buf.Write([]byte(terminal.EraseLine)) + c.buf.WriteString(terminal.EraseLine) switch { case msg == nil: c.buf.WriteString(fmt.Sprintf("%*s", width, " ")) diff --git a/pkg/editor/canvas/reset.go b/pkg/editor/canvas/reset.go @@ -3,6 +3,6 @@ package canvas import "code.dwrz.net/src/pkg/terminal" func (c *Canvas) Reset() { - c.out.Write([]byte(terminal.ClearScreen)) - c.out.Write([]byte(terminal.CursorTopLeft)) + c.out.WriteString(terminal.ClearScreen) + c.out.WriteString(terminal.CursorTopLeft) }