starship / starship

β˜„πŸŒŒοΈ The minimal, blazing-fast, and infinitely customizable prompt for any shell!
https://starship.rs
ISC License
42.77k stars 1.84k forks source link

Periodic prompt refresh #1281

Open catleeball opened 4 years ago

catleeball commented 4 years ago

Feature Request

It would be very nice if Starship could refresh the current prompt on a timer. This would allow interesting additional features for modules, and provide avenues for new modules that would be infeasible without a periodic updating prompt.

See alternative 1 below regarding a live prompt using event-driven prompt updates.

This would enable things like:

Describe the solution you'd like

Modules that use this feature could expose an update-interval = int seconds flag in the config, where users can specify how fast the prompt will update. Possibly, also a flag to disable updates, like periodic-update = bool

[time]
disabled = false
periodic-update = true
update-interval = 10  # sufficient for minute-granularity time
time-format = "[%R]"

For performance and low spec machines, it might be best to recommend developers default modules to having periodic updates toggled off, where applicable. Some use cases where this wouldn't be applicable are some possible fun1 new modules:

[animation]
disabled = false
frames = ["πŸŽΆπŸŽ·πŸ›", "πŸŽ΅πŸŽ·πŸ›"]
interval = 1
[inline-marquee]
disabled = false
# Prefix and Suffix are not animated to be marquee borders
prefix = "["
suffix = "]"
marquee-text = "this feature is deprecated"
# Rate to refresh prompt also impacts marquee speed
interval = 1 
[preprompt-marquee]
# Requires [line-break] = true
# Pre-prompt line will be marquee-ified
disabled = true
interval = 1

Describe alternatives you've considered

  1. Instead, this could be a callback hook instead of a refresh interval, where an event triggers Starship to update the prompt. This might be more flexible and efficient; modules do not need to wait for the next update interval to update, and only update when needed. Cons include complexity; this feature would likely need a considerable amount of work to implement, and developers who use it need to understand event-driven programming to use this feature. Further, effort would be needed to abstract this complexity away from users who want a simple config flag to do what they want.
  2. This could be user-implemented, where the shell itself is configured to re-evaluate starship on an interval. Pros include no work needed for Starship. Cons are that it would be less accessible to users (they need to figure out how to do this with their shell), and likely a lot slower (re-running starship init every N seconds likely incurs a lot of operations we don't actually need to re-run when we just want to refresh the display and update relevant modules)

1: Fun is subjective. Your milage may vary.

catleeball commented 4 years ago

I might break out the event-based update bug, and the example implementations into bugs, noting the caveat that this would need to first be implemented.

EDIT: I'll wait to figure out if this is a feasible feature before spamming more FRs with the above examples.

andytom commented 4 years ago

I think this could be a really interesting feature to add however this is definitely not possible at the moment and I don't think it is going to be simple to implement. The main difficulties are going to be around getting this to work across the different shells that starship supports. Related issue https://github.com/starship/starship/issues/1124#issuecomment-616682179 might also be a good place to start discussing this.

catleeball commented 4 years ago

@andytom : Understood, thanks for the info! Reading the comment you link does make it sound like a major overhaul to get support everywhere.