~emersion/mrsh

eaf18a7e54797ec42929f370acafb8ab2a549e4e — emersion 4 years ago a40f49c
Add editline support
5 files changed, 38 insertions(+), 12 deletions(-)

M .builds/archlinux.yml
M .builds/freebsd.yml
M frontend/readline.c
M meson.build
M meson_options.txt
M .builds/archlinux.yml => .builds/archlinux.yml +2 -1
@@ 2,12 2,13 @@ image: archlinux
packages:
  - gcc
  - meson
  - readline
sources:
  - https://github.com/emersion/mrsh
tasks:
  - setup: |
      cd mrsh
      meson build -Db_sanitize=address,undefined
      meson build -Db_sanitize=address,undefined -Dreadline=enabled
  - build: |
      cd mrsh
      ninja -C build

M .builds/freebsd.yml => .builds/freebsd.yml +2 -1
@@ 1,12 1,13 @@
image: freebsd
packages:
  - meson
  - libedit
sources:
  - https://github.com/emersion/mrsh
tasks:
  - setup: |
      cd mrsh
      meson build
      meson build -Dreadline=enabled -Dreadline-provider=editline
  - build: |
      cd mrsh
      ninja -C build

M frontend/readline.c => frontend/readline.c +10 -5
@@ 1,12 1,18 @@
/* readline/libedit interactive line interface */
// readline/editline interactive line interface
#define _POSIX_C_SOURCE 200809L
#include <limits.h>
#include <mrsh/parser.h>
#include <mrsh/shell.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if defined(HAVE_READLINE)
#include <readline/history.h>
#include <readline/readline.h>
#include <mrsh/shell.h>
#include <mrsh/parser.h>
#elif defined(HAVE_EDITLINE)
#include <editline/readline.h>
#include <histedit.h>
#endif
#include "frontend.h"

static const char *get_history_path() {


@@ 24,11 30,10 @@ void interactive_init(struct mrsh_state *state) {
size_t interactive_next(struct mrsh_state *state,
		char **line, const char *prompt) {
	char *rline = readline(prompt);
	size_t len = 0;
	if (!rline) {
		return 0;
	}
	len = strlen(rline);
	size_t len = strlen(rline);
	if (!(state->options & MRSH_OPT_NOLOG)) {
		add_history(rline);
		write_history(get_history_path());

M meson.build => meson.build +16 -5
@@ 17,10 17,21 @@ add_project_arguments('-Wno-missing-field-initializers', language: 'c')

cc = meson.get_compiler('c')

readline = cc.find_library(
	'readline',
	required: get_option('readline') == 'enabled',
)
if get_option('readline') != 'disabled'
	if get_option('readline-provider') == 'readline'
		readline = cc.find_library(
			'readline',
			required: get_option('readline') == 'enabled',
		)
		add_project_arguments('-DHAVE_READLINE', language: 'c')
	else # editline
		readline = dependency(
			'libedit',
			required: get_option('readline') == 'enabled',
		)
		add_project_arguments('-DHAVE_EDITLINE', language: 'c')
	endif
endif

mrsh_inc = include_directories('include')



@@ 99,7 110,7 @@ shell_deps = [mrsh]
shell_files = [
	'main.c'
]
if readline.found() and get_option('readline') != 'disabled'
if get_option('readline') != 'disabled' and readline.found()
	shell_deps += [readline]
	shell_files += ['frontend/readline.c']
else

M meson_options.txt => meson_options.txt +8 -0
@@ 5,3 5,11 @@ option(
	value: 'auto',
	description: 'Enable improved interactive interface via readline',
)

option(
	'readline-provider',
	type: 'combo',
	choices: ['readline', 'editline'],
	value: 'readline',
	description: 'Provider of the readline library',
)