Skip to content

Commit

Permalink
code style, add function
Browse files Browse the repository at this point in the history
  • Loading branch information
geremachek committed Nov 19, 2021
1 parent 74741df commit d700fc6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions ui/draw.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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))
}
12 changes: 9 additions & 3 deletions ui/linebuff.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
}
}
Expand All @@ -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

Expand All @@ -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)
}
4 changes: 2 additions & 2 deletions ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand All @@ -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
Expand Down

0 comments on commit d700fc6

Please sign in to comment.