Skip to content

Commit

Permalink
feat: improve terminal package
Browse files Browse the repository at this point in the history
  • Loading branch information
ravisuhag committed Nov 1, 2024
1 parent ac53404 commit 4175b9d
Show file tree
Hide file tree
Showing 10 changed files with 301 additions and 231 deletions.
22 changes: 7 additions & 15 deletions term/color.go → printer/color.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package term
package printer

import (
"fmt"
Expand Down Expand Up @@ -59,20 +59,20 @@ func NewColorScheme() *ColorScheme {

var cs = NewColorScheme()

func Bold(t ...string) string {
func bold(t ...string) string {
return termenv.String(t...).Bold().String()
}

func Boldf(t string, args ...interface{}) string {
return Bold(fmt.Sprintf(t, args...))
func boldf(t string, args ...interface{}) string {
return bold(fmt.Sprintf(t, args...))
}

func Italic(t ...string) string {
func italic(t ...string) string {
return termenv.String(t...).Italic().String()
}

func Italicf(t string, args ...interface{}) string {
return Italic(fmt.Sprintf(t, args...))
func italicf(t string, args ...interface{}) string {
return italic(fmt.Sprintf(t, args...))
}

func Green(t ...string) string {
Expand Down Expand Up @@ -131,14 +131,6 @@ func Magentaf(t string, args ...interface{}) string {
return Magenta(fmt.Sprintf(t, args...))
}

func SuccessIcon() string {
return termenv.String("✓").String()
}

func WarningIcon() string {
return termenv.String("!").String()
}

func FailureIcon() string {
return termenv.String("✘").String()
}
4 changes: 2 additions & 2 deletions printer/spinner.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"time"

"github.com/briandowns/spinner"
"github.com/raystack/salt/term"
"github.com/raystack/salt/terminal"
)

type Indicator struct {
Expand All @@ -20,7 +20,7 @@ func (s *Indicator) Stop() {

func Spin(label string) *Indicator {
set := spinner.CharSets[11]
if !term.IsTTY() {
if !terminal.IsTTY() {
return &Indicator{}
}
s := spinner.New(set, 120*time.Millisecond, spinner.WithColor("fgCyan"))
Expand Down
52 changes: 25 additions & 27 deletions printer/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,108 +2,106 @@ package printer

import (
"fmt"

"github.com/raystack/salt/term"
)

func Success(t ...string) {
fmt.Print(term.Green(t...))
fmt.Print(Green(t...))
}

func Successln(t ...string) {
fmt.Println(term.Green(t...))
fmt.Println(Green(t...))
}

func Successf(t string, args ...interface{}) {
fmt.Print(term.Greenf(t, args...))
fmt.Print(Greenf(t, args...))
}

func Warning(t ...string) {
fmt.Print(term.Yellow(t...))
fmt.Print(Yellow(t...))
}

func Warningln(t ...string) {
fmt.Println(term.Yellow(t...))
fmt.Println(Yellow(t...))
}

func Warningf(t string, args ...interface{}) {
fmt.Print(term.Yellowf(t, args...))
fmt.Print(Yellowf(t, args...))
}

func Error(t ...string) {
fmt.Print(term.Red(t...))
fmt.Print(Red(t...))
}

func Errorln(t ...string) {
fmt.Println(term.Red(t...))
fmt.Println(Red(t...))
}

func Errorf(t string, args ...interface{}) {
fmt.Print(term.Redf(t, args...))
fmt.Print(Redf(t, args...))
}

func Info(t ...string) {
fmt.Print(term.Cyan(t...))
fmt.Print(Cyan(t...))
}

func Infoln(t ...string) {
fmt.Println(term.Cyan(t...))
fmt.Println(Cyan(t...))
}

func Infof(t string, args ...interface{}) {
fmt.Print(term.Cyanf(t, args...))
fmt.Print(Cyanf(t, args...))
}

func Bold(t ...string) {
fmt.Print(term.Bold(t...))
fmt.Print(bold(t...))
}

func Boldln(t ...string) {
fmt.Println(term.Bold(t...))
fmt.Println(bold(t...))
}

func Boldf(t string, args ...interface{}) {
fmt.Print(term.Boldf(t, args...))
fmt.Print(boldf(t, args...))
}

func Italic(t ...string) {
fmt.Print(term.Italic(t...))
fmt.Print(italic(t...))
}

func Italicln(t ...string) {
fmt.Println(term.Italic(t...))
fmt.Println(italic(t...))
}

func Italicf(t string, args ...interface{}) {
fmt.Print(term.Italicf(t, args...))
fmt.Print(italicf(t, args...))
}

func Text(t ...string) {
fmt.Print(term.Grey(t...))
fmt.Print(Grey(t...))
}

func Textln(t ...string) {
fmt.Println(term.Grey(t...))
fmt.Println(Grey(t...))
}

func Textf(t string, args ...interface{}) {
fmt.Print(term.Greyf(t, args...))
fmt.Print(Greyf(t, args...))
}

func SuccessIcon() {
fmt.Print(term.Green("✓"))
fmt.Print(Green("✓"))
}

func WarningIcon() {
fmt.Print(term.Yellow("!"))
fmt.Print(Yellow("!"))
}

func ErrorIcon() {
fmt.Print(term.Red("✗"))
fmt.Print(Red("✗"))
}

func InfoIcon() {
fmt.Print(term.Cyan("⛭"))
fmt.Print(Cyan("⛭"))
}

func Space() {
Expand Down
46 changes: 0 additions & 46 deletions term/browser.go

This file was deleted.

118 changes: 0 additions & 118 deletions term/pager.go

This file was deleted.

22 changes: 0 additions & 22 deletions term/term.go

This file was deleted.

2 changes: 1 addition & 1 deletion term/brew.go → terminal/brew.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package term
package terminal

import (
"os/exec"
Expand Down
Loading

0 comments on commit 4175b9d

Please sign in to comment.