rcarriga / nvim-dap-ui

A UI for nvim-dap
MIT License
2.59k stars 95 forks source link

Inputting into `scanf` #278

Closed chowder3907 closed 1 year ago

chowder3907 commented 1 year ago

Hello, thanks for the great project. I'm trying to be able to input back into the terminal when it asks, however I cannot and am instead taken to the dap terminal if I press i. Is there something I'm missing? Here's my init.lua

require "core"

local custom_init_path = vim.api.nvim_get_runtime_file("lua/custom/init.lua", false)[1]

if custom_init_path then
  dofile(custom_init_path)
end

require("core.utils").load_mappings()

local lazypath = vim.fn.stdpath "data" .. "/lazy/lazy.nvim"

-- bootstrap lazy.nvim!
if not vim.loop.fs_stat(lazypath) then
  require("core.bootstrap").gen_chadrc_template()
  require("core.bootstrap").lazy(lazypath)
end

dofile(vim.g.base46_cache .. "defaults")
vim.opt.rtp:prepend(lazypath)
require "plugins"

local dap = require('dap')

dap.adapters.lldb = {
  type = 'executable',
  command = '/usr/bin/lldb-vscode-14', -- adjust as needed, must be absolute path
  name = 'lldb'
}

dap.configurations.cpp = {
  {
    name = 'Launch',
    type = 'lldb',
    request = 'launch',
    console = 'integrated',
    program = function()
      return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
    end,
    cwd = '${workspaceFolder}',
    stopOnEntry = false,
    args = {},
  },
}

-- If you want to use this for Rust and C, add something like this:
dap.configurations.c = dap.configurations.cpp
dap.configurations.rust = dap.configurations.cpp

require('dapui').setup()

here's my C program, pretty simple.

// C program to add two numbers
#include <stdio.h>

int main()
{
        int A, B, sum = 0;

        // Ask user to enter the two numbers
        printf("Enter number A: \n");

        // Read two numbers from the user || A = 2, B = 3
        scanf("%d", &A);
  printf("Enter number B: \n");
  scanf("%d", &B);
        // Calculate the addition of A and B
        // using '+' operator
        sum = A + B;

        // Print the sum
        printf("Sum of A and B is: %d", sum);

        return 0;
}

And here's a video of my problem

https://github.com/rcarriga/nvim-dap-ui/assets/63274355/c59fcab1-d5dd-4d07-acc2-be7e9bef353e

lavish440 commented 1 year ago

Remove the console = "integrated" line from your config. Also, the terminal of DapUI doens't seem to print the last line without \n at end.

rcarriga commented 1 year ago

The console value should be set to "integratedTerminal" which should make the debugger use the console window (right) which is a valid terminal instead of the REPL (left) which is not supposed to act as a terminal

eXvimmer commented 1 year ago

The console value should be set to "integratedTerminal" which should make the debugger use the console window (right) which is a valid terminal instead of the REPL (left) which is not supposed to act as a terminal

@rcarriga I have done this, but when I try to enter a value in DAP console window, it says E21: Cannot make changes, 'modifiable' is off. What should I do?

rcarriga commented 1 year ago

You'll have to provide more information using a minimal config to reproduce. Please open a separate issue, closing this as I believe it's resolved