Skip to content

Commit 7cd719e

Browse files
Merge pull request #27 from debeando/terminal-refresh
fix - gofmt
2 parents 1cef686 + 02435dc commit 7cd719e

File tree

4 files changed

+39
-9
lines changed

4 files changed

+39
-9
lines changed
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
"time"
7+
8+
"github.com/debeando/go-common/terminal"
9+
)
10+
11+
func main() {
12+
terminal.Reset()
13+
terminal.Clear()
14+
terminal.Flush()
15+
16+
for i := 0; i < 10; i++ {
17+
// fmt.Print("\x1B7") // Save the cursor position
18+
// fmt.Print("\x1B[2K") // Erase the entire line
19+
// fmt.Print("\x1B[0J") // Erase from cursor to end of screen
20+
// fmt.Print("\x1B[?47h") // Save screen
21+
// fmt.Print("\x1B[1J") // Erase from cursor to beginning of screen
22+
// fmt.Print("\x1B[?47l") // Restore screen
23+
// defer fmt.Print("\x1B8") // Restore the cursor position util new size is calculated
24+
25+
terminal.Cursor(0, i)
26+
fmt.Println(strings.Repeat("=", i))
27+
// fmt.Printf("Progress: [\x1B[33m%3d%%\x1B[0m] %s", 2, "===")
28+
time.Sleep(100 * time.Millisecond)
29+
}
30+
}

_examples/terminal/table/main.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ func main() {
2626
tbl.Add("Batman v Superman: Dawn of Justice", 2017, 6.5, "742K")
2727
tbl.Add("Justice League", 2017, 6.1, "741K")
2828
tbl.Add("Zack Snyder's Justice League", 2021, 7.9, "427K")
29-
tbl.Column(0, table.Column{ Name: "Movie", Alignment: table.Right, Truncate: 20, Width: 21 })
30-
tbl.Column(1, table.Column{ Name: "Year"})
31-
tbl.Column(2, table.Column{ Name: "Rate", Percentage: true, Alignment: table.Right })
32-
tbl.Column(3, table.Column{ Name: "Votes"})
29+
tbl.Column(0, table.Column{Name: "Movie", Alignment: table.Right, Truncate: 20, Width: 21})
30+
tbl.Column(1, table.Column{Name: "Year"})
31+
tbl.Column(2, table.Column{Name: "Rate", Percentage: true, Alignment: table.Right})
32+
tbl.Column(3, table.Column{Name: "Votes"})
3333
// tbl.Column(2, table.Column{ZeroFill: true, Precision:3, Scale:1})
3434
tbl.FilterBy(1, ">= 2000")
3535
tbl.SortBy(2).Print()

table/value.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ func (f *Field) Truncate(t int) {
4444
func (f *Field) Clear() {
4545
if f.IsString() {
4646
t := f.ToString()
47-
t = strings.TrimSpace(t)
48-
t = strings.ReplaceAll(t, "\n", " ")
49-
t = strings.ReplaceAll(t, "\r", " ")
50-
t = strings.ReplaceAll(t, " ", " ")
47+
t = strings.TrimSpace(t)
48+
t = strings.ReplaceAll(t, "\n", " ")
49+
t = strings.ReplaceAll(t, "\r", " ")
50+
t = strings.ReplaceAll(t, " ", " ")
5151

5252
(*f).Value = t
5353
}

terminal/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func Refresh(wait int, f func()) {
147147
ScreenRestore()
148148
defer CursorRestore()
149149

150-
CursorSet(0,0)
150+
CursorSet(0, 0)
151151
Flush()
152152
f()
153153
time.Sleep(time.Duration(wait) * time.Second)

0 commit comments

Comments
 (0)