github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/internal/hud/components.go (about)

     1  package hud
     2  
     3  import (
     4  	"github.com/tilt-dev/tilt/internal/hud/view"
     5  	"github.com/tilt-dev/tilt/internal/rty"
     6  )
     7  
     8  const resourcesScollerName = "resources"
     9  const alertScrollerName = "alert"
    10  
    11  func (h *Hud) activeScroller() scroller {
    12  	am := h.activeModal()
    13  	if am != nil {
    14  		return am
    15  	} else {
    16  		return h.r.rty.ElementScroller(resourcesScollerName)
    17  	}
    18  }
    19  
    20  func (h *Hud) activeModal() modal {
    21  	if h.currentViewState.AlertMessage != "" {
    22  		return makeAlertModal(h.r.rty)
    23  	} else {
    24  		return nil
    25  	}
    26  }
    27  
    28  type scroller interface {
    29  	Up()
    30  	Down()
    31  	Top()
    32  	Bottom()
    33  }
    34  
    35  type modal interface {
    36  	Up()
    37  	Down()
    38  	Top()
    39  	Bottom()
    40  	Close(vs *view.ViewState)
    41  }
    42  
    43  type alertModal struct {
    44  	rty.TextScroller
    45  }
    46  
    47  var _ modal = alertModal{}
    48  
    49  func makeAlertModal(r rty.RTY) modal {
    50  	return alertModal{r.TextScroller(alertScrollerName)}
    51  }
    52  
    53  func (am alertModal) Close(vs *view.ViewState) {
    54  	vs.AlertMessage = ""
    55  }