【问题标题】:Auto-completion visual not good (readline.h)自动完成视觉效果不佳(readline.h)
【发布时间】:2016-06-07 21:15:41
【问题描述】:

我想在我创建的 shell 上添加自动完成功能。我无法输入整个代码,但我可以告诉你我的 shell 正在工作! 所以我尝试通过使用 readline 函数来实现自动完成,但结果不是很好(请参阅我尝试过的评论中的代码):自动完成工作但问题是: 1.我现在需要按两次回车才能执行命令。 2. 我需要输入两次命令(如“ls”)才能执行!你能帮我解决这个问题吗?谢谢你:)

#include <readline/readline.h>
#include <readline/history.h>
#include <stdlib.h>
#include <stdio.h>
#include "includes/ft_sh1.h"

int main(int ac, char **av, char **envp)
{
    char    *line;
    t_env   *e = NULL;
    char *add;

    if (!(e = (t_env *)malloc(sizeof(t_env))))
        return (0);
    e->envp = env_cpy(envp, 0, 0);
    init_env(e);
    while (1)
    {

--> My question is only about this part below <--

        ft_printf("shell$> ");

     //   add =  readline( "shell ");
     //   add_history(add);
     //   printf("%s", add);

--> My question is only about this part above <--


        get_next_line(0, &line);
        get_pwd_env(e);
        e->cmd = get_cmd(e, line);
        if (ft_strcmp(line, "exit") == 0)
            exit(0);
        else if (ft_strncmp(e->cmd[0], "cd", 2) == 0)
            cd_cmd(e);
        else
            ft_execute(av, line, e);
    }
}

【问题讨论】:

    标签: c shell autocomplete


    【解决方案1】:

    当您只是取消注释有问题的代码部分时,您仍然可以调用

            get_next_line(0, &line);
    

    在你的程序中,难怪你需要输入两个命令行。

    【讨论】:

      猜你喜欢
      • 2021-09-15
      • 1970-01-01
      • 1970-01-01
      • 2015-11-30
      • 1970-01-01
      • 2010-11-09
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多