Skip to content

Commit

Permalink
Merge pull request #27 from debeando/terminal-refresh
Browse files Browse the repository at this point in the history
fix - gofmt
  • Loading branch information
nstrappazzonc committed Nov 26, 2023
2 parents 1cef686 + 02435dc commit 7cd719e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
30 changes: 30 additions & 0 deletions _examples/terminal/progress_bar/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

import (
"fmt"
"strings"
"time"

"github.com/debeando/go-common/terminal"
)

func main() {
terminal.Reset()
terminal.Clear()
terminal.Flush()

for i := 0; i < 10; i++ {
// fmt.Print("\x1B7") // Save the cursor position
// fmt.Print("\x1B[2K") // Erase the entire line
// fmt.Print("\x1B[0J") // Erase from cursor to end of screen
// fmt.Print("\x1B[?47h") // Save screen
// fmt.Print("\x1B[1J") // Erase from cursor to beginning of screen
// fmt.Print("\x1B[?47l") // Restore screen
// defer fmt.Print("\x1B8") // Restore the cursor position util new size is calculated

terminal.Cursor(0, i)
fmt.Println(strings.Repeat("=", i))
// fmt.Printf("Progress: [\x1B[33m%3d%%\x1B[0m] %s", 2, "===")
time.Sleep(100 * time.Millisecond)
}
}
8 changes: 4 additions & 4 deletions _examples/terminal/table/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ func main() {
tbl.Add("Batman v Superman: Dawn of Justice", 2017, 6.5, "742K")
tbl.Add("Justice League", 2017, 6.1, "741K")
tbl.Add("Zack Snyder's Justice League", 2021, 7.9, "427K")
tbl.Column(0, table.Column{ Name: "Movie", Alignment: table.Right, Truncate: 20, Width: 21 })
tbl.Column(1, table.Column{ Name: "Year"})
tbl.Column(2, table.Column{ Name: "Rate", Percentage: true, Alignment: table.Right })
tbl.Column(3, table.Column{ Name: "Votes"})
tbl.Column(0, table.Column{Name: "Movie", Alignment: table.Right, Truncate: 20, Width: 21})
tbl.Column(1, table.Column{Name: "Year"})
tbl.Column(2, table.Column{Name: "Rate", Percentage: true, Alignment: table.Right})
tbl.Column(3, table.Column{Name: "Votes"})
// tbl.Column(2, table.Column{ZeroFill: true, Precision:3, Scale:1})
tbl.FilterBy(1, ">= 2000")
tbl.SortBy(2).Print()
Expand Down
8 changes: 4 additions & 4 deletions table/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ func (f *Field) Truncate(t int) {
func (f *Field) Clear() {
if f.IsString() {
t := f.ToString()
t = strings.TrimSpace(t)
t = strings.ReplaceAll(t, "\n", " ")
t = strings.ReplaceAll(t, "\r", " ")
t = strings.ReplaceAll(t, " ", " ")
t = strings.TrimSpace(t)
t = strings.ReplaceAll(t, "\n", " ")
t = strings.ReplaceAll(t, "\r", " ")
t = strings.ReplaceAll(t, " ", " ")

(*f).Value = t
}
Expand Down
2 changes: 1 addition & 1 deletion terminal/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func Refresh(wait int, f func()) {
ScreenRestore()
defer CursorRestore()

CursorSet(0,0)
CursorSet(0, 0)
Flush()
f()
time.Sleep(time.Duration(wait) * time.Second)
Expand Down

0 comments on commit 7cd719e

Please sign in to comment.