这是indexloc提供的服务,不要输入任何密码
Skip to content

Outputting to multiple lines #14

@g3kk0

Description

@g3kk0

This is more a question than an issue.

I'd like to output and update the status of a list of tasks:

e.g.

Task1... Done
Task2... Done
Task3... Running
Task4... 

I've attempted to do this using multiple Fprintf statements as follows:

w := uilive.New()
w.Start()

for i := 0; i <= 60; i++ {
  var t1, t2, t3, t4 string

  if i > 2 {
    t1 = "Done     "
    t2 = "Running"
  }
  if i > 5 {
    t1 = "Done     "
    t2 = "Done     "
    t3 = "Running"
  }
  if i > 7 {
    t1 = "Done     "
    t2 = "Done     "
    t3 = "Done     "
    t4 = "Running"
  }
  if i > 9 {
    t1 = "Done     "
    t2 = "Done     "
    t3 = "Done     "
    t4 = "Done     "
  }

  fmt.Fprintf(w, "Task1...  %s\n", t1)
  fmt.Fprintf(w, "Task2...  %s\n", t2)
  fmt.Fprintf(w, "Task3...  %s\n", t3)
  fmt.Fprintf(w, "Task4...  %s\n", t4)
  time.Sleep(time.Second)
}

w.Stop()

This initially appears to work fine however on some iterations various tasks disappear and then reappear.

e.g.

# I get this
Task3...  Done
Task4...  Done

# instead of
Task1...  Done
Task2...  Done
Task3...  Done
Task4...  Done

Am I using this incorrectly or could this possibly be a bug?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions