@@ -12,8 +12,6 @@ import (
1212
1313 "github.com/gdamore/tcell/v2"
1414 "github.com/rivo/tview"
15- "golang.org/x/text/language"
16- "golang.org/x/text/message"
1715)
1816
1917var (
@@ -46,6 +44,7 @@ type AppService struct {
4644func NewAppService () AppServiceInterface {
4745 app := tview .NewApplication ()
4846 themeService := theme .NewTheme ()
47+ brewService := NewBrewService ()
4948
5049 appService := & AppService {
5150 app : app ,
@@ -58,7 +57,7 @@ func NewAppService() AppServiceInterface {
5857 showOnlyOutdated : false ,
5958 brewVersion : "-" ,
6059
61- BrewService : NewBrewService () ,
60+ BrewService : brewService ,
6261 CommandService : NewCommandService (),
6362 SelfUpdateService : NewSelfUpdateService (),
6463 }
@@ -156,137 +155,11 @@ func (s *AppService) search(searchText string, scrollToTop bool) {
156155
157156func (s * AppService ) setDetails (info * models.Formula ) {
158157 if info == nil {
159- s .layout .GetDetails ().SetContent ("" )
158+ s .layout .GetDetails ().SetContent (nil )
160159 return
161160 }
162161
163- // Installation status with colors
164- installedStatus := "[red]Not installed[-]"
165- installedIcon := "✗"
166- if len (info .Installed ) > 0 {
167- installedStatus = "[green]Installed[-]"
168- installedIcon = "✓"
169-
170- if info .Outdated {
171- installedStatus = "[orange]Update available[-]"
172- installedIcon = "⟳"
173- }
174- }
175-
176- // Basic information with icons
177- basicInfo := fmt .Sprintf (
178- "[yellow::b]%s %s[-]\n \n " +
179- "[blue]• Name:[-] %s\n " +
180- "[blue]• Version:[-] %s\n " +
181- "[blue]• Status:[-] %s %s\n " +
182- "[blue]• Tap:[-] %s\n " +
183- "[blue]• License:[-] %s\n \n " +
184- "[yellow::b]Description[-]\n %s\n \n " +
185- "[blue]• Homepage:[-] %s" ,
186- info .Name , installedIcon ,
187- info .FullName ,
188- info .Versions .Stable ,
189- installedStatus , s .getPackageVersionInfo (info ),
190- info .Tap ,
191- info .License ,
192- info .Description ,
193- info .Homepage ,
194- )
195-
196- // Installation details
197- installDetails := s .getPackageInstallationDetails (info )
198-
199- // Dependencies with improved formatting
200- dependenciesInfo := s .getDependenciesInfo (info )
201-
202- analyticsInfo := s .getAnalyticsInfo (info )
203-
204- s .layout .GetDetails ().SetContent (strings .Join ([]string {basicInfo , installDetails , dependenciesInfo , analyticsInfo }, "\n \n " ))
205- }
206-
207- func (s * AppService ) getPackageVersionInfo (info * models.Formula ) string {
208- if len (info .Installed ) == 0 {
209- return ""
210- }
211-
212- installedVersion := info .Installed [0 ].Version
213- stableVersion := info .Versions .Stable
214-
215- // Revision version
216- if strings .HasPrefix (installedVersion , stableVersion + "_" ) {
217- return fmt .Sprintf ("([green]%s[-])" , installedVersion )
218- } else if installedVersion == stableVersion {
219- return fmt .Sprintf ("([green]%s[-])" , installedVersion )
220- } else if installedVersion < stableVersion || info .Outdated {
221- return fmt .Sprintf ("([orange]%s[-] → [green]%s[-])" ,
222- installedVersion , stableVersion )
223- }
224-
225- // Other cases
226- return fmt .Sprintf ("([green]%s[-])" , installedVersion )
227- }
228-
229- func (s * AppService ) getPackageInstallationDetails (info * models.Formula ) string {
230- if len (info .Installed ) == 0 {
231- return "[yellow::b]Installation[-]\n Not installed"
232- }
233-
234- packagePrefix := s .BrewService .GetPrefixPath () + "/" + info .Name
235- installedOnRequest := "No"
236- if info .Installed [0 ].InstalledOnRequest {
237- installedOnRequest = "Yes"
238- }
239-
240- installedAsDependency := "No"
241- if info .Installed [0 ].InstalledAsDependency {
242- installedAsDependency = "Yes"
243- }
244-
245- return fmt .Sprintf (
246- "[yellow::b]Installation Details[-]\n " +
247- "[blue]• Path:[-] %s\n " +
248- "[blue]• Installed on request:[-] %s\n " +
249- "[blue]• Installed as dependency:[-] %s\n " +
250- "[blue]• Installed version:[-] %s" ,
251- packagePrefix ,
252- installedOnRequest ,
253- installedAsDependency ,
254- info .Installed [0 ].Version ,
255- )
256- }
257-
258- func (s * AppService ) getDependenciesInfo (info * models.Formula ) string {
259- title := "[yellow::b]Dependencies[-]\n "
260-
261- if len (info .Dependencies ) == 0 {
262- return title + "No dependencies"
263- }
264-
265- // Format dependencies in multiple columns or with separators
266- deps := ""
267- for i , dep := range info .Dependencies {
268- deps += dep
269- if i < len (info .Dependencies )- 1 {
270- if (i + 1 )% 3 == 0 {
271- deps += "\n "
272- } else {
273- deps += ", "
274- }
275- }
276- }
277-
278- return title + deps
279- }
280-
281- func (s * AppService ) getAnalyticsInfo (info * models.Formula ) string {
282- title := "[yellow::b]Analytics[-]\n "
283-
284- p := message .NewPrinter (language .English )
285-
286- title += fmt .Sprintf ("[blue]• 90d Global Rank:[-] %s\n " , p .Sprintf ("%d" , info .Analytics90dRank ))
287- title += fmt .Sprintf ("[blue]• 90d Downloads:[-] %s\n " , p .Sprintf ("%d" , info .Analytics90dDownloads ))
288-
289- return title
162+ s .layout .GetDetails ().SetContent (info )
290163}
291164
292165func (s * AppService ) forceRefreshResults () {
@@ -324,8 +197,7 @@ func (s *AppService) setResults(data *[]models.Formula, scrollToTop bool) {
324197 versionCell .SetTextColor (tcell .ColorOrange )
325198 }
326199
327- downloads := message .NewPrinter (language .English ).Sprintf ("%d" , info .Analytics90dDownloads )
328- downloadsCell := tview .NewTableCell (downloads ).SetSelectable (true ).SetAlign (tview .AlignRight )
200+ downloadsCell := tview .NewTableCell (fmt .Sprintf ("%d" , info .Analytics90dDownloads )).SetSelectable (true ).SetAlign (tview .AlignRight )
329201
330202 s .layout .GetTable ().View ().SetCell (i + 1 , 0 , nameCell .SetExpansion (0 ))
331203 s .layout .GetTable ().View ().SetCell (i + 1 , 1 , versionCell .SetExpansion (0 ))
0 commit comments