Skip to content

API simplifications with regards to the ruby side of libui-ng (LibUI) #114

Description

@rubyFeedback

Hey there kojix2,

LibUI has some code that could possibly be simplified.

For instance, the examples typically have this:

LibUI.main
LibUI.uninit

Or, as another example, to indicate what should happen when the main window
is closed:

LibUI.window_on_closing(main_window) {
  LibUI.quit
  1
}

I assume that this is largely inspired by the C side of libui; probably there
are functions that correspond to:

LibUI.main
LibUI.uninit

From the ruby side, though, this is a bit cumbersome. It is not a big issue at
all, of course, but could the API be simplified a bit, in addition to the current
status quo?

For instance, LibUI.main and LibUI.uninit, could perhaps either be coupled
to just LibUI.uninit (which then also calls LibUI.main), or if you want to keep
it separate then a helper function could be added, such as (just giving some
name examples):

LibUI.loop
LibUI.complete
LibUI.finalize
LibUI.start
LibUI.main
LibUI.muninit # not a great name though, hehe
LibUI.demain
LibUI.unmain
LibUI.main_then_uninit # not good because ideally the method name should be short
LibUI.main_uninit

Anyway just some examples. Perhaps there may be even ways to omit these completely,
such as via:

require 'libui/autoclose' # or some other .rb file that could be used for this

For the other example:

  LibUI.quit
  1

Perhaps LibUI.quit could return 1 by default; or it could be used to quit anyway,
and the return value may not be necessary.

My thinking here is that we could try to simplify some of the libui code in general.
There may be other areas where libui could be simplified perhaps; I am thinking
of the ffi calls, perhaps some could be abstracted into a helper module that is
optional and bundled via the ruby libui bindings, but this issue here is mostly
about just making libui a bit more ruby-like than C-like. See also your own example
at uing with the DSL. :)

(I don't know the C internals, perhaps a wrapper module may be necessary to
separate concerns here; I am mostly just thinking in terms of ruby code that
goes into .rb files. ruby-gtk also used to have, I think, Gtk.init for a long time,
before it was removed; or it was Gtk.main, I forgot. This was I think before kou
maintained it, Masao Mutoh or so was the maintainer before, I don't fully
recall the name correctly perhaps, but I think it was in the time period from
2005 to 2010 or so, give or take.)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions