generated from atomicgo/template
-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from atomicgo/feat/live-area
- Loading branch information
Showing
5 changed files
with
83 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package cursor | ||
|
||
import ( | ||
"fmt" | ||
"runtime" | ||
"strings" | ||
) | ||
|
||
// Area displays content which can be updated on the fly. | ||
// You can use this to create live output, charts, dropdowns, etc. | ||
type Area struct { | ||
height int | ||
} | ||
|
||
// NewArea returns a new Area. | ||
func NewArea() Area { | ||
return Area{} | ||
} | ||
|
||
// Clear clears the content of the Area. | ||
func (area *Area) Clear() { | ||
Bottom() | ||
if area.height > 0 { | ||
ClearLinesUp(area.height) | ||
} | ||
} | ||
|
||
// Update overwrites the content of the Area. | ||
func (area *Area) Update(content string) { | ||
area.Clear() | ||
lines := strings.Split(content, "\n") | ||
if runtime.GOOS == "windows" { | ||
for _, line := range lines { | ||
fmt.Print(line) | ||
StartOfLineDown(1) | ||
} | ||
} else { | ||
for _, line := range lines { | ||
fmt.Println(line) | ||
} | ||
} | ||
height = 0 | ||
|
||
area.height = len(lines) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters