Golang UX

Supported methods

The following UX elements are supported by the Golang SDK:

  • Print
  • ProgressBars
  • Spinners

To create a UX element in your Op, you need to create a new UX object.

func NewUx() *Ux

Alternatively, the Ux object is included in the Client object:

client := NewClient()
client.Ux.Print(...)

func (*Ux) Print

func (*Ux) Print(text string) error

Prints text to the output interface (e.g. terminal or Slack).

Example:

u := ctoai.NewUx()
err := u.Print("testing")
if err != nil {
    panic(err)
}

Output:

testing

func (*Ux) ProgressBarAdvance

func (*Ux) ProgressBarAdvance(increment int) error

ProgressBarAdvance adds onto a progressbar that is already present on the interface (e.g. terminal or Slack).

The increment indicates the additional length (out of total length) that will be filled.

Example:

...
[progressbar animation with 1/5 of the bar filled here] Downloading...
err := u.ProgressBarAdvance(1)
if err != nil {
    panic(err)
}

Output:

[progressbar animation with 2/5 of the bar filled here] Downloading...

func (*Ux) ProgressBarStart

func (*Ux) ProgressBarStart(length, initial int, message string) error

ProgressBarStart presents a progressbar on the output interface (i.e. terminal or slack) that will stay present until the progressbar stop method is called.

The input length is the total length of the progress bar, e.g. if you have 5 steps in your logic, then a unit length of 5 might be an appropriate length.

The initial length indicates the unit length (out of total length) that is initially filled at the start.

Example:

u := ctoai.NewUx()
err := u.ProgressBarStart(5, 1, "Downloading...")
if err != nil {
    panic(err)
}

Output:

[progressbar animation with 1/5 of the bar filled here] Downloading...

func (*Ux) ProgressBarStop

func (*Ux) ProgressBarStop(message string) error

ProgressBarStop completes a progressbar that is already present on the interface (i.e. terminal or Slack).

The message will change the initial text (set from the ux.ProgressBarStart method).

Example:

...
[progressbar animation with 2/5 of the bar filled here] Downloading...
err := u.ProgressBarStop("Done!")
if err != nil {
    panic(err)
}

Output:

[progressbar animation with 5/5 of the bar filled here] Done!

func (*Ux) SpinnerStart

func (*Ux) SpinnerStart(text string) error

SpinnerStart presents a spinner on the output interface (e.g. terminal or Slack) that will spin until the SpinnerStop method is called.

Example:

u := ctoai.NewUx()
err := u.SpinnerStart("Starting process...")
if err != nil {
    panic(err)
}

Output:

[spinner emoji w/ spinner animation here] Starting process...

func (*Ux) SpinnerStop

func (*Ux) SpinnerStop(text string) error

SpinnerStop stops a spinner that has been previously started on the interface (e.g. terminal or Slack).

Example:

... //previous spinner started here
err := u.SpinnerStop("Done!")
if err != nil {
    panic(err)
}

Output:

[spinner completed completed here] Done!

🚀 What's next?

  • If you want to explore the options offered by our SDKs, go to the Golang SDK page.
  • To see which prompts we offer for this SDK, you can go to Golang Prompts page.