Raxol.Search.Fuzzy (Raxol v2.0.1)

View Source

Search system with fuzzy, exact, and regex matching.

Provides multiple search modes for finding text in terminal buffers:

  • Fuzzy matching (like fzf)
  • Exact string matching
  • Regular expression matching
  • Result highlighting
  • Navigation with n/N

Example

buffer = Buffer.create_blank_buffer(80, 24)
# ... populate buffer ...

# Fuzzy search
results = Fuzzy.search(buffer, "hlo", :fuzzy)
# Matches "hello", "halo", etc.

# Exact search
results = Fuzzy.search(buffer, "hello", :exact)

# Regex search
results = Fuzzy.search(buffer, ~r/h.llo/, :regex)

Summary

Functions

Get all match positions.

Get current match position.

Get search statistics.

Highlight search results in buffer.

Create a new search state.

Navigate to next match.

Navigate to previous match.

Perform a search on the buffer.

Update search query and find new matches.

Types

match()

@type match() :: %{
  position: position(),
  text: String.t(),
  score: float(),
  highlight: [{non_neg_integer(), non_neg_integer()}]
}

position()

@type position() :: {non_neg_integer(), non_neg_integer()}

search_mode()

@type search_mode() :: :fuzzy | :exact | :regex

t()

@type t() :: %Raxol.Search.Fuzzy{
  buffer: Raxol.Core.Buffer.t(),
  case_sensitive: boolean(),
  current_index: non_neg_integer(),
  matches: [match()],
  mode: search_mode(),
  query: String.t()
}

Functions

get_all_matches(map)

@spec get_all_matches(t()) :: [position()]

Get all match positions.

get_current_match(arg1)

@spec get_current_match(t()) :: match() | nil

Get current match position.

get_stats(map)

@spec get_stats(t()) :: map()

Get search statistics.

highlight_matches(buffer, matches, style \\ %{})

@spec highlight_matches(Raxol.Core.Buffer.t(), [match()], map()) ::
  Raxol.Core.Buffer.t()

Highlight search results in buffer.

Returns a new buffer with highlighted matches.

new(buffer, opts \\ %{})

@spec new(Raxol.Core.Buffer.t(), map()) :: t()

Create a new search state.

next_match(state)

@spec next_match(t()) :: t()

Navigate to next match.

previous_match(state)

@spec previous_match(t()) :: t()

Navigate to previous match.

search(buffer, query, mode \\ :fuzzy, opts \\ %{})

@spec search(Raxol.Core.Buffer.t(), String.t(), search_mode(), map()) :: [match()]

Perform a search on the buffer.

update_query(state, query)

@spec update_query(t(), String.t()) :: t()

Update search query and find new matches.