Code Monkey home page Code Monkey logo

Comments (2)

mobily avatar mobily commented on May 29, 2024

@b0o could you provide a repro, please? 🙏

from nui-components.nvim.

b0o avatar b0o commented on May 29, 2024

The issue depends on the timing of when the signal value is updated. Specifically, it seems to happen if the signal is updated in the middle of a render?

local n = require 'nui-components'

local renderer = n.create_renderer {
  width = math.min(vim.o.columns, 64),
  height = math.min(vim.o.lines, 20),
}

local signal = n.create_signal {
  stdout = '',
  stderr = '',
}

renderer:render(
  --
  n.rows(
    n.paragraph {
      is_focusable = false,
      -- Side note: Although we are mapping over the stdout signal value, the function is called when
      -- either stdout or stderr changes.
      -- In fact, it seems we can map over any signal field, even if it doesn't exist, like signal.foobar:map(...)
      -- IMO, we should be able to just do signal:map() instead of needing to index a specific field
      lines = signal.stdout:map(function()
        local val = signal:get_value()
        return {
          n.line(n.text('Stdout: ', 'Keyword'), val.stdout),
          n.line(n.text('Stderr: ', 'Keyword'), val.stderr),
        }
      end),
    },
    n.gap(1),
    n.button {
      label = ' Run Command ',
      autofocus = true,
      on_press = function()
        vim.fn.jobstart('for i in {1..10}; do sleep 0.1; echo "stdout: $i"; echo "stderr: $i" >&2; done', {
          on_stdout = function(_, data, _)
            if data and data[1] and data[1] ~= '' then
              signal.stdout = data[1]
            end
          end,
          on_stderr = function(_, data, _)
            if data and data[1] and data[1] ~= '' then
              signal.stderr = data[1]
            end
          end,
        })
      end,
    }
  )
)

You might need to press the Run Command button a few times to see the error.

from nui-components.nvim.

Related Issues (15)

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.