Compare commits

...

1 Commits

Author SHA1 Message Date
Sebastian Lohff 237900e362 Broken search 4 years ago
  1. 37
      clintermission/climenu.py

37
clintermission/climenu.py

@ -3,6 +3,8 @@ @@ -3,6 +3,8 @@
from prompt_toolkit.application import Application
from prompt_toolkit.buffer import Buffer
from prompt_toolkit.document import Document
from prompt_toolkit.filters import is_searching
from prompt_toolkit.filters.base import Condition
from prompt_toolkit.key_binding import KeyBindings
from prompt_toolkit.layout import Layout, Window, HSplit
from prompt_toolkit.layout.controls import BufferControl
@ -68,6 +70,12 @@ class CliMenuTheme: @@ -68,6 +70,12 @@ class CliMenuTheme:
ANSI_CYAN = CliMenuStyle('ansicyan', 'ansibrightcyan', 'ansicyan')
@Condition
def is_not_searching():
print("CALLED IT")
return not is_searching()
class CliMenu:
default_stye = CliMenuTheme.BASIC
default_cursor = CliMenuCursor.TRIANGLE
@ -139,6 +147,8 @@ class CliMenu: @@ -139,6 +147,8 @@ class CliMenu:
return ' ' * (len(self._cursor) + 1 * self._dedent_selection)
def _transform_line(self, ti):
if len(list(ti.fragments)) == 0:
return Transformation(ti.fragments)
style, text = list(ti.fragments)[0]
item = self._items[ti.lineno]
s = self._style
@ -160,7 +170,9 @@ class CliMenu: @@ -160,7 +170,9 @@ class CliMenu:
indent += ' ' * (self._header_indent + len(self._cursor) + 1)
style = s.header_style
return Transformation([('', indent), (style, prefix + text)])
items = [(s if s else style, t) for s, t in ti.fragments]
return Transformation([('', indent), (style, prefix)] + items)
def next_item(self, direction):
if not any(item.focusable for item in self._items):
@ -198,21 +210,40 @@ class CliMenu: @@ -198,21 +210,40 @@ class CliMenu:
def up(event):
self.next_item(-1)
@self._kb.add('n')
def search_inc(event, filter=is_searching):
print(self._bufctrl.search_state.text)
print("curr pos", self._buf.get_search_position(self._bufctrl.search_state))
# search_state.direction = search.SearchDirection.BACKWARD
next10 = []
for i in range(10):
p = self._buf.get_search_position(self._bufctrl.search_state, count=i + 1, include_current_position=False)
next10.append(p)
print("next 10 pos are", next10)
#search.do_incremental_search(search.SearchDirection.FORWARD)
@self._kb.add('right')
@self._kb.add('c-m')
#@self._kb.add('c-m')
@self._kb.add('c-space')
def accept(event):
self._success = True
event.app.exit()
self._searchbar = SearchToolbar(text_if_not_searching=[('class:not-searching', 'NOOT NOOT')], ignore_case=True)
text = '\n'.join(map(lambda _x: _x.text, self._items))
self._doc = Document(text, cursor_position=self._pos)
self._buf = Buffer(read_only=True, document=self._doc)
self._bufctrl = BufferControl(self._buf,
search_buffer_control=self._searchbar.control,
preview_search=True,
input_processors=[MenuColorizer()])
split = HSplit([Window(self._bufctrl,
wrap_lines=True,
always_hide_cursor=True)])
always_hide_cursor=True),
self._searchbar])
# set initial pos
if not self._items[self._pos].focusable:

Loading…
Cancel
Save