Skip to content

Commit

Permalink
Changes to make vim work with scribble
Browse files Browse the repository at this point in the history
  • Loading branch information
N-Holzschuch committed Nov 19, 2022
1 parent 11429ca commit a25c2c4
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 6 deletions.
6 changes: 4 additions & 2 deletions build_vim_xcframework.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ ln -s Frameworks_iOS Frameworks

make distclean
# 1) configure
./configure vim_cv_toupper_broken=no vim_cv_terminfo=no vim_cv_tgetent=zero vim_cv_memmove_handles_overlap=no vim_cv_memcpy_handles_overlap=no vim_cv_bcopy_handles_overlap=no vim_cv_tty_group=world vim_cv_stat_ignores_slash=yes vim_cv_getcwd_broken=no LUA_PREFIX=${PWD} vi_cv_path_plain_lua=/usr/bin/lua vi_cv_version_plain_lua=5.3.4 --with-tlib=ncurses --with-features=big --enable-terminal --enable-luainterp --enable-python3interp --with-python3-command=python3 CC=clang CXX=clang++ CFLAGS="-DEXITFREE -arch arm64 -O2 -miphoneos-version-min=14.0 -isysroot $IOS_SDKROOT -fembed-bitcode -DDYNAMIC_PYTHON3" CPPFLAGS="-DEXITFREE -arch arm64 -O2 -miphoneos-version-min=14.0 -isysroot $IOS_SDKROOT -DDYNAMIC_PYTHON3" CXXFLAGS="-DEXITFREE -arch arm64 -O2 -miphoneos-version-min=14.0 -isysroot $IOS_SDKROOT -fembed-bitcode -DDYNAMIC_PYTHON3" LDFLAGS="-shared -arch arm64 -O2 -miphoneos-version-min=14.0 -isysroot $IOS_SDKROOT -F$FRAMEWORKS -framework ios_system " --build=x86_64-apple-darwin --host=armv7-apple-darwin
# --enable-terminal
./configure vim_cv_toupper_broken=no vim_cv_terminfo=no vim_cv_tgetent=zero vim_cv_memmove_handles_overlap=no vim_cv_memcpy_handles_overlap=no vim_cv_bcopy_handles_overlap=no vim_cv_tty_group=world vim_cv_stat_ignores_slash=yes vim_cv_getcwd_broken=no LUA_PREFIX=${PWD} vi_cv_path_plain_lua=/usr/bin/lua vi_cv_version_plain_lua=5.3.4 --with-tlib=ncurses --with-features=big --enable-luainterp --enable-python3interp --with-python3-command=python3 CC=clang CXX=clang++ CFLAGS="-DEXITFREE -arch arm64 -O2 -miphoneos-version-min=14.0 -isysroot $IOS_SDKROOT -fembed-bitcode -DDYNAMIC_PYTHON3" CPPFLAGS="-DEXITFREE -arch arm64 -O2 -miphoneos-version-min=14.0 -isysroot $IOS_SDKROOT -DDYNAMIC_PYTHON3" CXXFLAGS="-DEXITFREE -arch arm64 -O2 -miphoneos-version-min=14.0 -isysroot $IOS_SDKROOT -fembed-bitcode -DDYNAMIC_PYTHON3" LDFLAGS="-shared -arch arm64 -O2 -miphoneos-version-min=14.0 -isysroot $IOS_SDKROOT -F$FRAMEWORKS -framework ios_system " --build=x86_64-apple-darwin --host=armv7-apple-darwin

# 2) make. This creates ./src/vim, a Mach-O 64-bit dynamically linked shared library for arm64.
make
Expand Down Expand Up @@ -55,7 +56,8 @@ rm Frameworks
ln -s Frameworks_Simulator Frameworks

make distclean
./configure vim_cv_toupper_broken=no vim_cv_terminfo=no vim_cv_tgetent=zero vim_cv_memmove_handles_overlap=no vim_cv_memcpy_handles_overlap=no vim_cv_bcopy_handles_overlap=no vim_cv_tty_group=world vim_cv_stat_ignores_slash=yes vim_cv_getcwd_broken=no --with-tlib=ncurses --with-features=big --enable-terminal CC=clang CXX=clang++ CFLAGS="-DEXITFREE -O2 -mios-simulator-version-min=14.0 -isysroot $SIM_SDKROOT -fembed-bitcode" CPPFLAGS="-DEXITFREE -O2 -mios-simulator-version-min=14.0 -isysroot $SIM_SDKROOT" CXXFLAGS="-DEXITFREE -O2 -mios-simulator-version-min=14.0 -isysroot $SIM_SDKROOT -fembed-bitcode" LDFLAGS="-O2 -shared -mios-simulator-version-min=14.0 -isysroot $SIM_SDKROOT -fembed-bitcode -F$FRAMEWORKS -framework ios_system " --build=x86_64-apple-darwin --host=armv7-apple-darwin
# --enable-terminal
./configure vim_cv_toupper_broken=no vim_cv_terminfo=no vim_cv_tgetent=zero vim_cv_memmove_handles_overlap=no vim_cv_memcpy_handles_overlap=no vim_cv_bcopy_handles_overlap=no vim_cv_tty_group=world vim_cv_stat_ignores_slash=yes vim_cv_getcwd_broken=no --with-tlib=ncurses --with-features=big CC=clang CXX=clang++ CFLAGS="-DEXITFREE -O2 -mios-simulator-version-min=14.0 -isysroot $SIM_SDKROOT -fembed-bitcode" CPPFLAGS="-DEXITFREE -O2 -mios-simulator-version-min=14.0 -isysroot $SIM_SDKROOT" CXXFLAGS="-DEXITFREE -O2 -mios-simulator-version-min=14.0 -isysroot $SIM_SDKROOT -fembed-bitcode" LDFLAGS="-O2 -shared -mios-simulator-version-min=14.0 -isysroot $SIM_SDKROOT -fembed-bitcode -F$FRAMEWORKS -framework ios_system " --build=x86_64-apple-darwin --host=armv7-apple-darwin

# 2) make. This creates ./src/vim, a Mach-O 64-bit dynamically linked shared library for arm64.
make
Expand Down
77 changes: 74 additions & 3 deletions src/os_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -4411,7 +4411,49 @@ restore_environment()
# endif
environmentRestored = true;
}
#endif

typedef struct _keyboardParameters {
FILE* stdin;
FILE* stdout;
FILE* stderr;
int toshell_fd;
} keyboardParameters;

static void* forwardKeyboard(void* parameters) {
// What do I need: curbuf, toshell_fd.
keyboardParameters* kp = (keyboardParameters*)parameters;
int toshell_fd = kp->toshell_fd;
thread_stdin = kp->stdin;
thread_stdout = kp->stdout;
thread_stderr = kp->stderr;

// Can't use getchar, because it blocks all file reading functions, including fileno!
// Must wait for something to happen on thread_stdin, but passively.
#define BUFSIZE 1024
char buffer[BUFSIZE];
int in = fileno(thread_stdin);
int out = fileno(thread_stdout);
int num = read(in, buffer, BUFSIZE);
int written = 0;

for (;;)
{
while (written < num) {
written += write(out, buffer + written, num - written);
}
if (buffer[num - 1] == '\r') {
buffer[num-1] = '\n';
write(toshell_fd, buffer, num);
num = 0;
written = 0;
buffer[0] = '\n';
write(out, buffer, 1);
}
num += read(in, buffer + num, BUFSIZE - num);
}
}

#endif // TARGET_OS_IPHONE

#endif

Expand Down Expand Up @@ -4491,6 +4533,14 @@ build_argv(
char **argv = NULL;
int argc;

#if TARGET_OS_IPHONE
// Prevent the user from running ":term" or ":!sh"
if ((cmd == NULL) || (strcmp(cmd, "/bin/sh") == 0) || (strcmp(cmd, "sh") == 0)) {
mch_msg("We cannot run sh from Vim. Try :VimShell for a terminal.");
return FAIL;
}
#endif

*sh_tofree = vim_strsave(p_sh);
if (*sh_tofree == NULL) /* out of memory */
return FAIL;
Expand Down Expand Up @@ -4525,6 +4575,12 @@ build_argv(

argv[argc++] = (char *)cmd;
}
#if TARGET_OS_IPHONE
else {
mch_msg("We cannot start an empty shell command in Vim. Try :VimShell to open a terminal.\r\n");
return FAIL;
}
#endif
argv[argc] = NULL;
return OK;
}
Expand Down Expand Up @@ -4938,7 +4994,6 @@ mch_call_shell_fork(
vim_ignored = dup(fd_toshell[0]);
close(fd_toshell[0]);
# else
// iOS:
ios_dup2(fd_toshell[0], 0);
# endif
# if !TARGET_OS_IPHONE
Expand Down Expand Up @@ -4973,6 +5028,9 @@ mch_call_shell_fork(
* to the X server (esp. with GTK, which uses atexit()).
*/
#if TARGET_OS_IPHONE
// For taking keyboard input (if it works)
pipe(fd_toshell);
ios_dup2(fd_toshell[0], 0);
ios_system(cmd); // We do not need argv and sh, but we still built them to minimize code changes.
#else
execvp(argv[0], argv);
Expand All @@ -4984,6 +5042,7 @@ mch_call_shell_fork(
else /* parent */
#endif
{
// options == 4 (SHELL_COOKED). No SHELL_READ or SHELL_WRITE. Until I forced it in ex_cmds.
/*
* While child is running, ignore terminating signals.
* Do catch CTRL-C, so that "got_int" is set.
Expand All @@ -4993,6 +5052,16 @@ mch_call_shell_fork(
UNBLOCK_SIGNALS(&curset);
#if TARGET_OS_IPHONE
signal(SIGWINCH, (RETSIGTYPE (*)())sig_winch);
// iOS: listen to tty, write to output
keyboardParameters kp;
kp.toshell_fd = fd_toshell[1];
kp.stdin = thread_stdin;
kp.stdout = thread_stdout;
kp.stderr = thread_stderr;
volatile pthread_t _tid = NULL;
pthread_create(&_tid, NULL, forwardKeyboard, (void*)&kp);
while (_tid == NULL) { }
pthread_detach(_tid);
#endif
# ifdef FEAT_JOB_CHANNEL
++dont_check_job_ended;
Expand Down Expand Up @@ -5034,7 +5103,7 @@ mch_call_shell_fork(
else
# endif
{
# ifndef TARGET_OS_IPHONE
# if !TARGET_OS_IPHONE
close(fd_toshell[0]);
close(fd_fromshell[1]);
# endif
Expand Down Expand Up @@ -5513,6 +5582,8 @@ mch_call_shell_fork(

if (wait_pid != pid)
wait_pid = wait4pid(pid, &status);
if (_tid != NULL) pthread_cancel(_tid);


# ifdef FEAT_GUI
/* Close slave side of pty. Only do this after the child has
Expand Down
7 changes: 7 additions & 0 deletions src/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -2283,10 +2283,17 @@ screen_fill(
if (c2 == ' '
&& end_col == Columns
&& can_clear(T_CE)
// iOS: we need to use T_CE if we want scribble to write with Vim
// If this causes issues, deactivate the test only when scribble is active
#if !TARGET_OS_IPHONE
&& (attr == 0
|| (norm_term
&& attr <= HL_ALL
&& ((attr & ~(HL_BOLD | HL_ITALIC)) == 0))))
#else
)
#endif

{
/*
* check if we really need to clear something
Expand Down
8 changes: 7 additions & 1 deletion src/term.c
Original file line number Diff line number Diff line change
Expand Up @@ -2575,12 +2575,18 @@ all_termrequests[0] = &crv_status;
all_termrequests[1] = &u7_status;
# ifdef FEAT_TERMINAL
all_termrequests[2] = &rfg_status;
# endif
all_termrequests[3] = &rbg_status;
all_termrequests[4] = &rbm_status;
all_termrequests[5] = &rcs_status;
all_termrequests[6] = &winpos_status;
all_termrequests[7] = NULL;
# else
all_termrequests[2] = &rbg_status;
all_termrequests[3] = &rbm_status;
all_termrequests[4] = &rcs_status;
all_termrequests[5] = &winpos_status;
all_termrequests[6] = NULL;
# endif
#endif

#ifdef __BEOS__
Expand Down

0 comments on commit a25c2c4

Please sign in to comment.