summaryrefslogtreecommitdiff
path: root/src/terminal_ui.cc
AgeCommit message (Collapse)Author
2025-07-08Replace on_scope_end with CTAD with OnScopeEnd directlyMaxime Coste
2025-06-28fix: simplify variable by removing terminal_ partYukai Huang
2025-06-28fix: remove comment and document usageYukai Huang
2025-06-28Revert "chore: remove terminal option"Yukai Huang
This reverts commit 549a5d2c223d422390795741537b150b492a3935.
2025-06-27fix: revert new line changesYukai Huang
2025-06-27chore: remove terminal optionYukai Huang
2025-06-27fix: prevent cursor rendering conflicts by simplifying cursor positioning logicYukai Huang
2025-06-24feat(terminal): add option for native terminal cursor renderingYukai Huang
2024-09-08Add terminal_title terminal ui_option to control the titleMaxime Coste
Use a separate option from terminal_set_title for simplicity. Fixes #2217 Closes #4265
2024-08-19Merge remote-tracking branch 'arrufat/includes-cleanup'Maxime Coste
2024-08-19Don't interpret the \n input byte as <ret>Johannes Altmanninger
We set both ICRNL and INLCR, so there is no translation of \r to \n and vice versa. This means that when the user presses the Enter key, we always receive \r. So a "\n" input byte can realistically only be sent by <c-j> (or perhaps <c-J>), so we can interpret it as that. This intentionally breaks users that rely on <c-j> doing the same thing as <ret> on terminals that fail to disambiguate those two (for example gnome-terminal). This seems unavoidable; better teach them to map <c-j> separately sooner rather than later.
2024-08-19Decode XTerm's formatOtherKeys=0 encodingJohannes Altmanninger
When typing <s-ret>, XTerm sends \e[27;2;13~ Only when formatOtherKeys is set to 1 by the user, XTerm will send an equivalent CSI u encoding.
2024-08-19Decode kitty keyboard protocol's numlock keysJohannes Altmanninger
Fixes numlock input on Alacritty. Closes #5214
2024-08-16include headers cleanupAdrià Arrufat
2024-08-14Merge remote-tracking branch 'enricozb/enricozb/scroll-coordinates'Maxime Coste
2024-08-14Merge remote-tracking branch 'arrufat/support-double-underline'Maxime Coste
2024-08-12Extract format implementation to its own fileMaxime Coste
Split it to avoid pulling all string_utils dependencies for just format.
2024-08-04add scroll coordinatesEnrico Zandomeni Borba
adds scroll amount in the upper 16-bits of `Key.modifiers`, reclaiming the space in `Key.key` for coordinates. Previously, while mouse events included their coordinates, scrolling did not. Scroll events are now emitted as <scroll:amount:line.column>.
2024-08-04Add support for double underlineAdrià Arrufat
2024-06-23Fix trailing whitespacesMaxime Coste
2024-05-18Revert "Make TerminalUI::get_next_key() helpers static"Johannes Altmanninger
On macOS, backspace reportedly no longer works after <c-z> and fg. The value of m_original_termios.c_cc[VERASE] seems to be wrong in a static lambda that captures a singleton "this". Not sure what's the problem. I thought that it is guaranteed that "static auto convert = [this]() { ... }" is initialized lazily, hence it should capture the correct address. Maybe the address changes somehow or it's UB / a compiler bug. This reverts commit ad36585b7ad236bea7d1c02b0679ae371c3c2a9e Closes #5155
2024-03-15Fix off-by-two error in max size of frameless infoboxesJohannes Altmanninger
Framed info boxes need one cell for the border and one for inner space padding. That's 4 extra columns when counting both sides. Frameless boxes have neither border nor padding so 0 columns here. Closes #5106
2023-12-10Fix compiler warnings when char is unsignedChris Webb
In several places, we check for a control character with something like char c; [...] if (c >= 0 and c <= 0x1F) [...] When char is signed (e.g. amd64) this is fine, but when char is unsigned by default (e.g. arm32 and arm64) this generates warnings about the tautologous check that an unsigned value is non-negative. Write as if ((unsigned char) c <= 0x1F) [...] which is both correct and not suspicious under both conventions.
2023-11-24Skip output synchronization query when explicitly disabledChris Webb
Some terminals misbehave when queried for output synchronization support, such as Windows Terminal as reported in https://github.com/mawww/kakoune/issues/5032 The relatively long response from a terminal which does support output-sync is also prone to getting torn over a slow link such as a serial console, causing stray input to the editor. In ui_options, the terminal_synchronized option controls the use of this feature, but unfortunately the query is unconditionally sent at startup even when this is set false. Skip the query at startup when terminal_synchronized is explicitly false. We query at most once per terminal in set_ui_options so the behaviour is correct both when kakoune is started with terminal_synchronized unset and when it is started with terminal_synchronized set false but this is later unset.
2023-10-25Default comparison operators that can beMaxime Coste
2023-10-25Remove redundant comparison operatorsMaxime Coste
Since C++20 (a != b) get automatically rewritten as !(a == b) if the != operator does not exist.
2023-09-23Merge remote-tracking branch 'krobelus/foot-custom-keypad-sequences'Maxime Coste
2023-08-31Still inkorrect inglishMaxime Coste
Hopefully thats better now
2023-08-29Fix incorrect inglishMaxime Coste
2023-08-27Cleanup SIGHUP handling and forking server to backgroundMaxime Coste
Ensure we ignore SIGHUP once the TerminalUI is gone as it will be sent again on fork, fix the parent process terminating due to trying to write to stdout after it was closed. Fixes #4960
2023-06-24Support CSI u numpad keysJohannes Altmanninger
Normally page-down is sent as \033[6~ but some terminals send a CSI u encoding for the page-down on the numpad. See https://codeberg.org/dnkl/foot#keypad for example. Treat them as the underlying key; we could add a modifier if anyone cares about the distinction.
2023-06-09Remove unneeded this capture in lambdaAdrià Arrufat
Clang 15 was complaining about this.
2023-04-24Fix crash after multiple terminal resizesJohannes Altmanninger
When Kakoune's terminal is shown on my laptop monitor and I plug in my external monitor, the terminal's workspace will move to that external monitor. When this happens, Kakoune may segfault. There are multiple resize events (SIGWINCH) in quick succession; it crashes because we handle SIGWINCH during rendering. The problem happens during execution of "TerminalUI::Screen::output" (frame #18). When we receive SIGWINCH while writing to stdout, write(2) fails with EAGAIN, prompting us to handle pending events (See ae001a1f9 (Run EventManager whenever writing to a file descriptor would block, 2022-05-10)). We update the screen size in check_resize() here: #4 Kakoune::TerminalUI::check_resize (force=<optimized out>) at terminal_ui.cc:683 #5 Kakoune::TerminalUI::get_next_key () at terminal_ui.cc:719 #6 operator() (__closure=0x555555984198) at terminal_ui.cc:484 #7 std::__invoke_impl<void, Kakoune::TerminalUI::TerminalUI()::<lambda(Kakoune::FDWatcher&, Kakoune::FdEvents, Kakoune::EventMode)>&, Kakoune::FDWatcher&, Kakoune::FdEvents, Kakoune::EventMode> (__f=...) at /usr/include/c++/12.2.1/bits/invoke.h:61 #8 std::__invoke_r<void, Kakoune::TerminalUI::TerminalUI()::<lambda(Kakoune::FDWatcher&, Kakoune::FdEvents, Kakoune::EventMode)>&, Kakoune::FDWatcher&, Kakoune::FdEvents, Kakoune::EventMode> (__fn=...) at /usr/include/c++/12.2.1/bits/invoke.h:111 #9 std::_Function_handler<void(Kakoune::FDWatcher&, Kakoune::FdEvents, Kakoune::EventMode), Kakoune::TerminalUI::TerminalUI()::<lambda(Kakoune::FDWatcher&, Kakoune::FdEvents, Kakoune::EventMode)> >::_M_invoke(const std::_Any_data &, Kakoune::FDWatcher &, Kakoune::FdEvents &&, Kakoune::EventMode &&) (__functor=..., __args#0=..., __args#1=<optimized out>, __args#2=<optimized out>) at /usr/include/c++/12.2.1/bits/std_function.h:290 #10 std::function<void (Kakoune::FDWatcher&, Kakoune::FdEvents, Kakoune::EventMode)>::operator()(Kakoune::FDWatcher&, Kakoune::FdEvents, Kakoune::EventMode) const (__args#2=<optimized out>, __args#1=<optimized out>, __args#0=...) at /usr/include/c++/12.2.1/bits/std_function.h:591 #11 Kakoune::FDWatcher::run (mode=Kakoune::EventMode::Urgent, events=<optimized out>) at event_manager.cc:28 #12 Kakoune::EventManager::handle_next_events (mode=mode@entry=Kakoune::EventMode::Urgent, sigmask=sigmask@entry=0x0, block=<optimized out>, block@entry=false) at event_manager.cc:143 #13 Kakoune::write (fd=1, data=...) at file.cc:273 #14 Kakoune::BufferedWriter<4096>::flush () at string.hh:236 #15 Kakoune::BufferedWriter<4096>::write (data="t file.hh:145 #16 Kakoune::TerminalUI::Screen::set_face (face=..., writer=...) at terminal_ui.cc:255 #17 operator() (line=..., __closure=<synthetic pointer>) at terminal_ui.cc:326 #18 Kakoune::TerminalUI::Screen::output (force=force@entry=true, synchronized=<optimized out>, writer=...) at terminal_ui.cc:402 #19 Kakoune::TerminalUI::redraw (force=force@entry=true) at terminal_ui.cc:571 #20 Kakoune::TerminalUI::refresh (force=<optimized out>) at terminal_ui.cc:592 #21 Kakoune::Client::redraw_ifn () at client.cc:282 #22 Kakoune::ClientManager::redraw_clients () at client_manager.cc:232 #23 Kakoune::run_server (session=..., server_init=..., client_init=..., init_buffer="fish-rust/src/ast.rs", init_coord=..., flags=Kakoune::ServerFlags::None, ui_type=Kakoune::UIType::Terminal, debug_flags=<optimized out>, files=ArrayView<Kakoune::StringView> = {...}) at main.cc:893 #24 main (argc=<optimized out>, argv=<optimized out>) at main.cc:1243 Thereafter, "TerminalUI::Screen::output" resumes and crashes due to a buffer overflow in "lines" which has been resized.
2023-03-14Convert \r to \n in bracketed pastesMaxime Coste
It seems many terminals emits \r for newlines in bracketed pastes, manually convert this.
2023-03-13Slight refactoring of bracketed paste featureMaxime Coste
Handle begin/end paste directly in paste csi, manage paste buffer out of get_char, filter Key::Invalid earlier. get_next_key returning Key::Invalid means there was some input but it could not be represented as a Key. An empty optional means there was no input at all.
2023-03-11Implement bracketed pasteJohannes Altmanninger
Text pasted into Kakoune's normal mode is interpreted as command sequence, which is probably never what the user wants. Text pasted during insert mode will be inserted fine but may trigger auto-indentation hooks which is likely not what users want. Bracketed paste is pair of escape codes sent by terminals that allow applications to distinguish between pasted text and typed text. Let's use this feature to always insert pasted text verbatim, skipping keymap lookup and the InsertChar hook. In future, we could add a dedicated Paste hook. We need to make a decision on whether to paste before or after the selection. I chose "before" because that's what I'm used to. TerminalUI::set_on_key has EventManager::instance().force_signal(0); I'm not sure if we want the same for TerminalUI::set_on_paste? I assume it doesn't matter because they are always called in tandem. Closes #2465
2023-03-11Make TerminalUI::get_next_key() helpers staticJohannes Altmanninger
The only depend on the TerminalUI object which is a singleton, so we can make them all static.
2023-02-15Add option to set maximum info box widthAmeer Ghani
Some plugins (*cough* kak-lsp) and help texts tend to have immensely long content in a single line. This generates info boxes that span the entire terminal width. This is made especially worse on widescreen monitors or at small text size. This grants user control over how wide these boxes are. I deliberately avoid pushing this change to `kak-lsp` because it's not the only plugin that this could help--see the `hook` help text for an example of this problem in vanilla Kakoune. I would also suggest that since this is a rendering concern, it be handled by the terminal rendering logic.
2022-12-13Fix a couple bugs with underline highlightingMaxime Coste
Add missing curly_underline attribute to json-rpc Fix underline color not correct after attrbute only change
2022-09-17Fix crash when trying to display the menu in a tiny windowAdrià Arrufat
2021-12-11Make space a named key to correctly handle shift modifierMaxime Coste
2021-11-02use shifted key codes on kittyJason Felice
2021-11-02Fix DECRPM parsing for 2026Maxime Coste
As discovered in #4320 the previous code was buggy and would enable synchronized output on any response.
2021-10-29Fix terminal underline color not being properly resetMaxime Coste
2021-10-23Use DECRQM/DECRPM to detect support for synchronized outputMaxime Coste
Enable it if supported by default, let the user override it with the existing terminal_synchronized ui option. This should finalize work discussed on #4317
2021-09-26Restore diff based terminal output optimization when synchronizedMaxime Coste
terminal_synchronized ui_option now also controls this behaviour, update out of date documentation for ui_options as well. As discussed in #4317
2021-09-09Remove scrolling detection/optimization in terminal outputMaxime Coste
Just validate if line changed or not. This should avoid flickering on terminals such as the linux console that eagerly redraw on line deletions. Unfortunately this means drawing will use more data and might add a bit of latency on slow links. Fixes #4317 Fixes #4320
2021-09-07Add support for curly underline and separate underline colorMaxime Coste
Add support for a third color in face definition that controls the underline and a 'c' attribute for curly underline (that takes precedence over 'u' if both are specified) Allow empty colors to mean default, so that `,,red+u` means the same as `default,default,red+u` Fixes #4138
2021-09-02Remove unnecessary c_str() callsMaxime Coste
2021-09-02Remove terminal_wheel_up/down_button UI optionMaxime Coste
It seems nobody uses it, and it is not plugged through anyway. Closes #2642