1- from typing import Any , Protocol , Optional , List
2- from dataclasses import dataclass
1+ # Copyright 2026 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2+ #
3+ # Licensed under the Apache License, Version 2.0 (the "License");
4+ # you may not use this file except in compliance with the License.
5+ # You may obtain a copy of the License at
6+ #
7+ # http://www.apache.org/licenses/LICENSE-2.0
8+ #
9+ # Unless required by applicable law or agreed to in writing, software
10+ # distributed under the License is distributed on an "AS IS" BASIS,
11+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ # See the License for the specific language governing permissions and
13+ # limitations under the License.
14+
315import os
416import subprocess
517import sys
18+ from dataclasses import dataclass
19+ from typing import Any , Optional , Protocol
620
721
822def write_terminal_sequence (sequence : str ) -> None :
@@ -19,25 +33,14 @@ def write_terminal_sequence(sequence: str) -> None:
1933 sys .stdout .write (sequence )
2034 sys .stdout .flush ()
2135 except Exception :
22- # best-effort: ignore
2336 pass
2437
2538
2639class TerminalAdapter (Protocol ):
2740 """
28- Protocol implemented by terminal-specific adapters.
29-
30- Parent class for each terminal adapter.
31- Done:
32- - GNOME
33-
34- TODO:
35- - Terminator
36- - Zsh
37- - Kitty
38- - XTerm
39- - Alackritty
40- - Alacritty
41+ Abstract parent class to enhance VulcanAI visualization in each terminal.
42+ Currently supported: Gnome
43+ Not yet implemented: Terminator, Zsh
4144 """
4245
4346 name : str
@@ -48,9 +51,11 @@ def apply(self) -> Any: ...
4851
4952 def restore (self , state : Any ) -> None : ...
5053
54+
5155# region TERMINALS
5256
53- # region gnome
57+ # region gnome
58+
5459
5560def _run_gsettings (* args : str ) -> Optional [str ]:
5661 """
@@ -90,19 +95,19 @@ def detect(self) -> bool:
9095 @brief Detect whether the current terminal is GNOME Terminal.
9196 @return ``True`` when GNOME Terminal environment markers are found.
9297 """
93- terminal_emulator = os .environ .get ("TERMINAL_EMULATOR" , "" ).lower ()
94- term_program = os .environ .get ("TERM_PROGRAM" , "" ).lower ()
95- return (
96- "gnome-terminal" in terminal_emulator
97- or "gnome-terminal" in term_program
98- or "GNOME_TERMINAL_SCREEN" in os .environ
98+ is_gnome = (
99+ "GNOME_TERMINAL_SCREEN" in os .environ
100+ or "gnome-terminal" in os .environ .get ("TERMINAL_EMULATOR" , "" ).lower ()
101+ or "gnome-terminal" in os .environ .get ("TERM_PROGRAM" , "" ).lower ()
99102 )
103+ return is_gnome
100104
101105 def apply (self ) -> Optional [GnomeState ]:
102106 """
103107 @brief Hide GNOME scrollbar and return state for later restoration.
104108 @return ``GnomeState`` when the change is applied/confirmed, else ``None``.
105109 """
110+ # The return value could be None, empty string or string with just single quotes
106111 profile_id = _run_gsettings ("get" , "org.gnome.Terminal.ProfilesList" , "default" )
107112 if not profile_id :
108113 return None
@@ -137,17 +142,20 @@ def restore(self, state: Optional[GnomeState]) -> None:
137142 # endregion
138143
139144 # region TERMINATOR
145+
146+
140147# TODO
141- # endregion
148+ # endregion
142149
143- # region ZSH
150+ # region ZSH
144151# TODO
145- # endregion
152+ # endregion
146153
147154# endregion
148155
149156# region SESSION
150157
158+
151159@dataclass
152160class TerminalSessionConfig :
153161 """@brief Runtime options controlling generic terminal tweaks."""
@@ -165,11 +173,8 @@ class TerminalSession:
165173 Session helper that applies terminal tweaks and safely restores them.
166174 """
167175
168- def __init__ (self , adapters : List [TerminalAdapter ], config : TerminalSessionConfig ):
169- """
170- Build a terminal session with a list of adapters.
171- """
172- self .adapters = adapters
176+ def __init__ (self , config : TerminalSessionConfig ):
177+ self .adapters = [GnomeTerminalAdapter ()]
173178 self .config = config
174179 self ._active : list [tuple [TerminalAdapter , Any ]] = []
175180
@@ -225,4 +230,5 @@ def __exit__(self, exc_type, exc, tb):
225230 self .end ()
226231 return False
227232
228- # endregion
233+
234+ # endregion
0 commit comments