diff --git a/vendor/bruit/src/bruit.ml b/vendor/bruit/src/bruit.ml index afdebb1..9ac8020 100644 --- a/vendor/bruit/src/bruit.ml +++ b/vendor/bruit/src/bruit.ml @@ -147,7 +147,7 @@ let with_raw_mode (state : State.t) fn = c_vmin = 1; } in - Unix.tcsetattr state.ifd TCSAFLUSH tio; + Unix.tcsetattr state.ifd TCSADRAIN tio; Fun.protect ~finally:(fun () -> Unix.tcsetattr state.ifd TCSADRAIN saved_tio) fn @@ -386,6 +386,28 @@ let move_right (state : State.t) = in refresh_line s +let move_right_next_word (state : State.t) = + let pos = ref state.pos in + while !pos < state.len && Bytes.get state.buf !pos = ' ' do + incr pos + done; + while !pos < state.len && Bytes.get state.buf !pos <> ' ' do + incr pos + done; + let s = State.override ~pos:!pos state in + refresh_line s + +let move_left_next_word (state : State.t) = + let pos = ref state.pos in + while !pos > 0 && Bytes.get state.buf !pos = ' ' do + decr pos + done; + while !pos > 0 && Bytes.get state.buf !pos <> ' ' do + decr pos + done; + let s = State.override ~pos:!pos state in + refresh_line s + let reverse_incr_search ~history (state : State.t) = let has_match = ref true in let search_buf = Buffer.create 16 in @@ -539,19 +561,49 @@ let edit_feed ~history state = | Backspace -> Editing (edit_backspace state) | Tab -> Editing state | Escape_sequence -> ( - let c1 = + let c0 = read_char state |> function `Some c -> c | _ -> assert false in - let c2 = - read_char state |> function `Some c -> c | _ -> assert false - in - match (c1, c2) with - | '[', 'A' -> Editing (edit_history `Prev history state) - | '[', 'B' -> Editing (edit_history `Next history state) - | '[', 'C' -> Editing (move_right state) - | '[', 'D' -> Editing (move_left state) + match c0 with + | '[' -> + let c1 = + read_char state |> function + | `Some c -> c + | _ -> assert false + in + if Char.compare c1 '0' >= 0 && Char.compare c1 '9' <= 0 then + let c2 = + read_char state |> function + | `Some c -> c + | _ -> assert false + in + let c3 = + match read_char state with + | `Some c -> Some c + | (exception _) | _ -> None + in + let c4 = + match read_char state with + | `Some c -> Some c + | (exception _) | _ -> None + in + match (c2, c3) with + | ';', Some '5' -> ( + match c4 with + | Some 'D' -> Editing (move_left_next_word state) + | Some 'C' -> Editing (move_right_next_word state) + | _ -> Editing state) + | _ -> Editing state + else begin + match c1 with + | 'A' -> Editing (edit_history `Prev history state) + | 'B' -> Editing (edit_history `Next history state) + | 'C' -> Editing (move_right state) + | 'D' -> Editing (move_left state) + | _ -> Editing state + end | _ -> Editing state) - | Unknown _ | _ -> + | _ -> let state = edit_insert state uc in Editing state))