这是indexloc提供的服务,不要输入任何密码
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions writer_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ package uilive

import (
"fmt"
"strings"
)

// clear the line and move the cursor up
var clear = fmt.Sprintf("%c[%dA%c[2K", ESC, 1, ESC)

func (w *Writer) clearLines() {
for i := 0; i < w.lineCount; i++ {
fmt.Fprintf(w.Out, "%c[2K", ESC) // clear the line
fmt.Fprintf(w.Out, "%c[%dA", ESC, 1) // move the cursor up
}
fmt.Fprint(w.Out, strings.Repeat(clear, w.lineCount))
}
12 changes: 7 additions & 5 deletions writer_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ package uilive

import (
"fmt"
"github.com/mattn/go-isatty"
"strings"
"syscall"
"unsafe"

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

var kernel32 = syscall.NewLazyDLL("kernel32.dll")
Expand All @@ -18,6 +20,9 @@ var (
procFillConsoleOutputAttribute = kernel32.NewProc("FillConsoleOutputAttribute")
)

// clear the line and move the cursor up
var clear = fmt.Sprintf("%c[%dA%c[2K", ESC, 1, ESC)

type short int16
type dword uint32
type word uint16
Expand Down Expand Up @@ -48,10 +53,7 @@ func (w *Writer) clearLines() {
ok = false
}
if !ok {
for i := 0; i < w.lineCount; i++ {
fmt.Fprintf(w.Out, "%c[%dA", ESC, 0) // move the cursor up
fmt.Fprintf(w.Out, "%c[2K\r", ESC) // clear the line
}
fmt.Fprint(w.Out, strings.Repeat(clear, w.lineCount))
return
}
fd := f.Fd()
Expand Down