Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SpinGroup.puts_above #564

Merged
merged 1 commit into from
Dec 2, 2024
Merged

Add SpinGroup.puts_above #564

merged 1 commit into from
Dec 2, 2024

Conversation

joshheinrichs-shopify
Copy link
Contributor

@joshheinrichs-shopify joshheinrichs-shopify commented Nov 7, 2024

This is useful for things like printing out a stream of logs while you have one or more spinners reporting on the current status. We could also add Spinner.puts_above, but when you have multiple Spinners, "above" is kind of ambiguous. We can add it later if the need becomes obvious.

@joshheinrichs-shopify joshheinrichs-shopify force-pushed the spinner-puts branch 4 times, most recently from 5ae7c2d to 5ef9217 Compare November 7, 2024 19:55
@joshheinrichs-shopify joshheinrichs-shopify changed the title Add SpinGroup.puts Add support for printing above spinners Nov 7, 2024
@joshheinrichs-shopify joshheinrichs-shopify changed the title Add support for printing above spinners Add SpinGroup.puts_above Dec 2, 2024
@joshheinrichs-shopify joshheinrichs-shopify marked this pull request as ready for review December 2, 2024 21:52
@joshheinrichs-shopify joshheinrichs-shopify requested a review from a team as a code owner December 2, 2024 21:52
@joshheinrichs-shopify
Copy link
Contributor Author

joshheinrichs-shopify commented Dec 2, 2024

small example

require 'cli/ui'

CLI::UI::StdoutRouter.enable

CLI::UI::Frame.open('frame') do |f|
  CLI::UI::SpinGroup.new do |sg|
    sg.failure_debrief {}
    sg.add("running tests: {{@widget/status:0:0:1:4}}") do |spinner|
      n_jobs = 5
      n_passed = 0
      n_failed = 0
      (1..(n_jobs)).each do |n|
        sleep(2.5)
        passed = n != 3
        if passed
          sg.puts_above("{{v}} job #{n} passed")
          n_passed += 1
        else
          sg.puts_above("{{x}} job #{n} failed\n{{red:  └── /path/to/output.log}}")
          n_failed += 1
        end
        spinner.update_title("running jobs: {{@widget/status:#{n_passed}:#{n_failed}:1:#{n_jobs - n}}}")
      end
      spinner.update_title("ran jobs: {{@widget/status:#{n_passed}:#{n_failed}:0:0}}")
      n_failed == 0 ? nil : CLI::UI::Spinner::TASK_FAILED
    end
  end
end

out

when run non-interactively we just print as normal. the status widget doesn't respond well to being written to a file yet

image

This is useful for things like printing out a stream of logs while you
have one or more spinners reporting on the current status. We could also
add Spinner.puts_above, but when you have multiple Spinners, "above" is
kind of ambiguous. We can add it later if the need becomes obvious.
@joshheinrichs-shopify joshheinrichs-shopify merged commit 149fc15 into main Dec 2, 2024
15 checks passed
@joshheinrichs-shopify joshheinrichs-shopify deleted the spinner-puts branch December 2, 2024 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants