mirror of
https://github.com/mistralai/mistral-vibe
synced 2026-04-26 01:24:55 +02:00
Co-authored-by: Clément Sirieix <clement.sirieix@mistral.ai> Co-authored-by: Kim-Adeline Miguel <kimadeline.miguel@mistral.ai> Co-authored-by: Lucas Marandat <31749711+lucasmrdt@users.noreply.github.com> Co-authored-by: Michel Thomazo <51709227+michelTho@users.noreply.github.com> Co-authored-by: Paul Cacheux <paul.cacheux@mistral.ai> Co-authored-by: Peter Evers <pevers90@gmail.com> Co-authored-by: Pierre Rossinès <pierre.rossines@mistral.ai> Co-authored-by: Pierre Rossinès <pierre.rossines@protonmail.com> Co-authored-by: Quentin <quentin.torroba@mistral.ai> Co-authored-by: Simon Van de Kerckhove <simon.vandekerckhove@mistral.ai> Co-authored-by: Val <102326092+vdeva@users.noreply.github.com> Co-authored-by: Vincent G <10739306+VinceOPS@users.noreply.github.com> Co-authored-by: Mistral Vibe <vibe@mistral.ai>
46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from rich.text import Text
|
|
from textual.widgets import Static
|
|
|
|
|
|
class CompletionPopup(Static):
|
|
def __init__(self, **kwargs: Any) -> None:
|
|
super().__init__("", id="completion-popup", **kwargs)
|
|
self.styles.display = "none"
|
|
self.can_focus = False
|
|
|
|
def update_suggestions(
|
|
self, suggestions: list[tuple[str, str]], selected: int
|
|
) -> None:
|
|
if not suggestions:
|
|
self.hide()
|
|
return
|
|
|
|
text = Text()
|
|
for idx, (label, description) in enumerate(suggestions):
|
|
if idx:
|
|
text.append("\n")
|
|
|
|
label_style = "bold reverse" if idx == selected else "bold"
|
|
description_style = "italic" if idx == selected else "dim"
|
|
|
|
text.append(self._display_label(label), style=label_style)
|
|
if description:
|
|
text.append(" ")
|
|
text.append(description, style=description_style)
|
|
|
|
self.update(text)
|
|
self.styles.display = "block"
|
|
|
|
def hide(self) -> None:
|
|
self.update("")
|
|
self.styles.display = "none"
|
|
|
|
def _display_label(self, label: str) -> str:
|
|
if label.startswith("@"):
|
|
return label[1:]
|
|
return label
|