Skip to content

Commit

Permalink
Add SetCursor
Browse files Browse the repository at this point in the history
  • Loading branch information
blp1526 committed Jan 16, 2018
1 parent 0540938 commit 8ef4817
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ $ isac

|Name|Description|
|-|-|
|ESC, C-c|exit|
|C-c|exit|
|Arrow Up, C-p|move current row up|
|Arrow Down, C-n|move current row down|
|C-u|power on current row's server|
Expand Down
23 changes: 13 additions & 10 deletions lib/isac.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ MAINLOOP:
switch ev.Type {
case termbox.EventKey:
switch ev.Key {
case termbox.KeyEsc, termbox.KeyCtrlC:
case termbox.KeyCtrlC:
break MAINLOOP
case termbox.KeyArrowUp, termbox.KeyCtrlP:
i.currentRowUp()
Expand Down Expand Up @@ -140,21 +140,22 @@ func (i *Isac) draw(message string) {
lines := []string{
"Quick reference for isac keybindings:",
"",
"<ESC>, <C-c> exit",
"<Arrow Up>, <C-p> move current row up",
"<Arrow Down>, <C-n> move current row down",
"<C-u> power on current row's server",
"<C-r> refresh rows",
"<BackSpace, C-b>, <C-h> delete a filter character",
"<C-s> sort rows",
"<C-/> show help",
"<Enter> show current row's detail",
"<C-c> exit",
"<Arrow Up>, <C-p> move current row up",
"<Arrow Down>, <C-n> move current row down",
"<C-u> power on current row's server",
"<C-r> refresh rows",
"<BackSpace>, C-b>, <C-h> delete a filter character",
"<C-s> sort rows",
"<C-/> show help",
"<Enter> show current row's detail",
}

for index, line := range lines {
i.setLine(index, line)
}

termbox.HideCursor()
termbox.Flush()
return
}
Expand All @@ -180,6 +181,7 @@ func (i *Isac) draw(message string) {
i.setLine(index, line)
}

termbox.HideCursor()
termbox.Flush()
return
}
Expand Down Expand Up @@ -215,6 +217,7 @@ func (i *Isac) draw(message string) {
}

headers := i.row.Headers(i.message, strings.Join(i.zones, ", "), len(servers), i.currentNo(), i.filter)
termbox.SetCursor(i.row.CursorX, i.row.CursorY)

for index, header := range headers {
i.setLine(index, header)
Expand Down
29 changes: 21 additions & 8 deletions lib/row/row.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package row

import "fmt"
import (
"fmt"

runewidth "github.com/mattn/go-runewidth"
)

type Row struct {
MovableBottom int
Current int
CursorX int
CursorY int
}

func New() *Row {
Expand All @@ -15,14 +21,21 @@ func New() *Row {
func (r *Row) Headers(message string, zones string, totalServers int, currentNo int, filter string) (headers []string) {
id := fmt.Sprintf("%-12v", "ID")

headers = []string{
fmt.Sprintf("isac Message: %v", message),
fmt.Sprintf("Selected Zones: %v", zones),
fmt.Sprintf("Total Servers: %v, Current No.: %v", totalServers, currentNo),
fmt.Sprintf("Filter: %v", filter),
fmt.Sprintf(""),
fmt.Sprintf("Zone %v Status Name", id),
headers = append(headers, fmt.Sprintf("isac Message: %v", message))
headers = append(headers, fmt.Sprintf("Selected Zones: %v", zones))
headers = append(headers, fmt.Sprintf("Total Servers: %v, Current No.: %v", totalServers, currentNo))
headers = append(headers, fmt.Sprintf("Filter: %v", filter))

r.CursorY = len(headers) - 1
runes := []rune(headers[r.CursorY])
x := 0
for _, r := range runes {
x += runewidth.RuneWidth(r)
}
r.CursorX = x

headers = append(headers, fmt.Sprintf(""))
headers = append(headers, fmt.Sprintf("Zone %v Status Name", id))

return headers
}
Expand Down

0 comments on commit 8ef4817

Please sign in to comment.