open Base type t = { prompt : Key.t; content : char Zipper.t } type result = Search of bool * char Sequence.t | No_result let create prompt = { prompt; content = Zipper.empty } let render c = let prompt = Key.to_string c.prompt |> String.to_list and content = c.content |> Zipper.to_seq in Sequence.shift_right_with_list content prompt let is_search c = match c.prompt with Key '/' | Key '?' -> true | _ -> false let cursor c = String.length (Key.to_string c.prompt) + Zipper.left_length c.content + 1 let get_result c = let open Zipper in match c.prompt with | Key '/' -> Search (true, c.content |> to_seq) | Key '?' -> Search (false, c.content |> to_seq) | _ -> No_result let set_content s c = { c with content = Zipper.(of_seq s |> far_right) } let move_left c = { c with content = Zipper.left c.content } let move_right c = { c with content = Zipper.right c.content } let delete_before c = { c with content = Zipper.pop_before c.content |> snd } let delete_after c = { c with content = Zipper.pop c.content |> snd } let bol c = { c with content = Zipper.far_left c.content } let eol c = { c with content = Zipper.far_right c.content } let insert k c = { c with content = Zipper.push_before k c.content }