diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2024-07-24 14:19:09 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2024-07-24 14:19:09 -0300 |
commit | 321abf096a1d82134180022bc16e596dc27b702f (patch) | |
tree | 94818a0fd3a3a62988b620b24fbd8839c155b651 | |
parent | f4e756f0cb72c3c7384e76b25e234de651691793 (diff) | |
download | finder-321abf096a1d82134180022bc16e596dc27b702f.tar.gz finder-321abf096a1d82134180022bc16e596dc27b702f.tar.bz2 |
feat make output buffer read-only
-rw-r--r-- | packages/finder/main.py | 20 | ||||
-rw-r--r-- | packages/finder/plugin/searcher/file/name.py | 4 |
2 files changed, 21 insertions, 3 deletions
diff --git a/packages/finder/main.py b/packages/finder/main.py index 21932c5..f562322 100644 --- a/packages/finder/main.py +++ b/packages/finder/main.py @@ -39,6 +39,7 @@ try: from prompt_toolkit.layout.controls import BufferControl, FormattedTextControl from prompt_toolkit.layout.margins import NumberedMargin, ScrollbarMargin from prompt_toolkit.enums import EditingMode + from prompt_toolkit.document import Document except ImportError: print("Please install prompt_toolkit first!") raise ImportError @@ -52,7 +53,14 @@ class FinderMain(): return True def change(self, _): - self.output_buffer.text = self.format(self.searcher.filter(self.input_field.text)) + # Text for the buffer + text = self.format(self.searcher.filter(self.input_field.text)) + + # This only works when the buffer is read-write + #self.output_buffer.text = text + + # For read-only buffers + self.output_buffer.set_document(Document(text), bypass_readonly=True) def open(self): item = self.output_buffer.document.current_line @@ -111,7 +119,7 @@ class FinderMain(): } # Buffers - self.output_buffer = Buffer() + self.output_buffer = Buffer(read_only = True) # UI fields self.output_field = BufferControl(buffer=self.output_buffer) @@ -162,8 +170,14 @@ class FinderMain(): self.searcher = FinderPluginFileNameSearcher(self.path) self.opener = FinderPluginFileXdgOpener() - self.output_buffer.text = self.format(await self.searcher.finder()) self.state['loading'] = False + text = self.format(await self.searcher.finder()) + + # This only works when the buffer is read-write + #self.output_buffer.text = text + + # For read-only buffers + self.output_buffer.set_document(Document(text), bypass_readonly=True) def run(self): return asyncio.run(self.main()) diff --git a/packages/finder/plugin/searcher/file/name.py b/packages/finder/plugin/searcher/file/name.py index 6cfeb87..b9c631c 100644 --- a/packages/finder/plugin/searcher/file/name.py +++ b/packages/finder/plugin/searcher/file/name.py @@ -52,6 +52,10 @@ class FinderPluginFileNameSearcher(): if file == ignore_file: continue + # Ignore hidden files + if file.startswith('.'): + continue + self.items.append(os.path.join(parent, file)) return self.items |