From 4d6c901282a9e47e3e9ac21c1d12e7300365f0d4 Mon Sep 17 00:00:00 2001 From: freyja Date: Mon, 1 Nov 2021 16:51:34 -0700 Subject: [PATCH] effective deletion of unicode characters --- stack/parse.go | 4 +--- ui/linebuff.go | 12 ++++++------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/stack/parse.go b/stack/parse.go index 72bb152..a2710c5 100644 --- a/stack/parse.go +++ b/stack/parse.go @@ -21,7 +21,7 @@ func parseValue(v string) (float64, error) { // parse commands... -func (s *Stack) parseCommand(c cmd.Command) (err error) { +func (s *Stack) parseCommand(c cmd.Command) { switch c { case cmd.Pop: s.pop() case cmd.Swap: s.swap() @@ -51,8 +51,6 @@ func (s *Stack) parseCommand(c cmd.Command) (err error) { case cmd.Atan: s.operateSingle(s.atan) case cmd.Fact: s.operateSingle(ari.FactW) } - - return } // value... command... error? Deal with them all! diff --git a/ui/linebuff.go b/ui/linebuff.go index 7fc049e..0dab898 100644 --- a/ui/linebuff.go +++ b/ui/linebuff.go @@ -6,19 +6,19 @@ import ( ) type lineBuff struct { - buffer string + buffer []rune locX int locY int } func newLineBuff(x, y int) *lineBuff { - return &lineBuff { "", x, y } + return &lineBuff { nil, x, y } } func (lb lineBuff) text() string { - return lb.buffer + return string(lb.buffer) } // show our cursor @@ -30,7 +30,7 @@ func (lb lineBuff) showPos(s tcell.Screen) { // add a char... func (lb *lineBuff) push(s tcell.Screen, ch rune) { - lb.buffer += string(ch) + lb.buffer = append(lb.buffer, ch) s.SetContent(lb.locX, lb.locY, ch, []rune(""), tcell.StyleDefault) // move and show the cursor @@ -43,7 +43,7 @@ func (lb *lineBuff) push(s tcell.Screen, ch rune) { func (lb *lineBuff) delete(s tcell.Screen) { if l := len(lb.buffer); l > 0 { // buffer is not empty - lb.buffer = lb.buffer[:l-1] // remove the char + lb.buffer = lb.buffer[:l-1] lb.locX-- // move curs back // erase it from the screen @@ -63,7 +63,7 @@ func (lb *lineBuff) refresh(s tcell.Screen) { // reset and show the cursor lb.locX = 0 - lb.buffer = "" + lb.buffer = nil lb.showPos(s) }