From f6b8d9903bd4ac889c12d7c5b972fbd2ccde48ee Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sun, 6 Nov 2022 14:47:37 -0500 Subject: [PATCH] Return err from Application.Run --- application.go | 36 ++++++++---------------------------- examples/hello/main.go | 3 ++- 2 files changed, 10 insertions(+), 29 deletions(-) diff --git a/application.go b/application.go index 80c8443..db956eb 100644 --- a/application.go +++ b/application.go @@ -21,7 +21,11 @@ func (application *Application) SetTitle (title string) { application.backend.SetTitle(title) } -func (application *Application) Run (callback func (application *Application)) { +func (application *Application) Run ( + callback func (application *Application), +) ( + err error, +) { // default values for certain parameters width, height := application.Size() if width < 1 { width = 80 } @@ -38,11 +42,11 @@ func (application *Application) Run (callback func (application *Application)) { application.config.padding = 4 - // TODO: instead, return the error - var err error application.backend, err = instantiateBackend(application) - if err != nil { panic(err.Error()) } + if err != nil { return } application.backend.Run(callback) + + return } func (application *Application) Await (timeout time.Duration) (keepRunning bool) { @@ -69,27 +73,3 @@ func (application *Application) Resized () (resized bool) { resized = application.backend.Resized() return } - - -// // updateWindowSize updates the window size according to the buffer size. -// func (application *Application) updateWindowSize () { - // if application.window == nil { return } - // application.window.SetBounds(application.calculateWindowSize()) -// } - -// updateBufferSize updats the buffer size according to the window size. -// func (application *Application) updateBufferSize () { - // if application.window == nil { - // panic("call to application.updateBufferSize before window exists") - // } - // - // windowBounds := application.window.Bounds().Max - // - // if windowBounds != application.previousBounds { - // application.previousBounds = windowBounds - // application.boundsDirty = true - // application.DamageBuffer.SetSize ( - // int(windowBounds.X) / application.metrics.cellWidth, - // int(windowBounds.Y) / application.metrics.cellHeight) - // } -// } diff --git a/examples/hello/main.go b/examples/hello/main.go index da5b229..e48f2dd 100644 --- a/examples/hello/main.go +++ b/examples/hello/main.go @@ -7,7 +7,8 @@ import _ "git.tebibyte.media/sashakoshka/stone/backends/pixel" func main () { application := stone.Application { } - application.Run(run) + err := application.Run(run) + if err != nil { panic(err) } } func run (application *stone.Application) {