1
0
Fork 0

new linenoise-ng

This commit is contained in:
Frank Celler 2016-03-15 16:54:43 +01:00
parent 1df84976d7
commit ae8430589f
9 changed files with 2695 additions and 2314 deletions

4
3rdParty/linenoise-ng/.clang-format vendored Normal file
View File

@ -0,0 +1,4 @@
BasedOnStyle: Google
DerivePointerAlignment: false
PointerAlignment: Left
Standard: Cpp11

View File

@ -1,4 +1,12 @@
CMakeCache.txt
CMakeFiles
Makefile
build
cmake_install.cmake
install_manifest.txt
example
linenoise_example
liblinenoise.a
*.dSYM
history.txt
*.o

View File

@ -29,27 +29,42 @@ if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${BASE_COMPILER_OPTIONS} -O3 -fomit-frame-pointer")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${BASE_COMPILER_OPTIONS} -O3 -g")
elseif(CMAKE_COMPILER_IS_CLANGCXX)
elseif(CMAKE_COMPILER_IS_CLANGCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# using regular Clang or AppleClang
message(STATUS "Compiler type CLANG: ${CMAKE_CXX_COMPILER}")
set(BASE_COMPILER_OPTIONS "-std=c++11 -Wall -Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILER_COMPTIONS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILER_OPTIONS}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${BASE_COMPILER_OPTIONS} -O0 -g")
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} ${BASE_COMPILER_OPTIONS} -Os")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${BASE_COMPILER_OPTIONS} -O3 -fomit-frame-pointer")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${BASE_COMPILER_OPTIONS} -O3 -g")
elseif(MSVC)
elseif(MSVC)
message(STATUS "Compiler type MSVC: ${CMAKE_CXX_COMPILER}")
add_definitions("-D_CRT_SECURE_NO_WARNINGS=1")
set(${CMAKE_CXX_FLAGS} "${CMAKE_CXX_FLAGS} /MT")
set(${CMAKE_CXX_FLAGS_DEBUG} "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
# hard-coded target platform to x64. does not link otherwise
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MACHINE:x64 /SUBSYSTEM:CONSOLE /LTCG /SAFESEH:NO /ignore:4099")
foreach (flag_var
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS_RELWITHDEBINFO)
if (flag_var MATCHES "DEBUG")
set(${flag_var} "${${flag_var}} /MTd")
else ()
set(${flag_var} "${${flag_var}} /MT")
endif ()
endforeach()
# https://msdn.microsoft.com/en-us/library/aa267384%28VS.60%29.aspx
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /INCREMENTAL:NO /SUBSYSTEM:CONSOLE /LTCG /ignore:4099 /NODEFAULTLIB:libc.lib /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:libcd.lib /NODEFAULTLIB:msvcrtd.lib")
set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL} /SUBSYSTEM:CONSOLE /ignore:4099 /NODEFAULTLIB:libc.lib /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:libcd.lib /NODEFAULTLIB:msvcrtd.lib")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /SUBSYSTEM:CONSOLE /ignore:4099 /NODEFAULTLIB:libc.lib /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:libcd.lib /NODEFAULTLIB:msvcrtd.lib")
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /SUBSYSTEM:CONSOLE /ignore:4099 /NODEFAULTLIB:libc.lib /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:libcd.lib /NODEFAULTLIB:msvcrtd.lib")
else()
# unknown compiler
message(STATUS "Compiler type UNKNOWN: ${CMAKE_CXX_COMPILER}")
set(BASE_COMPILER_OPTIONS "-std=c++11 -Wall -Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILER_COMPTIONS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILER_OPTIONS}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${BASE_COMPILER_OPTIONS} -O0 -g")
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} ${BASE_COMPILER_OPTIONS} -Os")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${BASE_COMPILER_OPTIONS} -O3 -fomit-frame-pointer")
@ -68,6 +83,12 @@ add_library(
src/wcwidth.cpp
)
# install
install(TARGETS linenoise DESTINATION lib)
# headers
install(FILES include/linenoise.h DESTINATION include)
# build example
add_executable(
example

View File

@ -1,25 +1,66 @@
Copyright (c) 2010-2014, Salvatore Sanfilippo <antirez at gmail dot com>
Copyright (c) 2010-2013, Pieter Noordhuis <pcnoordhuis at gmail dot com>
linenoise.cpp
=============
Copyright (c) 2010, Salvatore Sanfilippo <antirez at gmail dot com>
Copyright (c) 2010, Pieter Noordhuis <pcnoordhuis at gmail dot com>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Redis nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
wcwidth.cpp
===========
Markus Kuhn -- 2007-05-26 (Unicode 5.0)
Permission to use, copy, modify, and distribute this software
for any purpose and without fee is hereby granted. The author
disclaims all warranties with regard to this software.
ConvertUTF.cpp
==============
Copyright 2001-2004 Unicode, Inc.
Disclaimer
This source code is provided as is by Unicode, Inc. No claims are
made as to fitness for any particular purpose. No warranties of any
kind are expressed or implied. The recipient agrees to determine
applicability of information provided. If this file has been
purchased on magnetic or optical media from Unicode, Inc., the
sole remedy for any claim will be exchange of defective media
within 90 days of receipt.
Limitations on Rights to Redistribute This Code
Unicode, Inc. hereby grants the right to freely use the information
supplied in this file in the creation of products supporting the
Unicode Standard, and to make copies of this file in any form
for internal or external distribution as long as this notice
remains attached.

View File

@ -1,23 +1,87 @@
# Linenoise Next Generation
A linenoise implementation based on the work by Salvatore Sanfilippo,
10gen Inc and others. They goal is to create a zero-config, BSD
A small, portable GNU readline replacement for Linux, Windows and
MacOS which is capable of handling UTF-8 characters. Unlike GNU
readline, which is GPL, this library uses a BSD license and can be
used in any kind of program.
## Origin
This linenoise implementation is based on the work by
[Salvatore Sanfilippo](https://github.com/antirez/linenoise) and
10gen Inc. The goal is to create a zero-config, BSD
licensed, readline replacement usable in Apache2 or BSD licensed
programs.
* single and multi line editing mode with the usual key bindings implemented
## Features
* single-line and multi-line editing mode with the usual key bindings implemented
* history handling
* completion
* BSD license source code
* Only uses a subset of VT100 escapes (ANSI.SYS compatible)
* UTF8 aware
* support for linux, MacOS and Windows
* support for Linux, MacOS and Windows
It deviates from Salvatore's original goal to have a minimal readline
replacement for the sake of supporting UTF8 and Windows. It deviates
from 10gen Inc. goal to create a C++ interface, we stick to a pure
C interface. However, the library itself uses C++11 unicode strings
internally.
from 10gen Inc.'s goal to create a C++ interface to linenoise. This
library uses C++ internally, but to the user it provides a pure C
interface that is compatible with the original linenoise API.
C interface.
## Requirements
To build this library, you will need a C++11-enabled compiler and
some recent version of CMake.
## Build instructions
To build this library on Linux, first create a build directory
```bash
mkdir -p build
```
and then build the library:
```bash
(cd build && cmake -DCMAKE_BUILD_TYPE=Release .. && make)
```
To build and install the library at the default target location, use
```bash
(cd build && cmake -DCMAKE_BUILD_TYPE=Release .. && make && sudo make install)
```
The default installation location can be adjusted by setting the `DESTDIR`
variable when invoking `make install`:
```bash
(cd build && make DESTDIR=/tmp install)
```
To build the library on Windows, use these commands in an MS-DOS command
prompt:
```
md build
cd build
```
After that, invoke the appropriate command to create the files for your
target environment:
* 32 bit: `cmake -G "Visual Studio 12 2013" -DCMAKE_BUILD_TYPE=Release ..`
* 64 bit: `cmake -G "Visual Studio 12 2013 Win64" -DCMAKE_BUILD_TYPE=Release ..`
After that, open the generated file `linenoise.sln` from the `build`
subdirectory with Visual Studio.
*note: the following sections of the README.md are from the original
linenoise repository and are partly outdated*
## Can a line editing library be 20k lines of code?
@ -79,12 +143,14 @@ use both in free software and commercial software.
* FreeBSD xterm ($TERM = xterm)
* ANSI.SYS
* Emacs comint mode ($TERM = dumb)
* Windows
Please test it everywhere you can and report back!
## Let's push this forward!
Patches should be provided in the respect of linenoise sensibility for
small easy to understand code that. They must be submitted under the
Apache2 license using the supplied Apache2 contributor license
agreement.
small and easy to understand code that and the license
restrictions. Extensions must be submitted under a BSD license-style.
A contributor license is required for contributions.

11
3rdParty/linenoise-ng/appveyor.yml vendored Normal file
View File

@ -0,0 +1,11 @@
version: 1.0.{build}
branches:
only:
- master
configuration: Release
build:
build_script:
- md build
- cd %APPVEYOR_BUILD_FOLDER%\build
- cmake -G "Visual Studio 12 Win64" -DCMAKE_BUILD_TYPE=Release ..
- cmake --build . --config Release

View File

@ -44,21 +44,25 @@
extern "C" {
#endif
typedef struct linenoiseCompletions linenoiseCompletions;
typedef struct linenoiseCompletions linenoiseCompletions;
typedef void(linenoiseCompletionCallback)(const char*, linenoiseCompletions*);
void linenoiseSetCompletionCallback(linenoiseCompletionCallback* fn);
void linenoiseAddCompletion(linenoiseCompletions* lc, const char* str);
typedef void(linenoiseCompletionCallback)(const char*, linenoiseCompletions*);
void linenoiseSetCompletionCallback(linenoiseCompletionCallback* fn);
void linenoiseAddCompletion(linenoiseCompletions* lc, const char* str);
char* linenoise(const char* prompt);
void linenoisePreloadBuffer(const char* preloadText);
int linenoiseHistoryAdd(const char* line);
int linenoiseHistorySetMaxLen(int len);
int linenoiseHistorySave(const char* filename);
int linenoiseHistoryLoad(const char* filename);
void linenoiseHistoryFree(void);
void linenoiseClearScreen(void);
int linenoiseInstallWindowChangeHandler(void);
char* linenoise(const char* prompt);
void linenoisePreloadBuffer(const char* preloadText);
int linenoiseHistoryAdd(const char* line);
int linenoiseHistorySetMaxLen(int len);
char* linenoiseHistoryLine(int index);
int linenoiseHistorySave(const char* filename);
int linenoiseHistoryLoad(const char* filename);
void linenoiseHistoryFree(void);
void linenoiseClearScreen(void);
void linenoiseSetMultiLine(int ml);
void linenoisePrintKeyCodes(void);
/* the following is extension to the original linenoise API */
int linenoiseInstallWindowChangeHandler(void);
#ifdef __cplusplus
}

File diff suppressed because it is too large Load Diff

View File

@ -18,7 +18,18 @@ void completionHook (char const* prefix, linenoiseCompletions* lc) {
}
}
int main () {
int main (int argc, char** argv) {
linenoiseInstallWindowChangeHandler();
while(argc > 1) {
argc--;
argv++;
if (!strcmp(*argv, "--keycodes")) {
linenoisePrintKeyCodes();
exit(0);
}
}
const char* file = "./history";
linenoiseHistoryLoad(file);
@ -26,13 +37,21 @@ int main () {
printf("starting...\n");
char const* prompt = "linenoise> ";
char const* prompt = "\x1b[1;32mlinenoise\x1b[0m> ";
while (1) {
char* result = linenoise(prompt);
if (result == NULL) {
break;
} else if (!strncmp(result, "/history", 8)) {
/* Display the current history. */
for (int index = 0; ; ++index) {
char* hist = linenoiseHistoryLine(index);
if (hist == NULL) break;
printf("%4d: %s\n", index, hist);
free(hist);
}
}
if (*result == '\0') {
free(result);
@ -43,7 +62,7 @@ int main () {
linenoiseHistoryAdd(result);
free(result);
}
linenoiseHistorySave(file);
linenoiseHistoryFree();
}