Commit Graph

93 Commits

Author SHA1 Message Date
Justin M. Keyes
9f81acc076
paste: break lines at CR, CRLF #10877
Some terminals helpfully translate \n to \r.

fix #10872
ref #10223
2019-08-29 23:45:02 +02:00
Justin M. Keyes
3157baed83 API: TRY_WRAP() for "abort-causing non-exception errors"
- Introduce TRY_WRAP() until we have an *architectural* solution.
  - TODO: bfredl idea: prepare error-handling at "top level" (nv_event).
- nvim_paste(): Revert luaeval() hack (see parent commit).
  - With TRY_WRAP() in nvim_put(), 'nomodifiable' error now correctly
    "bubbles up".
2019-08-28 00:55:13 +02:00
Justin M. Keyes
46aa254bf3 paste: handle 'nomodifiable'
- nvim_paste(): Marshal through luaeval() instead of nvim_execute_lua()
  because the latter seems to hide some errors.
- Handle 'nomodifiable' in `nvim_put()` explicitly.
- Require explicit `false` from `vim.paste()` in order to "cancel",
  otherwise assume true ("continue").
2019-08-27 23:37:15 +02:00
Justin M. Keyes
87389c6a57 paste: make vim.paste() "public" 2019-08-27 22:14:52 +02:00
Justin M. Keyes
ed60015266 paste: handle vim.paste() failure
- Show error only once per "paste stream".
- Drain remaining chunks until phase=3.
- Lay groundwork for "cancel".
- Constrain semantics of "cancel" to mean "client must stop"; it is
  unrelated to presence of error(s).
2019-08-27 22:13:45 +02:00
Justin M. Keyes
5b41070c63 paste: implement redo (AKA dot-repeat)
- Normal-mode redo idiom(?): prepend "i" and append ESC.
- Insert-mode only needs AppendToRedobuffLit().
- Cmdline-mode: only paste the first line.
2019-08-27 22:13:45 +02:00
Justin M. Keyes
bfc5a18f4b paste: insert text "before" cursor in Insert-mode 2019-08-27 22:13:45 +02:00
Justin M. Keyes
eacc70fb3e API: nvim_paste 2019-08-27 22:13:45 +02:00
Justin M. Keyes
c95f5d166f paste: workaround typeahead race
Workaround this failure:

    [  ERROR   ] test/functional/terminal/tui_spec.lua @ 192: TUI paste: exactly 64 bytes
    test/functional/helpers.lua:403:
    retry() attempts: 478
    test/functional/terminal/tui_spec.lua:201: Expected objects to be the same.
    Passed in:
    (table: 0x47cd77e8) {
     *[1] = 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz endz' }
    Expected:
    (table: 0x47cd7830) {
     *[1] = 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz end' }

This happens because `curwin->w_cursor.col` is sometimes decremented at
the end of `do_put`... because the editor is in Normal-mode instead of
the expected Insert-mode.

Caused by "typeahead race" (#10826): there may be queued input in the
main thread not yet processed, thus the editor mode (`State` global)
will be "wrong" during paste. Example: input "i" followed immediately by
a paste sequence:

    i<start-paste>...<stop-paste>
    ^
     "i" does not get processed in time, so the editor is in
     Normal-mode instead of Insert-mode while handling the paste.

Attempted workarounds:
- vim.api.nvim_feedkeys('','x',false) in vim._paste()
- exec_normal() in tinput_wait_enqueue()
- LOOP_PROCESS_EVENTS(&main_loop,…,0) in tinput_wait_enqueue()

ref #10826
2019-08-27 21:19:10 +02:00
Justin M. Keyes
613296936b API: nvim_put: always PUT_CURSEND
Fixes strange behavior where sometimes the buffer contents of a series
of paste chunks (vim._paste) would be out-of-order.

Now the tui_spec.lua screen-tests are much more reliable. But they still
sometimes fail because of off-by-one cursor (caused by "typeahead race"
resulting in wrong mode; fixed later in this patch-series).
2019-08-27 21:19:10 +02:00
Justin M. Keyes
1fdae25b2b test/tui_spec: connect to child session 2019-08-27 21:19:10 +02:00
Justin M. Keyes
0221a9220a paste: edge-case: handle EOL at end-of-buffer
This is "readfile()-style", see also ":help channel-lines".
2019-08-27 21:19:10 +02:00
Justin M. Keyes
d303790ee7 paste: test 2019-08-27 21:19:10 +02:00
Justin M. Keyes
5a2894d677 paste: use nvim_put() 2019-08-27 21:19:10 +02:00
Justin M. Keyes
abd55be19a paste: fixup tests 2019-08-27 21:19:10 +02:00
Justin M. Keyes
68ea9a7c8a TUI/paste: always flush on paste mode-change
Flush input before entering, not only when leaving, paste mode. Else
there could be pending input which will erroneously be sent to the paste
handler.
2019-08-27 21:19:10 +02:00
Daniel Hahler
1e2af5e39d
tests: make TERM=interix test pending (#10576)
Ref: https://github.com/neovim/neovim/issues/10179
Ref: https://github.com/neovim/neovim/pull/9494
2019-07-22 18:49:37 +02:00
Daniel Hahler
e48257e63e
tests: fix/improve "TUI background color" tests (#10229)
- Ensure the opposite of the expected bg is active.
- Improves performance: 1.2s instead of 4.5s.
2019-07-03 03:37:19 +02:00
Alan Wu
9fd4a0b526 getchar: Handle incomplete <Paste> in typeahead buffer #10311
<Paste> is a 3-byte sequence and the beginning one or two bytes can appear at
the very end of the typeahead buffer. When this happens, we were exiting from
`vgetorpeek()` instead of reading more characters to see the complete sequence.

I think this should fix #7994 -- at least partially. Before this change, when I
paste exactly 64 characters into a freshly booted instance, I get what I pasted
plus the literal text "<Paste>" at the end. Nvim also stays in nopaste mode.
The attached test case fails in this manner without the code change.

Fix #7994
2019-06-24 00:28:04 +02:00
Harm te Hennepe
424ddd01f5 tui: support rgba background detection (#10205)
Fixes https://github.com/neovim/neovim/issues/10159.
2019-06-13 14:14:41 +02:00
erw7
ce90a19abd TUI: set os/input.c:global_fd to input->in_fd #10174
Problem: When we changed startup to wait for the TUI (like a remote UI),
         we forgot to set os/input.c:global_fd.  That used to be done by
         input_start().

Solution: Initialize os/input.c:global_fd before initializing libtermkey
          (termkey_new_abstract) so that tui_get_stty_erase() and
          friends can inspect the correct fd.

fixes #10134
close #10174
2019-06-10 16:43:52 +02:00
Justin M. Keyes
fd04877eb0 test: remove use of require('test.helpers')
The test.functional.helpers and test.unit.helpers modules now include
all of the public functions from test.helpers, so there is no need to
separately require('test.helpers').
2019-05-18 15:48:13 +02:00
Justin M. Keyes
b9ad12e6c2 UI/nvim_ui_attach(): add override option
Before now, Nvim always degrades UI capabilities to the lowest-common
denominator. For example, if any connected UI has `ext_messages=false`
then `ext_messages=true` requested by any other connected UI is ignored.

Now `nvim_ui_attach()` supports `override=true`, which flips the
behavior: if any UI requests an `ext_*` UI capability then the
capability is enabled (and the legacy behavior is disabled).

Legacy UIs will be broken while a `override=true` UI is connected, but
it's useful for debugging: you can type into the TUI and observe the UI
events from another connected (UI) client. And the legacy UI will
"recover" after the `override=true` UI disconnects.

Example using pynvim:

    >>> n.ui_attach(2048, 2048, rgb=True, override=True, ext_multigrid=True, ext_messages=True, ext_popupmenu=True)
    >>> while True: n.next_message();
2019-05-09 22:27:41 +02:00
Justin M. Keyes
b90256e6cc test: simplify TUI bg-detection test
Previous approach skipped the test if the expected value matched the
default value ("dark"). New approach always checks, but uses retry() to
ignore potentially wrong 'background' before the terminal response is
handled.
2019-03-15 05:26:41 +01:00
Justin M. Keyes
43184566aa TUI/background detection: hook into VimEnter event
If terminal response is received during startup, set 'background' from
a nested "one-shot" (once) VimEnter autocmd.

The previous not-so-clever "self-rescheduling" approach could cause
a long delay at startup (event-loop does not make forward progress).

fixes #9675
ref #9509
2019-03-11 08:43:27 +01:00
Justin M. Keyes
d3dc946155 TUI: rework background-color detection
- Like Vim, use set_option_value() followed by reset_option_was_set().
- Do not use set_string_default(), so the default is predictable.
  This affects `:set bg&`.
- Wait until end-of-startup (VimEnter) to handle the response. The
  response is racey anyways, so timing is irrelevant. This allows
  OptionSet to be triggered, unlike during startup.
2019-02-22 21:15:16 +01:00
Justin M. Keyes
6bd6927656 Merge #5027 'TUI: detect background color' 2019-02-17 14:47:40 +01:00
Björn Linse
baf93d9606 UI: always use contrete colors for default_colors_set
But add an escape hatch needed for external TUI, so it still can use
terminal emulator defaults.
2019-02-05 19:41:38 +01:00
Andrew Pyatkov
894f6bee54 :terminal : set topline based on window height #8325
closes #8324
closes #8556
2019-01-29 03:00:48 +01:00
Justin M. Keyes
7e9b99d55b Merge #5027 'TUI: detect background color' 2019-01-17 13:05:51 +01:00
Utkarsh Maheshwari
ebe16cd9bd multigrid: add multigrid screen tests 2018-12-31 12:44:22 +01:00
Björn Linse
1f8afe15a4 multigrid: add multigrid support to test infrastructure
make Screen explicitly tied to its session
2018-12-31 12:44:22 +01:00
Justin M. Keyes
e85b911f02 test: win/TUI builtin terminfos 2018-12-28 01:46:25 +01:00
Justin M. Keyes
32a30d90b4
highlight: Fix missing .rgb_sp_color in initializers (#9287)
terminal_get_line_attributes() had this bug for a long time, though it
likely had no effect visible to users.

ref #9028
ref 60f845ca55
2018-11-30 21:13:01 +01:00
Justin M. Keyes
deb18a050e
defaults: background=dark #2894 (#9205)
By historical accident, Nvim defaults to background=light. So on a dark
background, `:colorscheme default` looks completely wrong.

The "smart" logic that Vim uses is confusing for anyone who uses Vim on
multiple platforms, so rather than mimic that, pick the (hopefully) most
common default.

- Since Neovim is dark-powered, we assume most users have dark backgrounds.
- Most of the GUIs tend to have a dark background by default.

ref #6289
2018-11-20 10:52:49 +01:00
Björn Linse
c8810a51a3 tests: improve robustness of immediate successes in screen tests 2018-10-15 20:13:11 +02:00
Björn Linse
075dc42fb2 test: replace wait() with pre-assertion in assert_term_colors 2018-10-06 11:36:09 +02:00
Björn Linse
43823acae2 ui: rename ext_newgrid to ext_linegrid 2018-10-01 21:24:15 +02:00
Björn Linse
3d88287e30 tests: introduce screen:expect{...} form 2018-08-27 15:15:49 +02:00
Björn Linse
1adb01c120 ui: use line-based rather than char-based updates in screen.c
Add ext_newgrid and ext_hlstate extensions. These use predefined
highlights and line-segment based updates, for efficiency and
simplicity.. The ext_hlstate extension in addition allows semantic
identification of builtin and syntax highlights.

Reimplement the old char-based updates in the remote UI layer, for
compatibility. For the moment, this is still the default. The bulitin
TUI uses the new line-based protocol.

cmdline uses curwin cursor position when ext_cmdline is active.
2018-07-21 13:21:58 +02:00
Björn Linse
5be3865ce7 nvim_list_uis: include channel id 2018-06-01 10:20:13 +02:00
Justin M. Keyes
48967695c4
test: tui_spec.lua: relax test (#8289)
Sometimes an extra FocusGained/FocusLost event might trigger. This
doesn't matter, we just want to test that the events were received in
cmdline-mode.
2018-04-16 23:35:58 +02:00
Justin M. Keyes
224ebc0078 insert-mode: interpret unmapped META as ESC
closes #2454
closes #8213
ref #7972
2018-04-04 03:23:15 +02:00
Björn Linse
5d8da126d0 ui/tui: highlighting refactor
Make HlAttr contain highlighting state for both color modes (cterm and rgb).
This allows us to implement termguicolors completely in the TUI.

Simplify some logic duplicated between ui.c and screen.c. Also avoid
some superfluous highlighting reset events.
2018-02-11 10:29:32 +01:00
Justin M. Keyes
1be315de37 tui: final_column_wrap(): fix row calculation
closes #7572
closes #7579
closes #7628

ASAN report:

    ==9500==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6040000024c0 at pc 0x00000187d2ca bp 0x7fc3c6e58d10 sp 0x7fc3c6e58d08
    READ of size 8 at 0x6040000024c0 thread T1
        0 0x187d2c9 in ugrid_put /home/vagrant/neovim/build/../src/nvim/ugrid.c:107:17
        1 0x1850adf in tui_put /home/vagrant/neovim/build/../src/nvim/tui/tui.c:1012:10
        2 0x18a6ce6 in ui_bridge_put_event /home/vagrant/neovim/build/src/nvim/auto/ui_events_bridge.generated.h:154:3
        3 0xa4dcda in multiqueue_process_events /home/vagrant/neovim/build/../src/nvim/event/multiqueue.c:150:7
        4 0xa478bf in loop_poll_events /home/vagrant/neovim/build/../src/nvim/event/loop.c:63:3
        5 0x185451c in tui_main /home/vagrant/neovim/build/../src/nvim/tui/tui.c:362:12
        6 0x18a3080 in ui_thread_run /home/vagrant/neovim/build/../src/nvim/ui_bridge.c:106:3
        7 0x7fc3caaac6b9 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x76b9)
        8 0x7fc3c9ca33dc in clone /build/glibc-bfm8X4/glibc-2.23/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:109

    0x6040000024c0 is located 0 bytes to the right of 48-byte region [0x604000002490,0x6040000024c0)
    allocated by thread T1 here:
        0 0x50e048 in malloc (/home/vagrant/neovim/build/bin/nvim+0x50e048)
        1 0xf7ab71 in try_malloc /home/vagrant/neovim/build/../src/nvim/memory.c:87:15
        2 0xf7ad99 in xmalloc /home/vagrant/neovim/build/../src/nvim/memory.c:121:15
        3 0x187937b in ugrid_resize /home/vagrant/neovim/build/../src/nvim/ugrid.c:32:17
        4 0x184be58 in tui_resize /home/vagrant/neovim/build/../src/nvim/tui/tui.c:770:3
        5 0x18a3dc8 in ui_bridge_resize_event /home/vagrant/neovim/build/src/nvim/auto/ui_events_bridge.generated.h:4:3
        6 0xa4dcda in multiqueue_process_events /home/vagrant/neovim/build/../src/nvim/event/multiqueue.c:150:7
        7 0xa478bf in loop_poll_events /home/vagrant/neovim/build/../src/nvim/event/loop.c:63:3
        8 0x185451c in tui_main /home/vagrant/neovim/build/../src/nvim/tui/tui.c:362:12
        9 0x18a3080 in ui_thread_run /home/vagrant/neovim/build/../src/nvim/ui_bridge.c:106:3
        10 0x7fc3caaac6b9 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x76b9)

    Thread T1 created by T0 here:
        0 0x4655ed in __interceptor_pthread_create (/home/vagrant/neovim/build/bin/nvim+0x4655ed)
        1 0x1ad87b0 in uv_thread_create /home/vagrant/neovim/.deps/build/src/libuv/src/unix/thread.c:75
        2 0x184b9aa in tui_start /home/vagrant/neovim/build/../src/nvim/tui/tui.c:159:10
        3 0x188dd4c in ui_builtin_start /home/vagrant/neovim/build/../src/nvim/ui.c:125:3
        4 0xe6d399 in main /home/vagrant/neovim/build/../src/nvim/main.c:457:5
        5 0x7fc3c9bbc82f in __libc_start_main /build/glibc-bfm8X4/glibc-2.23/csu/../csu/libc-start.c:291
2018-01-16 09:37:55 +01:00
Björn Linse
34057045be
ui: forward relevant option updates to UIs (#7520)
also make termguicolors mutable after startup
2017-12-12 18:23:19 +01:00
Justin M. Keyes
2d4abc1cae tui: flush -V3 ('verbose' >= 3) info ASAP 2017-12-05 01:46:41 +01:00
Justin M. Keyes
837100fcb1 test/tui: -V3log logs terminfo values 2017-12-05 01:46:41 +01:00
Justin M. Keyes
175174597d test: macOS 10.13: unibilium cannot find "xterm" terminfo
On some macOS versions we can't find the terminfo for whatever reason,
so just skip the test if it fails.
2017-12-05 01:46:40 +01:00
Justin M. Keyes
a11751eae8 test: tui_spec: narrower scope for timeout tweaks 2017-12-05 01:46:40 +01:00