prime8dev

prime8dev
git clone https://git.prime8.dev/prime8dev.git
Log | Files | Refs | README | LICENSE

types.go (3305B)


      1 package tui
      2 
      3 import (
      4 	"math/rand"
      5 	"time"
      6 
      7 	appconfig "git.prime8.dev/moncheeta/prime8dev/internal/config"
      8 	appcontent "git.prime8.dev/moncheeta/prime8dev/internal/content"
      9 	"git.prime8.dev/moncheeta/prime8dev/internal/external"
     10 	"github.com/charmbracelet/bubbles/help"
     11 	"github.com/charmbracelet/bubbles/viewport"
     12 	"github.com/patrickmn/go-cache"
     13 )
     14 
     15 const (
     16 	tabAbout = iota
     17 	tabExperience
     18 	tabProjects
     19 
     20 	minWindowWidth  = 80
     21 	minWindowHeight = 24
     22 )
     23 
     24 var tabLabels = []string{"about", "experience", "projects"}
     25 
     26 type tickMsg time.Time
     27 
     28 type portfolioModel struct {
     29 	user            string
     30 	about           appconfig.About
     31 	currentJob      *appconfig.Experience
     32 	aboutASCIICache map[int]string
     33 	aboutASCIILoads map[int]bool
     34 	// rows of the portrait drawn so far; the reveal prints it a row at a time
     35 	aboutLogoRows int
     36 	aboutLogoGen  int
     37 
     38 	projects   []appconfig.Project
     39 	experience []appconfig.Experience
     40 
     41 	activeTab           int
     42 	windowTitleSet      string
     43 	projectIndex        int
     44 	projectReadmeScroll bool
     45 	experienceIndex     int
     46 
     47 	shell shellState
     48 
     49 	// detailLineWidths holds the visible width of each viewport line, for
     50 	// horizontal scrolling and the cut-off markers.
     51 	detailLineWidths []int
     52 	detailXOffset    int
     53 	detailView       detailViewKey
     54 	detailViewSet    bool
     55 
     56 	width  int
     57 	height int
     58 	now    time.Time
     59 
     60 	bootTitle         string
     61 	bootSubtitle      string
     62 	bootTitleFrame    string
     63 	bootSubtitleFrame string
     64 	bootStartedAt     time.Time
     65 	bootFadeProgress  float64
     66 	bootActive        bool
     67 	bootRand          *rand.Rand
     68 
     69 	keys       keyMap
     70 	help       help.Model
     71 	viewport   viewport.Model
     72 	gitService *external.Git
     73 
     74 	projectReadmes      map[string]string
     75 	projectReadmeErrors map[string]string
     76 	projectReadmeLoads  map[string]bool
     77 	projectReadmeRender map[string]map[int]string
     78 	projectPrefetchDone bool
     79 
     80 	wakaHours   string
     81 	wakaLoaded  bool
     82 	wakaLoading bool
     83 	wakaTime    *external.WakaTime
     84 }
     85 
     86 func newPortfolioModel(user string) portfolioModel {
     87 	gitService := external.NewGit()
     88 
     89 	about := appconfig.GetAbout()
     90 	exp := appconfig.GetExperience()
     91 	projects, _ := appcontent.LoadProjects(gitService)
     92 	bootTitle := about.Name
     93 	if bootTitle == "" {
     94 		bootTitle = "prime8.dev"
     95 	}
     96 	vp := viewport.New(1, 1)
     97 	vp.SetContent("loading...")
     98 
     99 	h := help.New()
    100 	h.ShowAll = false
    101 
    102 	m := portfolioModel{
    103 		gitService:      gitService,
    104 		user:            user,
    105 		about:           about,
    106 		currentJob:      appconfig.CurrentJob(exp),
    107 		aboutASCIICache: make(map[int]string),
    108 		aboutASCIILoads: make(map[int]bool),
    109 		projects:        projects,
    110 		experience:      exp,
    111 		now:             time.Now(),
    112 		width:           80,
    113 		height:          24,
    114 		bootTitle:       bootTitle,
    115 		bootSubtitle:    "www.prime8.dev",
    116 		bootStartedAt:   time.Now(),
    117 		bootActive:      true,
    118 		bootRand:        rand.New(rand.NewSource(time.Now().UnixNano())),
    119 		keys:            defaultKeyMap(),
    120 		help:            h,
    121 		viewport:        vp,
    122 		shell:           newShellState(user),
    123 
    124 		projectReadmes:      make(map[string]string),
    125 		projectReadmeErrors: make(map[string]string),
    126 		projectReadmeLoads:  make(map[string]bool),
    127 		projectReadmeRender: make(map[string]map[int]string),
    128 
    129 		wakaTime: external.NewWakaTime(cache.New(5*time.Minute, 10*time.Minute)),
    130 	}
    131 	m.syncBootFrame(m.bootStartedAt)
    132 	m.syncViewport()
    133 
    134 	return m
    135 }