From d700fc68ed91dc755c88509ad8d716bf2356855b Mon Sep 17 00:00:00 2001 From: freyja Date: Thu, 18 Nov 2021 21:47:13 -0800 Subject: [PATCH] code style, add function --- ui/draw.go | 4 ++-- ui/linebuff.go | 12 +++++++++--- ui/ui.go | 4 ++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/ui/draw.go b/ui/draw.go index f2ab52a..96c7897 100644 --- a/ui/draw.go +++ b/ui/draw.go @@ -8,7 +8,7 @@ import ( // draw text to the screen -func addstr(s tcell.Screen, style tcell.Style, x int, y int, text string) { +func addString(s tcell.Screen, style tcell.Style, x int, y int, text string) { curs := x for _, ch := range text { @@ -28,5 +28,5 @@ func drawAligned(s tcell.Screen, x, y, width int, text string) { disp = disp[:l - (l - width) - 3] + "..." } - addstr(s, tcell.StyleDefault, x, y, fmt.Sprintf("%" + strconv.Itoa(width) + "s", disp)) + addString(s, tcell.StyleDefault, x, y, fmt.Sprintf("%" + strconv.Itoa(width) + "s", disp)) } diff --git a/ui/linebuff.go b/ui/linebuff.go index 0dab898..23a63ac 100644 --- a/ui/linebuff.go +++ b/ui/linebuff.go @@ -31,7 +31,7 @@ func (lb lineBuff) showPos(s tcell.Screen) { func (lb *lineBuff) push(s tcell.Screen, ch rune) { lb.buffer = append(lb.buffer, ch) - s.SetContent(lb.locX, lb.locY, ch, []rune(""), tcell.StyleDefault) + lb.drawChar(s, ch) // move and show the cursor @@ -48,7 +48,7 @@ func (lb *lineBuff) delete(s tcell.Screen) { // erase it from the screen - s.SetContent(lb.locX, lb.locY, ' ', []rune(""), tcell.StyleDefault) + lb.drawChar(s, ' ') lb.showPos(s) } } @@ -58,7 +58,7 @@ func (lb *lineBuff) delete(s tcell.Screen) { func (lb *lineBuff) refresh(s tcell.Screen) { // clear the line - addstr(s, tcell.StyleDefault, 0, lb.locY, strings.Repeat(" ", len(lb.buffer))) + addString(s, tcell.StyleDefault, 0, lb.locY, strings.Repeat(" ", len(lb.buffer))) // reset and show the cursor @@ -67,3 +67,9 @@ func (lb *lineBuff) refresh(s tcell.Screen) { lb.showPos(s) } + +// draw a character at the current cursor position + +func (lb lineBuff) drawChar(s tcell.Screen, ch rune) { + s.SetContent(lb.locX, lb.locY, ch, []rune{}, tcell.StyleDefault) +} diff --git a/ui/ui.go b/ui/ui.go index fdd0b04..9c19786 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -50,7 +50,7 @@ func (u *ui) drawStackWindow() { func (u *ui) clearStackWindow(lines int) { for y := u.height-1; y >= u.height-lines; y-- { - addstr(u.scr, tcell.StyleDefault, 0, y, u.clearLine) + addString(u.scr, tcell.StyleDefault, 0, y, u.clearLine) } } @@ -71,7 +71,7 @@ func (u ui) drawAngleMode() { // draw the barrier decoration... func (u ui) drawLine() { - addstr(u.scr, tcell.StyleDefault, 0, u.height, strings.Repeat(bar, u.width)) + addString(u.scr, tcell.StyleDefault, 0, u.height, strings.Repeat(bar, u.width)) } // match keys with actions