Giter Site home page Giter Site logo

amokhuginnsson / replxx Goto Github PK

View Code? Open in Web Editor NEW
667.0 32.0 104.0 912 KB

A readline and libedit replacement that supports UTF-8, syntax highlighting, hints and Windows and is BSD licensed.

License: Other

CMake 1.29% C 5.32% C++ 59.62% Python 32.76% Shell 0.58% PowerShell 0.42%
readline syntax-highlighting utf-8 multiplatform gnu-readline linenoise ansi libedit

replxx's Introduction

Read Evaluate Print Loop ++

demo

Build Status

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 replxx implementation is based on the work by ArangoDB Team and Salvatore Sanfilippo and 10gen Inc. The goal is to create a zero-config, BSD licensed, readline replacement usable in Apache2 or BSD licensed programs.

Features

  • single-line and multi-line editing mode with the usual key bindings implemented
  • history handling
  • completion
  • syntax highlighting
  • hints
  • BSD license source code
  • Only uses a subset of VT100 escapes (ANSI.SYS compatible)
  • UTF8 aware
  • support for Linux, MacOS and Windows

Requirements

To build this library, you will need a C++11-enabled compiler and some recent version of CMake.

Build instructions

*nix

  1. Create a build directory
mkdir -p build && cd build
  1. Build the library
cmake -DCMAKE_BUILD_TYPE=Release .. && make
  1. Install the library at the default target location
sudo make install

The default installation location can be adjusted by setting the DESTDIR variable when invoking make install:

make DESTDIR=/tmp install

Windows

  1. Create a build directory in MS-DOS command prompt
md build
cd build
  1. Generate Visual Studio solution file with cmake
  • 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 ..
  1. Open the generated file replxx.sln in the build subdirectory with Visual Studio.

Tested with...

  • Linux text only console ($TERM = linux)
  • Linux KDE terminal application ($TERM = xterm)
  • Linux xterm ($TERM = xterm)
  • Linux Buildroot ($TERM = vt100)
  • Mac OS X iTerm ($TERM = xterm)
  • Mac OS X default Terminal.app ($TERM = xterm)
  • OpenBSD 4.5 through an OSX Terminal.app ($TERM = screen)
  • IBM AIX 6.1
  • FreeBSD xterm ($TERM = xterm)
  • ANSI.SYS
  • Emacs comint mode ($TERM = dumb)
  • Windows

Please test it everywhere you can and report back!

replxx's People

Contributors

ajg avatar alexey-milovidov avatar amokhuginnsson avatar amosbird avatar antirez avatar blattersturm avatar bsutherland avatar fceller avatar fingolfin avatar firodj avatar fnxweb avatar gdimitrov-vmware avatar gilzoide avatar gsserge avatar guusw avatar gwenn avatar jsteemann avatar ksherlock avatar minfrin avatar naios avatar nlebedenco avatar octplane avatar olegator77 avatar pietern avatar polch avatar shengwen-tw avatar spullara avatar starwing avatar syohex avatar yury avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

replxx's Issues

Terminal::clear_screen is broken on Windows

Introduction

As the code is currently structured, the call to replxx::clear_screen happens while raw-mode is disabled.
Unfortunately, that means _consoleOut (and _consoleIn) have been invalidated, which means all Windows API calls with these handles will fail.

As such, this code should be updated with a separate path for when raw mode is disabled.

Relevant code:

replxx/src/io.cxx

Lines 604 to 621 in a8553d0

#ifdef _WIN32
COORD coord = { 0, 0 };
CONSOLE_SCREEN_BUFFER_INFO inf;
bool toEnd( clearScreen_ == CLEAR_SCREEN::TO_END );
GetConsoleScreenBufferInfo( _consoleOut, &inf );
if ( ! toEnd ) {
SetConsoleCursorPosition( _consoleOut, coord );
} else {
coord = inf.dwCursorPosition;
}
DWORD nWritten( 0 );
DWORD toWrite(
toEnd
? ( inf.dwSize.Y - inf.dwCursorPosition.Y ) * inf.dwSize.X - inf.dwCursorPosition.X
: inf.dwSize.X * inf.dwSize.Y
);
FillConsoleOutputCharacterA( _consoleOut, ' ', toWrite, coord, &nWritten );
#else

Reproduction

This issue can be reproduced by trying to run the .clear command in the CXX API example on Windows.

Modernize CMake definition

How do you feel about bumping the minimum required CMake version to 2.8.12?

I would like to use replxx from source by adding it as a subdirectory in my project. In modern CMake for this to work more naturally so I can just use the replxx target it would require to add the replxx include directory as public dependency to the replxx target:

target_include_directories(replxx PUBLIC ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/src)

This feature though requires CMake at least 2.8.12.

Thanks

Feature request: timeout callback

First of all, thanks for this awesome piece of software, it has really rocket my world :-)

It would be great to have a timeout callback, similar to the

rl_set_keyboard_input_timeout(100000);
rl_event_hook = timeout_function;

construct of libreadline.

Question: Switch from static global state to an explicitly constructed state.

How do you feel about switching replxx from a static global state which is implicitly used by all public methods to an explicitly constructed and initialized state owned by the application.
This will remove the static construction order potential problem as well as allow some additional features. One of the benefits would be the ability to choose which file descriptors to be used by replxx.

This will be an API breaking change because all public methods would need to be modified with one additional parameter.

The usage would look like this:

main()
{
    replxx* repl;
    replxx_init(repl, stdin, stdout, stderr);
    replxx_install_window_change_handler(repl);
    replxx_history_load(repl, file);
    ...
    repl_free(repl);
}

Programmatic Input Manipulation

I'd like a way to move the cursor inside "()" after I complete them. I can only return a vector of strings from my completion callback, so I need some API to accomplish this on the Replxx class.

missing prompt on Windows using MSYS2

How to reproduce:

  • On Windows 10, install MSYS2 64bit
  • Use pacman to install dev tools and libraries (git, make, gcc, etc).
  • Use git to clone today's version of replxx.
  • Build today's version of replxx on Windows using MSYS2 (using the MinGW 64 bit shell):
    cd replxx
    mkdir build
    cd build
    cmake -G"MSYS2 Makefile" ..
    make
    
  • Run the example program:
    ./replxx-example-cxx-api
    

The prompt is not printed. This bug doesn't occur on Ubuntu Linux.

Adding simple Unit Tests

What are your thoughts on adding some simple Unit Tests? I was thinking some Google Tests but another framework would work just as good.

I was thinking that taking the examples and putting them in a unit test form could be nice.

Headers #undef Windows-defined definitions which can be needed

The replxx.h and .hxx headers undef DELETE and ERROR, which are set to required values by Windows headers. I'm not going to justify Windows doing that (their headers are full of #defines)! One, in replxx.h is even redundant — I think these both came from the original linenoise source.

However, we have code that requires those defines that replxx masks.

I don't see a non-breaking way to fix this; locally, I have renamed them to DEL and _ERROR and then removed the undefs, which worked for me.

Possibility to use shell commands

Hello,

I'm using replxx for an interactive command line application combined with TCLAP. It is nice and easy to use. I was wondering if there is a way to support also system commands.
For example on linux if I type ls (dir on windows), send it to the system prompt and get the output back.
Do you think there is an easy way? I mean, if the command is not one of the supported (auto-completed) send it to the system?

Thanks a lot.

CTRL-P/CTRL-N unexpected behavior

CTRL-P and CTRL-N do not work as expected in the head revision.
What they should do is move up and down the history list, just like up-arrow and down-arrow.
They used to work this way, but the behaviour has changed.

Can reproduce using the example application.

Autoclosing Grouping Characters?

Is there a way to wrangle replxx into automatically closing grouping symbols like (), {}, [], etc..?

I feel like there is a way to hack into one of the completion systems but that feels wrong.

Implement a way to verify history files are loaded

In the linenoise library, the history modification functions return 0 if successful and -1 on error. There doesn't appear to any way to do something like this in replxx. Here are the related functions in linenoise:

https://github.com/antirez/linenoise/blob/97d2850af13c339369093b78abe5265845d78220/linenoise.h#L61-L64

Could something similar be added to this library? Instead of returning an int, it would be much better to return a bool or an enum signaling what went wrong.

Thanks so much for this great library!

Issue with editing of lines without any callbacks.

Hi, I have found a display problem when doing line editing when there are no callbacks.

To reproduce the problem, recompile your demo program c-api.c without the callbacks, i.e.

//replxx_set_completion_callback( replxx, completionHook, examples );
//replxx_set_highlighter_callback( replxx, colorHook, replxx );
//replxx_set_hint_callback( replxx, hintHook, examples );
//replxx_bind_key( replxx, '.', word_eater, replxx );

Run the demo, input a line and return, then try to redit the line, and the display of the line doesn't match what is captured. Here's an example:

starting...
replxx> (+ 1 2)
thanks for the input: (+ 1 2)
replxx> (+ 1 )4
thanks for the input: (+ 1 4)
replxx>

What I did was: up arrow, left arrow, backspace, 4. The bracket disappeared, but the program captured the correct input. The line displayed was not correct.

However, in the demo program when I turn on the callbacks, I can't reduplicate the problem.

Thanks, for your library. Apart from this, it seems to work fine.

Word break escape support?

For a project I'm trying to migrate away from GNU/Readline to this library here. I encountered an issue I couldn't figure out yet.

In readline there is support for escaping characters like spaces and quotes. So when you set the work break character to a space it won't be actually recognized as a word break, allowing to auto complete strings with spaces in it, while at the same time it is possible to kind of "restart" the completion when an actual unescaped space is passed.

Does this library support this?

Bump minimum CMake version for more modern usage?

Hi! Looks like this isn't the first time people have requested this, however, I'd like to up the minimum CMake version to at least 3.4, or higher if desired. I can submit a pull request after your decision to what version, but I highly recommend a version at or greater than 3.4. This would make your CMakeLists.txt a lot more manageable and remove a lot of unnecessary boilerplate.

Possibly support bazel build?

Hi!

Thank you for this amazing library.

Bazel makes it easy to integrate the library by simply specifying the target dependency as "@replxx". The users of the library don't need to know how to build the library as a result. Do you think the library could support building with Bazel directly so people wouldn't have to maintain their own BUILD.bazel files? Here's example usage:

cc_binary(
    name = "executable",
    srcs = ["src/main.cc"],
    deps = [
        "@replxx",       # <-- super simple.
    ],
)

I include it in my workspace using:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "replxx",
    type = "zip",
    url = "https://github.com/AmokHuginnsson/replxx/archive/<commit>.zip",
    sha256 = "<sha256-digest>",
    strip_prefix = "replxx-<commit>",
    # Don't need the following line if project includes a Bazel build file shown below along 
    # with a WORKSPACE file.
    build_file = "//third_party/cc/remote:replxx.BUILD",
)

BUILD.bazel file:

load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")

licenses(["notice"])  # BSD

exports_files(["LICENSE.md"])

cc_binary(
    name = "example_c",
    srcs = [
        "examples/c-api.c",
    ],
    visibility = ["//visibility:public"],
    deps = [
        ":examples_util_lib",
    ],
)

cc_binary(
    name = "example_cc",
    srcs = [
        "examples/cxx-api.cxx",
    ],
    visibility = ["//visibility:public"],
    deps = [
        ":examples_util_lib",
    ],
)

cc_library(
    name = "examples_util_lib",
    srcs = [
        "examples/util.c",
    ],
    hdrs = [
        "examples/util.h",
    ],
    deps = [
        ":replxx",
    ],
)

cc_library(
    name = "replxx",
    srcs = [
        "src/ConvertUTF.cpp",
        "src/conversion.cxx",
        "src/escape.cxx",
        "src/history.cxx",
        "src/io.cxx",
        "src/prompt.cxx",
        "src/replxx.cxx",
        "src/replxx_impl.cxx",
        "src/util.cxx",
        "src/wcwidth.cpp",
        "src/windows.cxx",
    ],
    hdrs = [
        "include/replxx.h",
        "include/replxx.hxx",
        "src/ConvertUTF.h",
        "src/conversion.hxx",
        "src/escape.hxx",
        "src/history.hxx",
        "src/io.hxx",
        "src/killring.hxx",
        "src/prompt.hxx",
        "src/replxx_impl.hxx",
        "src/unicodestring.hxx",
        "src/utf8string.hxx",
        "src/util.hxx",
        "src/windows.hxx",
    ],
    includes = [
        "include",
    ],
    linkstatic = True,
    visibility = ["//visibility:public"],
)

To build and run the example, I just type bazel run "@replx//:example_cc":

❯ bazel run "@replxx//:example_cc"
INFO: Analyzed target @replxx//:example_cc (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target @replxx//:example_cc up-to-date:
  bazel-bin/external/replxx/example_cc
INFO: Elapsed time: 5.804s, Critical Path: 2.85s
INFO: 0 processes.
INFO: Build completed successfully, 1 total action
INFO: Build completed successfully, 1 total action
Welcome to Replxx
Press 'tab' to view autocompletions
Type '.help' for help
Type '.quit' or '.exit' to exit

replxx> 

Bazel fetches the correct version and enables reproducible builds. The only changes the user needs are the 1st and the 2nd code snippets. That allows the user to have hermetic, reproducible, and fast builds.

What do you think?

CMake Policy CMP0048

CMake Warning (dev) at replxx/CMakeLists.txt:5 (project):
  Policy CMP0048 is not set: project() command manages VERSION variables.
  Run "cmake --help-policy CMP0048" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.

  The following variable(s) would be set to empty:

    PROJECT_VERSION
    PROJECT_VERSION_MAJOR
    PROJECT_VERSION_MINOR
    PROJECT_VERSION_PATCH
This warning is for project developers.  Use -Wno-dev to suppress it.

cmake --help-policy CMP0048
CMP0048
-------

The ``project()`` command manages VERSION variables.

CMake version 3.0 introduced the ``VERSION`` option of the ``project()``
command to specify a project version as well as the name.  In order to keep
``PROJECT_VERSION`` and related variables consistent with variable
``PROJECT_NAME`` it is necessary to set the VERSION variables
to the empty string when no ``VERSION`` is given to ``project()``.
However, this can change behavior for existing projects that set VERSION
variables themselves since ``project()`` may now clear them.
This policy controls the behavior for compatibility with such projects.

The OLD behavior for this policy is to leave VERSION variables untouched.
The NEW behavior for this policy is to set VERSION as documented by the
``project()`` command.

This policy was introduced in CMake version 3.0.
CMake version 3.10.2 warns when the policy is not set and uses
OLD behavior.  Use the cmake_policy command to set it to OLD or
NEW explicitly.

.. note::
  The ``OLD`` behavior of a policy is
  ``deprecated by definition``
  and may be removed in a future version of CMake.

adding

if (POLICY CMP0048)
  cmake_policy(SET CMP0048 OLD)
endif()

to the top of the CMakeLists.txt suppresses the error for now. The "correct" solution is to bump the cmake minimum to 3.0 and use

project(replxx VERSION 0.0.1 LANGUAGES CXX)

Build fails on clang 10 with UBSAN

I'm on clang 10.0.0:

$ clang++-10 --version
clang version 10.0.0 
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm/10/bin

And I cannot build replxx when using USAN (-fsanitize=undefined):

$ CC=clang-10 CXX=clang++-10 LD=clang-10 \
  CFLAGS='-fsanitize=undefined' \
  CXXFLAGS='-fsanitize=undefined' \
  LDFLAGS='-fsanitize=undefined' \
  cmake -GNinja -DBUILD_SHARED_LIBS=ON path/to/replxx && ninja -k 666
-- The CXX compiler identification is Clang 10.0.0
-- The C compiler identification is Clang 10.0.0
-- Check for working CXX compiler: /usr/lib/llvm/10/bin/clang++-10
-- Check for working CXX compiler: /usr/lib/llvm/10/bin/clang++-10 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working C compiler: /usr/lib/llvm/10/bin/clang-10
-- Check for working C compiler: /usr/lib/llvm/10/bin/clang-10 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE  
CMake Warning (dev) at CMakeLists.txt:41 (message):
  CMAKE_BUILD_TYPE not set.  Defaulting to Release
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY - Success
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY - Success
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Success
-- Configuring done
-- Generating done
-- Build files have been written to: /home/jkt/temp/xx
[0/2] Re-checking globbed directories...
[17/19] Linking C executable replxx-example-c-api
FAILED: replxx-example-c-api 
: && /usr/lib/llvm/10/bin/clang-10 -fsanitize=undefined -O3 -DNDEBUG  -fsanitize=undefined CMakeFiles/replxx-example-c-api.dir/examples/c-api.c.o CMakeFiles/replxx-example-c-api.dir/examples/util.c.o  -o replxx-example-c-api  -Wl,-rpath,/home/jkt/temp/xx libreplxx.so.0.0.2 && :
libreplxx.so.0.0.2: undefined reference to `__ubsan_vptr_type_cache'
libreplxx.so.0.0.2: undefined reference to `__ubsan_handle_function_type_mismatch_v1'
libreplxx.so.0.0.2: undefined reference to `__ubsan_handle_dynamic_type_cache_miss'
clang-10: error: linker command failed with exit code 1 (use -v to see invocation)
[19/19] Linking CXX executable replxx-example-cxx-api
ninja: build stopped: cannot make progress due to previous errors.

I can reproduce this on a Gentoo Linux system with clang 10, and on Fedora 31 with clang 9. Configuring with (-DREPLXX_BUILD_EXAMPLES=OFF) makes this problem go away.

Aborted while entering non-ascii characters in quoted string

Hello!
Nice library.

But there is a problem.
Input aborted while entering non-ascii characters (cyrillics in my case) as quoted string (no matter it is a double or single quotation mark).

Below the example of output (aborted when I tried to close the quotation mark immediately after the first character).

replxx> "Фterminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 3) >= this->size() (which is 3) Aborted (core dumped)

Thanks

Problem with siglongjmp and "input cancellation"

Consider this code

#include <setjmp.h>
sigjmp_buf ctrlc_buf;
__attribute__((noreturn))
static void prompt_cancel_input(int)
{
    std::endl(std::cout);
    // jump back to prompt
    siglongjmp(ctrlc_buf, 1);
}

// ...

// register jump address
while (sigsetjmp(ctrlc_buf, 1) != 0);

// set Ctrl+C to cancel and restart prompt
const auto &orig_int = std::signal(SIGINT, prompt_cancel_input);

// wait for user input
const auto &input = rx->input(_readlinePrompt);

// restore default Ctrl+C behavior
std::signal(SIGINT, orig_int);

In GNU/Readline (and maybe libeditline too) this works as expected. Cancel input and advance the cursor into the next line and show the prompt again. In replxx though, this doesn't work that way. The cursor just stays in the same line no matter how many line feeds you try to print and shows a new prompt on the right to the current prompt messing up the output. I know about Ctrl+U to clear the line, but this used to be a convenient feature. The output is fixed once pressing enter and getting back to another prompt normally without jumping to it. What part of replxx is causing this to happen, that a jump doesn't work?

ConvertUTF.{cpp,h} are non-free

The ConvertUTF.{cpp,h} are non-free (and buggy/unmaintained), as discussed on the Debian mailing list:

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=823100

This poses problems for packaging/redistribution. Would it be possible to, perhaps, support linking with libicu for this purpose?

We're currently using linenoise-ng in Nix, and this is same issue is blocking an effort to package Nix for Debian. replxx looks nice, and if we could get this issue resolved here, it's possible we'd switch away from linenoise-ng.

Thanks!

Hook hint colouring does not work in Windows10 (at least)

hook hints themselves seem to work, you just can't see them as the colouring isn't set, this may be because it's using VT codes and are not decoding. All other colours elsewhere work fine, it just seems to be when there's more than one hint.

Request for a release

I started using this library and I would love to have it as a package on FreeBSD (my OS of choice). I didn't want to bother you before I created the port itself, so here it is: https://github.com/mekanix/replxx-port. It uses my fork and release on it as I needed some release to work with (checksumming the .tar files, for example), but I would like to use official repo/release in the future. Do you think you can tag any release soon so I can submit the port to be included in official FreeBSD ports? Thanx!

Adding some static analysis

Would you be okay if I helped expand out the Travis CI build to include the static analysis from sonarcloud.io?

I think it could give some good pointers to new developers who would like to help fix issues but don't know where to start. I haven't found out how to get the code coverage on there, but vulnerabilities, code smell, and code duplications appear to work from my playing around with it.

set_max_line_size is error prone

Thanks for the great package, we are using it at lgraph.

One issue has been the "rx.set_max_line_size". At the end, we have to put 32KB.

It would be great if it were unbound (dynamically grown), or at least trigger an error (not split the command) if we go over the limit

Windows 10 Virtual Terminal Sequence Support

Hi,

Windows 10 now supports VT100 escape sequences with a call to SetConsoleMode and the ENABLE_VIRTUAL_TERMINAL_PROCESSING flag. It might ease cross platform support to use this in the primary case, and fall back on the current Windows support only when absolutely necessary, or requested by a user.

gcc compile warnings on Windows

When I compile replxx on Windows using g++ in the MSYS2 environment, I get the following warning messages:

In file included from C:/msys64/curv/curv/repl.cc:34:
C:/msys64/curv/extern/replxx/include/replxx.hxx:250: warning: ignoring '#pragma warning ' [-Wunknown-pragmas]
  250 | #pragma warning(push)
      |
C:/msys64/curv/extern/replxx/include/replxx.hxx:251: warning: ignoring '#pragma warning ' [-Wunknown-pragmas]
  251 | #pragma warning(disable:4251)
      |
C:/msys64/curv/extern/replxx/include/replxx.hxx:255: warning: ignoring '#pragma warning ' [-Wunknown-pragmas]
  255 | #pragma warning(pop)
      |
C:/msys64/curv/extern/replxx/include/replxx.hxx:367: warning: ignoring '#pragma warning ' [-Wunknown-pragmas]
  367 | #pragma warning(push)
      |
C:/msys64/curv/extern/replxx/include/replxx.hxx:368: warning: ignoring '#pragma warning ' [-Wunknown-pragmas]
  368 | #pragma warning(disable:4251)
      |
C:/msys64/curv/extern/replxx/include/replxx.hxx:372: warning: ignoring '#pragma warning ' [-Wunknown-pragmas]
  372 | #pragma warning(pop)
      |

These pragmas are unknown to GCC, they are specific to MSVC++. The solution is to guard them with #ifdef _MSC_VER instead of #ifdef _WIN32.

Line continuation support

I ran into your library, which looks stunning (thank you), and was wondering if it supported line continuation. For example, my need requires that the user be able to "enter" and continue to the next line, with a numerical indicator of the line. Except for the builtin (help format, save, etc... ) commands are ended with a semi-colon ";" ... something like this ...

replxx> this
      2 is
      3 an
      4 example of 
      5 continuation lines;
replxx> this is an example of  continuation lines;

I haven't dug into the library yet, so I thought I'd ask before spending to much time. Any advice, example, or information you can provide would be greatly appreciated.

Thank you

Question: Printing to stdout while replxx is active

Hello,
I was experimenting with the replxx example andthe following question came up:
While asking replxx for some input using rx.input(prompt); is it possible to
print something to stdout meanwhile?

For instance when developing a server application which regularly prints something to stdout
could replxx be used as command line interface such that a console logger stays active
while replxx is still usable?

My own tests have shown that printing interferes with the repl:

  std::thread t([&] {
    while (true) {
      rx.print("some stuff\n");
      std::this_thread::sleep_for(std::chrono::seconds(2));
    }
  });

Replxx output binary name only defined on DEBUG and RELEASE configs

Introduced in 8d1477b.

We build with config RelWithDebInfo, but replxx does not define the binary output names for that config, so they revert to the name of the target.

Relevant lines:

replxx/CMakeLists.txt

Lines 98 to 103 in 8d1477b

if ( MSVC )
set_target_properties( replxx-static PROPERTIES RELEASE_OUTPUT_NAME replxx-static DEBUG_OUTPUT_NAME replxx-static-d )
target_compile_definitions(replxx-static PRIVATE REPLXX_STATIC)
else ()
set_target_properties( replxx-static PROPERTIES RELEASE_OUTPUT_NAME replxx DEBUG_OUTPUT_NAME replxx-d )
endif ()

Allow user defined key bindings (refactor replxx_impl.cxx).

It'd be nice to have the option to auto-complete a line/command with the first available hint when pressing enter/return, rather than have to do it explicitly by tabbing. This would allow emulating the code completion behavior of typical IDEs (and search engine input boxes.)

It doesn't look like this is currently possible, or is it?

Thanks.

bracketed_paste code won't build in win32

read_unicode_character isn't implemented in win32 (escape32.cxx)

replxx/src/replxx_impl.cxx

Lines 1945 to 1949 in 155fed4

Replxx::ACTION_RESULT Replxx::ReplxxImpl::bracketed_paste( char32_t ) {
static const UnicodeString BRACK_PASTE_SUFF( "\033[201~" );
static const int BRACK_PASTE_SLEN( BRACK_PASTE_SUFF.length() );
UnicodeString buf;
while ( char32_t c = read_unicode_character() ) {

Out of bounds vector access

I accidentally caught a Visual Studio debug assertion (not exactly sure what I typed) but it highlighted a possible out of bounds vector access in replxx_impl.cxx (line 1871 at time of writing):

} else if ( ( dp._direction > 0 ) ? ( historySearchIndex < _history.size() ) : ( historySearchIndex > 0 ) ) {
  historySearchIndex += dp._direction;
  activeHistoryLine.assign( _history[historySearchIndex] );

_direction was incremented to have the value of the actual size of the vector, thus going out; I think the check in the if should be: ( historySearchIndex < _history.size() - 1 )

Minor issues in headers

Some minor issues I have found, none of which are actual functionality bugs (so do with them as you please):

  • The Replxx class can't be fully used in a DLL environment on Windows without a version of the __declspec(dllimport/dllexport) dance.
  • ConvertUTF.h is missing an include guard (usually a nicety, but we require them due to the weird way we do our builds).
  • The Doxygen markup in replxx.h is now wrong and produces warnings (replxx_init() now has no parameters but three are documented, and replxx_bind_key() no longer has the documented handle parameter).

Fix for compiling on macOs 10.14 with AppleClang 10.0.1.10010046

Hi, I had to make this fix, in io.cxx line 565 for the library to compile on macOs (added a cast):

timeval tv{ timeout_ / 1000, static_cast<__darwin_suseconds_t>( timeout_ % 1000 ) * 1000 };

the old code was

timeval tv{ timeout_ / 1000, ( timeout_ % 1000 ) * 1000 };

This is probably not a portable fix. The examples seem to work after the library compiled.
I'm on macOs 10.14.6 and the C++ compiler was AppleClang 10.0.1.10010046.

Thanks for the library, it seems great.

Line flickering in Win32

It looks like the Windows API is a bit too slow for Replxx::ReplxxImpl::refresh_line.
When Replxx clears the line to refresh it, Windows will stall to update the command Window and this is visible to end users.

2019-09-24_17-06-49

We can likely fix this by simply clearing past the end of the current line (_display), and overwriting everything else when re-writing _display.

Relevant lines:

replxx/src/replxx_impl.cxx

Lines 726 to 743 in 1982d8c

// position at the end of the prompt, clear to end of previous input
_terminal.jump_cursor(
_prompt._indentation, // 0-based on Win32
-( _prompt._cursorRowOffset - _prompt._extraLines )
);
_terminal.clear_screen( Terminal::CLEAR_SCREEN::TO_END );
_prompt._previousInputLen = _data.length();
// display the input line
_terminal.write32( _display.data(), _display.size() );
#ifndef _WIN32
// we have to generate our own newline on line wrap
if ( ( xEndOfInput == 0 ) && ( yEndOfInput > 0 ) ) {
_terminal.write8( "\n", 1 );
}
#endif
// position the cursor
_terminal.jump_cursor( xCursorPos, -( yEndOfInput - yCursorPos ) );
_prompt._cursorRowOffset = _prompt._extraLines + yCursorPos; // remember row for next pass

Hints are partly broken when no highlighter hook is set

I found a weird issue by accident. Some experiments revealed that when there is no highlighter hook set, the hints are not updated/shown while typing. To make the hints show you need to press backspace. And even than, the hints don't update while typing until you press backspace again.

Once you add a highlighter (can be an empty function too) the hints work normally without issues and keep updating while typing. First I thought it was due to too many data in the hint list (about ~40.000 entries), but apparently that wasn't the issue. replxx can handle that just fine as it seems.

Terminal Emulators used during this finding: KDE/Konsole 18.04.0 and KDE/yakuake 3.0.5 with en_US.UTF-8 locale set.

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.