热门问题
时间线
聊天
视角

GNU Readline

軟件庫,通過命令行界面為交互式程序提供行編輯和歷史記錄功能 来自维基百科,自由的百科全书

GNU Readline
Remove ads

GNU Readline是一個軟件庫,可為具有命令行界面(例如Bash)的交互式程序英語interactive program提供行編輯器和歷史記錄功能。是GNU計劃的一部分,目前由Chet Ramey維護。

事实速览 原作者, 開發者 ...

用戶可以移動文本光標,搜索命令歷史,控制kill ring(一個更靈活的剪貼板),並在文本終端上使用Tab鍵自動完成。作為一個跨平臺的庫,readline允許不同系統上的應用程序展現相同的行編輯行為。

Remove ads

GPL許可協議

GNU Readline是一個著名的自由軟件庫,它是通過GNU通用公共許可協議(GPL)進行授權的。而其他的自由軟件庫通常是通過GNU寬公用許可協議(LGPL)進行授權,例如GNU C庫GNU GettextFLTK[1]但其它軟件在分發時,如果鏈接到像GNU Readline這種GPL協議的庫,必須將與之相連的整個軟件以GPL協議進行授權,以符合GPL第5章的規定。[2][3]自由軟件基金會為GNU Readline選用了這個授權協議,以鼓勵其它軟件選用GPL協議。[4]

示例代碼

下面的代碼是C語言的,必須通過向編譯器傳遞-lreadline標誌來鏈接到readline庫:

#include <stdlib.h>
#include <stdio.h>
#include <readline/readline.h>
#include <readline/history.h>

int main()
{
    // Configure readline to auto-complete paths when the tab key is hit.
    rl_bind_key('\t', rl_complete);

    while (1) {
        // Display prompt and read input
        char* input = readline("prompt> ");

        // Check for EOF.
        if (!input)
            break;

        // Add input to readline history.
        add_history(input);

        // Do stuff...

        // Free buffer that was allocated by readline
        free(input);
    }
    return 0;
}
Remove ads

外部連結

Loading related searches...

Wikiwand - on

Seamless Wikipedia browsing. On steroids.

Remove ads