mirror of
				https://github.com/taigrr/wtf
				synced 2025-01-18 04:03:14 -08:00 
			
		
		
		
	Make all exported fields unexported in WtfApp
This commit is contained in:
		
							parent
							
								
									4c0f7650dd
								
							
						
					
					
						commit
						8436b74ac1
					
				| @ -17,41 +17,46 @@ import ( | |||||||
| // WtfApp is the container for a collection of widgets that are all constructed from a single | // WtfApp is the container for a collection of widgets that are all constructed from a single | ||||||
| // configuration file and displayed together | // configuration file and displayed together | ||||||
| type WtfApp struct { | type WtfApp struct { | ||||||
| 	App            *tview.Application | 	app            *tview.Application | ||||||
| 	Config         *config.Config | 	config         *config.Config | ||||||
| 	ConfigFilePath string | 	configFilePath string | ||||||
| 	Display        *Display | 	display        *Display | ||||||
| 	FocusTracker   wtf.FocusTracker | 	focusTracker   wtf.FocusTracker | ||||||
| 	IsCustomConfig bool | 	isCustomConfig bool | ||||||
| 	Pages          *tview.Pages | 	pages          *tview.Pages | ||||||
| 	Widgets        []wtf.Wtfable | 	widgets        []wtf.Wtfable | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // NewWtfApp creates and returns an instance of WtfApp | // NewWtfApp creates and returns an instance of WtfApp | ||||||
| func NewWtfApp(app *tview.Application, config *config.Config, configFilePath string, isCustom bool) *WtfApp { | func NewWtfApp(app *tview.Application, config *config.Config, configFilePath string, isCustom bool) *WtfApp { | ||||||
| 	wtfApp := WtfApp{ | 	wtfApp := WtfApp{ | ||||||
| 		App:            app, | 		app:            app, | ||||||
| 		Config:         config, | 		config:         config, | ||||||
| 		ConfigFilePath: configFilePath, | 		configFilePath: configFilePath, | ||||||
| 		IsCustomConfig: isCustom, | 		isCustomConfig: isCustom, | ||||||
| 		Pages:          tview.NewPages(), | 		pages:          tview.NewPages(), | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	wtfApp.Widgets = maker.MakeWidgets(wtfApp.App, wtfApp.Pages, wtfApp.Config) | 	wtfApp.widgets = maker.MakeWidgets(wtfApp.app, wtfApp.pages, wtfApp.config) | ||||||
| 	wtfApp.Display = NewDisplay(wtfApp.Widgets, wtfApp.Config) | 	wtfApp.display = NewDisplay(wtfApp.widgets, wtfApp.config) | ||||||
| 	wtfApp.FocusTracker = wtf.NewFocusTracker(wtfApp.App, wtfApp.Widgets, wtfApp.Config) | 	wtfApp.focusTracker = wtf.NewFocusTracker(wtfApp.app, wtfApp.widgets, wtfApp.config) | ||||||
| 
 | 
 | ||||||
| 	wtfApp.App.SetInputCapture(wtfApp.keyboardIntercept) | 	wtfApp.pages.AddPage("grid", wtfApp.display.Grid, true, true) | ||||||
| 	wtfApp.Pages.AddPage("grid", wtfApp.Display.Grid, true, true) | 	wtfApp.app.SetRoot(wtfApp.pages, true) | ||||||
| 	wtfApp.App.SetRoot(wtfApp.Pages, true) | 	wtfApp.app.SetInputCapture(wtfApp.keyboardIntercept) | ||||||
| 
 | 
 | ||||||
| 	wtf.ValidateWidgets(wtfApp.Widgets) | 	wtf.ValidateWidgets(wtfApp.widgets) | ||||||
| 
 | 
 | ||||||
| 	return &wtfApp | 	return &wtfApp | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /* -------------------- Exported Functions -------------------- */ | /* -------------------- Exported Functions -------------------- */ | ||||||
| 
 | 
 | ||||||
|  | // App returns the *tview.Application instance | ||||||
|  | func (wtfApp *WtfApp) App() *tview.Application { | ||||||
|  | 	return wtfApp.app | ||||||
|  | } | ||||||
|  | 
 | ||||||
| // Start initializes the app | // Start initializes the app | ||||||
| func (wtfApp *WtfApp) Start() { | func (wtfApp *WtfApp) Start() { | ||||||
| 	wtfApp.scheduleWidgets() | 	wtfApp.scheduleWidgets() | ||||||
| @ -66,7 +71,7 @@ func (wtfApp *WtfApp) Stop() { | |||||||
| /* -------------------- Unexported Functions -------------------- */ | /* -------------------- Unexported Functions -------------------- */ | ||||||
| 
 | 
 | ||||||
| func (wtfApp *WtfApp) stopAllWidgets() { | func (wtfApp *WtfApp) stopAllWidgets() { | ||||||
| 	for _, widget := range wtfApp.Widgets { | 	for _, widget := range wtfApp.widgets { | ||||||
| 		widget.Stop() | 		widget.Stop() | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| @ -78,23 +83,23 @@ func (wtfApp *WtfApp) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey { | |||||||
| 		wtfApp.refreshAllWidgets() | 		wtfApp.refreshAllWidgets() | ||||||
| 		return nil | 		return nil | ||||||
| 	case tcell.KeyTab: | 	case tcell.KeyTab: | ||||||
| 		wtfApp.FocusTracker.Next() | 		wtfApp.focusTracker.Next() | ||||||
| 		return nil | 		return nil | ||||||
| 	case tcell.KeyBacktab: | 	case tcell.KeyBacktab: | ||||||
| 		wtfApp.FocusTracker.Prev() | 		wtfApp.focusTracker.Prev() | ||||||
| 		return nil | 		return nil | ||||||
| 	case tcell.KeyEsc: | 	case tcell.KeyEsc: | ||||||
| 		wtfApp.FocusTracker.None() | 		wtfApp.focusTracker.None() | ||||||
| 		return nil | 		return nil | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// Checks to see if any widget has been assigned the pressed key as its focus key | 	// Checks to see if any widget has been assigned the pressed key as its focus key | ||||||
| 	if wtfApp.FocusTracker.FocusOn(string(event.Rune())) { | 	if wtfApp.focusTracker.FocusOn(string(event.Rune())) { | ||||||
| 		return nil | 		return nil | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// If no specific widget has focus, then allow the key presses to fall through to the app | 	// If no specific widget has focus, then allow the key presses to fall through to the app | ||||||
| 	if !wtfApp.FocusTracker.IsFocused { | 	if !wtfApp.focusTracker.IsFocused { | ||||||
| 		switch string(event.Rune()) { | 		switch string(event.Rune()) { | ||||||
| 		case "/": | 		case "/": | ||||||
| 			return nil | 			return nil | ||||||
| @ -105,13 +110,13 @@ func (wtfApp *WtfApp) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (wtfApp *WtfApp) refreshAllWidgets() { | func (wtfApp *WtfApp) refreshAllWidgets() { | ||||||
| 	for _, widget := range wtfApp.Widgets { | 	for _, widget := range wtfApp.widgets { | ||||||
| 		go widget.Refresh() | 		go widget.Refresh() | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (wtfApp *WtfApp) scheduleWidgets() { | func (wtfApp *WtfApp) scheduleWidgets() { | ||||||
| 	for _, widget := range wtfApp.Widgets { | 	for _, widget := range wtfApp.widgets { | ||||||
| 		go Schedule(widget) | 		go Schedule(widget) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| @ -128,9 +133,9 @@ func (wtfApp *WtfApp) watchForConfigChanges() { | |||||||
| 			case <-watch.Event: | 			case <-watch.Event: | ||||||
| 				wtfApp.Stop() | 				wtfApp.Stop() | ||||||
| 
 | 
 | ||||||
| 				config := cfg.LoadWtfConfigFile(wtfApp.ConfigFilePath, wtfApp.IsCustomConfig) | 				config := cfg.LoadWtfConfigFile(wtfApp.configFilePath, wtfApp.isCustomConfig) | ||||||
| 
 | 
 | ||||||
| 				newApp := NewWtfApp(wtfApp.App, config, wtfApp.ConfigFilePath, wtfApp.IsCustomConfig) | 				newApp := NewWtfApp(wtfApp.app, config, wtfApp.configFilePath, wtfApp.isCustomConfig) | ||||||
| 				newApp.Start() | 				newApp.Start() | ||||||
| 			case err := <-watch.Error: | 			case err := <-watch.Error: | ||||||
| 				log.Fatalln(err) | 				log.Fatalln(err) | ||||||
| @ -141,7 +146,7 @@ func (wtfApp *WtfApp) watchForConfigChanges() { | |||||||
| 	}() | 	}() | ||||||
| 
 | 
 | ||||||
| 	// Watch config file for changes. | 	// Watch config file for changes. | ||||||
| 	absPath, _ := utils.ExpandHomeDir(wtfApp.ConfigFilePath) | 	absPath, _ := utils.ExpandHomeDir(wtfApp.configFilePath) | ||||||
| 	if err := watch.Add(absPath); err != nil { | 	if err := watch.Add(absPath); err != nil { | ||||||
| 		log.Fatalln(err) | 		log.Fatalln(err) | ||||||
| 	} | 	} | ||||||
|  | |||||||
							
								
								
									
										2
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								main.go
									
									
									
									
									
								
							| @ -69,7 +69,7 @@ func main() { | |||||||
| 	wtfApp := app.NewWtfApp(tviewApp, config, flags.Config, flags.HasCustomConfig()) | 	wtfApp := app.NewWtfApp(tviewApp, config, flags.Config, flags.HasCustomConfig()) | ||||||
| 	wtfApp.Start() | 	wtfApp.Start() | ||||||
| 
 | 
 | ||||||
| 	if err := wtfApp.App.Run(); err != nil { | 	if err := wtfApp.App().Run(); err != nil { | ||||||
| 		fmt.Printf("\n%s %v\n", aurora.Red("ERROR"), err) | 		fmt.Printf("\n%s %v\n", aurora.Red("ERROR"), err) | ||||||
| 		os.Exit(1) | 		os.Exit(1) | ||||||
| 	} | 	} | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user