func NewModel()

in internal/ui/importlist/importlist.go [34:106]


func NewModel(ctx context.Context, c meta.Meta, l meta.ImportList, idx int) Model {
	// Build candidate words for the textinput
	var resourceSchemas map[string]*schema.Schema
	switch c.ProviderName() {
	case "azapi":
		resourceSchemas = azapi.ProviderSchemaInfo.ResourceSchemas
	case "azurerm":
		resourceSchemas = azurerm.ProviderSchemaInfo.ResourceSchemas
	}
	candidates := make([]string, 0, len(resourceSchemas))
	for rt := range resourceSchemas {
		candidates = append(candidates, rt)
	}
	sort.Strings(candidates)

	// Build list items
	var items []list.Item
	for idx, item := range l {
		ti := textinput.NewModel()
		ti.SetCursorMode(textinput.CursorStatic)
		if !item.Skip() {
			ti.SetValue(item.TFAddr.String())
		}
		ti.CandidateWords = candidates
		items = append(items, Item{
			idx:       idx,
			v:         item,
			textinput: ti,
		})
	}

	lst := list.NewModel(items, NewImportItemDelegate(c.ProviderName()), 0, 0)
	lst.Title = " " + c.ScopeName() + " "
	lst.Styles.Title = common.SubtitleStyle
	lst.StatusMessageLifetime = 3 * time.Second
	lst.Select(idx)
	lst.Filter = func(term string, targets []string) []list.Rank {
		p, err := regexp.Compile(term)
		if err != nil {
			return nil
		}
		result := []list.Rank{}
		for idx, tgt := range targets {
			m := p.FindStringIndex(tgt)
			if m == nil {
				continue
			}
			rnk := list.Rank{
				Index: idx,
			}
			for i := m[0]; i < m[1]; i++ {
				rnk.MatchedIndexes = append(rnk.MatchedIndexes, i)
			}
			result = append(result, rnk)
		}
		return result
	}

	bindKeyHelps(&lst, newListKeyMap().ToBindings())

	// Reset the quit to deallocate the "ESC" as a quit key.
	lst.KeyMap.Quit = key.NewBinding(
		key.WithKeys("q"),
		key.WithHelp("q", "quit"),
	)

	return Model{
		ctx:      ctx,
		c:        c,
		listkeys: newListKeyMap(),
		list:     lst,
	}
}