Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #35 from coryb/erase-flags
Browse files Browse the repository at this point in the history
fix incompat issues between posix and windows EraseInLine arguments
  • Loading branch information
AlecAivazis authored Apr 18, 2017
2 parents c204e78 + 6a1b406 commit c0034b8
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 20 deletions.
2 changes: 1 addition & 1 deletion confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (c *Confirm) Cleanup(rl *readline.Instance, val interface{}) error {
// go up one line
terminal.CursorPreviousLine(1)
// clear the line
terminal.EraseInLine(0)
terminal.EraseLine(terminal.ERASE_LINE_ALL)

// the string version of the answer
ans := ""
Expand Down
2 changes: 1 addition & 1 deletion input.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (i *Input) Cleanup(rl *readline.Instance, val interface{}) error {
// go up one line
terminal.CursorPreviousLine(1)
// clear the line
terminal.EraseInLine(0)
terminal.EraseLine(terminal.ERASE_LINE_ALL)

// render the template
out, err := core.RunTemplate(
Expand Down
6 changes: 3 additions & 3 deletions multiselect.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (m *MultiSelect) render() error {
// clean up what we left behind last time
for range m.Options {
terminal.CursorPreviousLine(1)
terminal.EraseInLine(0)
terminal.EraseLine(terminal.ERASE_LINE_ALL)
}

// render the template summarizing the current state
Expand Down Expand Up @@ -170,10 +170,10 @@ func (m *MultiSelect) Prompt(rl *readline.Instance) (interface{}, error) {
// Cleanup removes the options section, and renders the ask like a normal question.
func (m *MultiSelect) Cleanup(rl *readline.Instance, val interface{}) error {
terminal.CursorPreviousLine(1)
terminal.EraseInLine(0)
terminal.EraseLine(terminal.ERASE_LINE_ALL)
for range m.Options {
terminal.CursorPreviousLine(1)
terminal.EraseInLine(0)
terminal.EraseLine(terminal.ERASE_LINE_ALL)
}

// execute the output summary template with the answer
Expand Down
6 changes: 3 additions & 3 deletions select.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (s *Select) OnChange(line []rune, pos int, key rune) (newLine []rune, newPo
func (s *Select) render() error {
for range s.Options {
terminal.CursorPreviousLine(1)
terminal.EraseInLine(0)
terminal.EraseLine(terminal.ERASE_LINE_ALL)
}

// the formatted response
Expand Down Expand Up @@ -153,10 +153,10 @@ func (s *Select) Prompt(rl *readline.Instance) (interface{}, error) {

func (s *Select) Cleanup(rl *readline.Instance, val interface{}) error {
terminal.CursorPreviousLine(1)
terminal.EraseInLine(0)
terminal.EraseLine(terminal.ERASE_LINE_ALL)
for range s.Options {
terminal.CursorPreviousLine(1)
terminal.EraseInLine(0)
terminal.EraseLine(terminal.ERASE_LINE_ALL)
}

// execute the output summary template with the answer
Expand Down
14 changes: 6 additions & 8 deletions terminal/display.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// +build !windows

package terminal

import (
"fmt"
)
type EraseLineMode int

func EraseInLine(mode int) {
fmt.Printf("\x1b[%dK", mode)
}
const (
ERASE_LINE_END EraseLineMode = iota
ERASE_LINE_START
ERASE_LINE_ALL
)
11 changes: 11 additions & 0 deletions terminal/display_posix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// +build !windows

package terminal

import (
"fmt"
)

func EraseLine(mode EraseLineMode) {
fmt.Printf("\x1b[%dK", mode)
}
8 changes: 4 additions & 4 deletions terminal/display_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"unsafe"
)

func EraseInLine(mode int) {
func EraseLine(mode EraseLineMode) {
handle := syscall.Handle(os.Stdout.Fd())

var csbi consoleScreenBufferInfo
Expand All @@ -16,11 +16,11 @@ func EraseInLine(mode int) {
var x short
cursor := csbi.cursorPosition
switch mode {
case 1:
case ERASE_LINE_END:
x = csbi.size.x
case 2:
case ERASE_LINE_START:
x = 0
case 3:
case ERASE_LINE_ALL:
cursor.x = 0
x = csbi.size.x
}
Expand Down

0 comments on commit c0034b8

Please sign in to comment.