Coder Social home page Coder Social logo

ex_termbox's People

Contributors

fhunleth avatar fireproofsocks avatar ndreynolds avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ex_termbox's Issues

Rewrite bindings in Rust with Rustler

This should be possible and ought to make the bindings safer. Thread-based concurrency with shared memory is hard to get right, and Rust would help ensure the memory access is correct.

termbox2 and the future of ex_termbox

Hi all! @mhanberg and I had a brief conversation about porting this library to use termbox2 and we wanted to solicit input.

In addition to some useful enhancements over termbox, the primary motivation of moving to termbox2 is that it is actively maintained. (Indeed, the termbox readme currently points to termbox2 as a preferred choice for new projects.)

There are a few of options for how to proceed:

  • If @ndreynolds has interest, I believe it would be possible to update this project to use termbox2 without breaking backwards compatibility.
  • This project could be forked as ex_termbox2 and maintained independently. If this occurred, a separate discussion could be had about maintaining API compatibility, which might allow Ratatouille to easily switch to it if desired at any point.

I'm eager to hear any thoughts, suggestions, or alternatives from anyone interested!

Build fails [Windows 10]

Specs:

  • Erlang/OTP 24 [erts-12.0] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit]
  • Elixir 1.12.3 (compiled with Erlang/OTP 22)

Reproduction Steps:

  • Create a new empty project. mix new whatever_you_like.
  • Add {:ex_termbox, "~> 1.0"} to your dependencies (mix.exs)
  • Run mix deps.get
  • Run mix

Expected output:
Success

Actual output:

==> ex_termbox

Microsoft (R) Program Maintenance Utility Version 14.00.24245.0
Copyright (C) Microsoft Corporation.  All rights reserved.

NMAKE : fatal error U1052: file 'Makefile.win' not found
Stop.
could not compile dependency :ex_termbox, "mix compile" failed. You can recompile this dependency with "mix deps.compile ex_termbox", update it with "mix deps.update ex_termbox" or clean it with "mix deps.clean ex_termbox"
==> terminal_game
** (Mix) Could not compile with "nmake" (exit status: 2).
One option is to install a recent version of
[Visual C++ Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/)
either manually or using [Chocolatey](https://chocolatey.org/) -
`choco install VisualCppBuildTools`.

After installing Visual C++ Build Tools, look in the "Program Files (x86)"
directory and search for "Microsoft Visual Studio". Note down the full path
of the folder with the highest version number. Open the "run" command and
type in the following command (make sure that the path and version number
are correct):

    cmd /K "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64

This should open up a command prompt with the necessary environment variables
set, and from which you will be able to run the "mix compile", "mix deps.compile",
and "mix test" commands.

Using a different python executable

Not sure if I'm even going in the right direction here. Mac recently stopped coming packaged with python 2.7 with the python executable, so now only python3 is available. Is there some way I can configure this to be used instead? I could probably make a copy of the executable I currently have, but that feels like a solution that will come with its own issues/break at some point.

Failing to run release with reason: {on_load_function_failed,'Elixir.ExTermbox.Bindings'}

I'm using Ratatouille to build a CLI app and everything works perfectly in IEX .

But building a release with either Mix releases or Distillery causes the same error to occur:


=SUPERVISOR REPORT==== 26-Jun-2022::21:43:49.365723 ===
    supervisor: {local,kernel_sup}
    errorContext: start_error
    reason: {on_load_function_failed,'Elixir.ExTermbox.Bindings'}
    offender: [{pid,undefined},
               {id,kernel_safe_sup},
               {mfargs,{supervisor,start_link,
                                   [{local,kernel_safe_sup},kernel,safe]}},
               {restart_type,permanent},
               {significant,false},
               {shutdown,infinity},
               {child_type,supervisor}]

=CRASH REPORT==== 26-Jun-2022::21:43:49.365813 ===
  crasher:
    initial call: supervisor:kernel/1
    pid: <0.932.0>
    registered_name: []
    exception exit: {on_load_function_failed,'Elixir.ExTermbox.Bindings'}
      in function  init:run_on_load_handlers/0
      in call from kernel:init/1 (kernel.erl, line 189)
      in call from supervisor:init/1 (supervisor.erl, line 330)
      in call from gen_server:init_it/2 (gen_server.erl, line 423)
      in call from gen_server:init_it/6 (gen_server.erl, line 390)
    ancestors: [kernel_sup,<0.906.0>]
    message_queue_len: 0
    messages: []
    links: [<0.908.0>]
    dictionary: []
    trap_exit: true
    status: running
    heap_size: 376
    stack_size: 29
    reductions: 226
  neighbours:

=CRASH REPORT==== 26-Jun-2022::21:43:50.369580 ===
  crasher:
    initial call: application_master:init/4
    pid: <0.905.0>
    registered_name: []
    exception exit: {{shutdown,
                         {failed_to_start_child,kernel_safe_sup,
                             {on_load_function_failed,
                                 'Elixir.ExTermbox.Bindings'}}},
                     {kernel,start,[normal,[]]}}
      in function  application_master:init/4 (application_master.erl, line 142)
    ancestors: [<0.904.0>]
    message_queue_len: 1
    messages: [{'EXIT',<0.906.0>,normal}]
    links: [<0.904.0>,<0.903.0>]
    dictionary: []
    trap_exit: true
    status: running
    heap_size: 376
    stack_size: 29
    reductions: 165
  neighbours:

=INFO REPORT==== 26-Jun-2022::21:43:50.370283 ===
    application: kernel
    exited: {{shutdown,
                 {failed_to_start_child,kernel_safe_sup,
                     {on_load_function_failed,'Elixir.ExTermbox.Bindings'}}},
             {kernel,start,[normal,[]]}}
    type: permanent

{"Kernel pid terminated",application_controller,"{application_start_failure,kernel,{{shutdown,{failed_to_start_child,kernel_safe_sup,{on_load_function_failed,'Elixir.ExTermbox.Bindings'}}},{kernel,start,[normal,[]]}}}"}
Kernel pid terminated (application_controller) ({application_start_failure,kernel,{{shutdown,{failed_to_start_child,kernel_safe_sup,{on_load_function_failed,'Elixir.ExTermbox.Bindings'}}},{kernel,start,[normal,[]]}}})

Any idea why this works fine in dev but fails on a release?

Hello world example fails

Hello,

first of all, thanks for your effort with this library. Really appreciate it.

Now onto the issue: running either the basic hello world example or event viewer example fails for me with the following message:

** (exit) exited in: GenServer.call(ExTermbox.EventManager, {:subscribe, #PID<0.74.0>}, 5000)
** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started
(elixir) lib/gen_server.ex:914: GenServer.call/3
examples/event_viewer.exs:14: EventViewer.run/0
(elixir) lib/code.ex:767: Code.require_file/2
(mix) lib/mix/tasks/run.ex:146: Mix.Tasks.Run.run/5

I've traced the issue to these two lines:

{:ok, _pid} = EventManager.start_link()
:ok = EventManager.subscribe(self())

Since EventManager.subscribe/2 accepts two arguments, the first one being PID of the EventManager, and we're passing it PID of the current process (which is iex shell in our case), I've modified these two lines just a little bit to get them working:

{:ok, em_pid} = EventManager.start_link()
:ok = EventManager.subscribe(em_pid, self())

I see the EventManager.subscribe/2 source has been modified within the last month, most importantly, the first argument was repurposed to be EventManager PID and has a default value of __MODULE__. IMO that argument should be put second, since its breaking backwards compatibility (and examples).

Some wide characters are not correctly displayed

It seems that some of the Chinese characters are not displayed.

Let's take the hello world for example. Here's a script:
https://gist.github.com/qhwa/7ef65acb13ec656cc13d7418d066cfcc

when mix run it, the expected output will be:

Hello, World! 你好世界!

Whilst the current output is

Hello, World! 你世!

Looks like characters at even positions are missing.

Do you happen to have any idea how I can fix it?

FYI. I tried termbox the C program and confirms it works with Chinese characters.

UPDATE:
After some digging, I realize it is an issue with ratatouille on calculating positions. It is an issue about wide characters including CJK, full-width Unicode characters and some emojis. It can be fixed with a small patch calculating character width. On my local machine, I have got it working properly at least for some Chinese characters. I can make a pull request on it if it makes sense to you. :)

Example fails to compile with Error 127

I thought I would give the examples a try, but there seems to be a hitch:

❯ mix run examples/hello_world.exs
cd c_src/termbox && CFLAGS=-fPIC ./waf configure --prefix=. && ./waf
/bin/sh: ./waf: No such file or directory
make: *** [c_src/termbox/build/src/libtermbox.a] Error 127
** (Mix) Could not compile with "make" (exit status: 2).
You need to have gcc and make installed. Try running the
commands "gcc --version" and / or "make --version". If these programs
are not installed, you will be prompted to install them.

I do have gcc and make installed:

❯ gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.5 (clang-1205.0.22.9)
Target: x86_64-apple-darwin20.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
❯ make --version
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for i386-apple-darwin11.3.0

In case it matters, here's my elixir version:

❯ elixir --version
Erlang/OTP 23 [erts-11.1.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe]

Elixir 1.11.2 (compiled with Erlang/OTP 23)

I'm on Mac OS 11.6

It seems that the git clone command did not pull down any files from c_src/termbox/ -- I'm not sure what I'm looking at there (a submodule?) but in the Github UI it resolves to https://github.com/nsf/termbox/tree/0178b0123e176b9c4656177c07af832bc141b03f

Resize events not working anymore after key/mouse events

Replicable into the included example (and also in a ratatouille simple app or toby), examples/event_viewer.exs.

  1. mix run examples/event_viewer.exs
  2. resize the terminal (kde konsole here) -> the app receives the resize events
  3. trigger several key/mouse events -> the app receives the events
  4. resize again the terminal -> the app doesn't receive the resize events anymore, but the key/mouse events still work

ExTermbox in escript

Hi, I'm trying to make a command-line app with Ratatouille and ExTermbox and having a lot of fun of it.

So far everything works fine in iex, and mix run, but in an escript.

When running the escript binary, I got error messages like this:

13:58:42.454 [warn]  The on_load function for module Elixir.ExTermbox.Bindings returned:
{:error, :bad_name}

** (EXIT from #PID<0.98.0>) shutdown: failed to start child: Ratatouille.Window
    ** (EXIT) an exception was raised:
        ** (UndefinedFunctionError) function ExTermbox.Bindings.init/0 is undefined (module ExTermbox.Bindings is not available)
            (ex_termbox 1.0.2) ExTermbox.Bindings.init()
            (ratatouille 0.5.1) lib/ratatouille/window.ex:104: Ratatouille.Window.init/1
            (stdlib 3.11) gen_server.erl:405: :gen_server.init_it/2
            (stdlib 3.11) gen_server.erl:373: :gen_server.init_it/6
            (stdlib 3.11) proc_lib.erl:249: :proc_lib.init_p_do_apply/3

FYI, here is a minimum repository to reproduce this issue.

Why does not it work?

In an escript binary, ExTermbox is unable to load the NIF file from its priv dir.
This is because priv dir of dependencies are stripped during the escript compilation.

Should we fix it?

I suggest so.

While this is certainly not ExTerbox's fault, and there are other libraries with the same problem too, I think it's a special case for ExTermbox, because ExTermbox IMO is supposed to be used in command-line applications, and CLI applications on Elixir are most likely packed in escripts.

My attempt to fix it

So I took an attempt to solve this problem by changing the way of loading NIF. The idea is to embed NIF binaries into the Elixir module, and generate a temporary file for loading.

I forked and made a proof of concept commit here:
qhwa@971cfe6

and it works. In case you want to see the result, you can check out the embed_nif branch of the example repo to give it a try.

Help needed

Although I got it working as I wished, I need some discussion and your opinions. I wonder if there is a better approach to fix this problem.

Please drop your ideas. :)

'mix compile' fails when using Python 3.11

macOS 14.2

$ elixir -v
Erlang/OTP 26 [erts-14.2] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit:ns]

Elixir 1.15.7 (compiled with Erlang/OTP 26)
$ python --version
Python 3.11.6

When running 'mix compile' on a new Elixir project including ratatouille (which depends on ex_termbox):

$ mix compile
==> ex_termbox
cd c_src/termbox && CFLAGS=-fPIC ./waf configure --prefix=. && ./waf
Waf: The wscript in '/Users/tomhead/projects/nrat/deps/ex_termbox/c_src/termbox' is unreadable
Traceback (most recent call last):
  File "/Users/tomhead/projects/nrat/deps/ex_termbox/c_src/termbox/.waf3-2.0.14-e67604cd8962dbdaf7c93e0d7470ef5b/waflib/Scripting.py", line 102, in waf_entry_point
    set_main_module(wscript)
  File "/Users/tomhead/projects/nrat/deps/ex_termbox/c_src/termbox/.waf3-2.0.14-e67604cd8962dbdaf7c93e0d7470ef5b/waflib/Scripting.py", line 142, in set_main_module
    Context.g_module=Context.load_module(file_path)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tomhead/projects/nrat/deps/ex_termbox/c_src/termbox/.waf3-2.0.14-e67604cd8962dbdaf7c93e0d7470ef5b/waflib/Context.py", line 349, in load_module
    code=Utils.readf(path,m='rU',encoding=encoding)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tomhead/projects/nrat/deps/ex_termbox/c_src/termbox/.waf3-2.0.14-e67604cd8962dbdaf7c93e0d7470ef5b/waflib/Utils.py", line 146, in readf
    with open(fname,m)as f:
         ^^^^^^^^^^^^^
ValueError: invalid mode: 'rUb'
make: *** [c_src/termbox/build/src/libtermbox.a] Error 2

Downgrading Python to 3.10 allows 'mix compile' to complete successfully.

I think this is related to the following issue, which mentions that support for the deprecated 'U' flag was removed in v3.11:

open(): remove 'U' mode, deprecated since Python 3.3 #81511

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.