@@ -3,6 +3,7 @@ use crate::domain::models::ExtractionOptions;
33use crate :: domain:: models:: Languages ;
44use crate :: domain:: services:: theme_manager:: ThemeManager ;
55use crate :: domain:: services:: version_service:: VersionService ;
6+ use crate :: infrastructure:: console:: { Console , ConsoleImpl } ;
67use crate :: infrastructure:: logging;
78use crate :: presentation:: cli:: args:: Cli ;
89use crate :: presentation:: game:: { GameData , SessionManager } ;
@@ -16,6 +17,8 @@ use std::sync::{Arc, Mutex};
1617pub fn run_game_session ( cli : Cli ) -> Result < ( ) > {
1718 log:: info!( "Starting GitType game session" ) ;
1819
20+ let console = ConsoleImpl :: new ( ) ;
21+
1922 // Create single EventBus instance for the entire application
2023 let event_bus = EventBus :: new ( ) ;
2124
@@ -47,8 +50,11 @@ pub fn run_game_session(cli: Cli) -> Result<()> {
4750 // Initialize theme manager
4851 if let Err ( e) = ThemeManager :: init ( ) {
4952 log:: warn!( "Failed to initialize theme manager: {}" , e) ;
50- eprintln ! ( "⚠️ Warning: Failed to load theme configuration: {}" , e) ;
51- eprintln ! ( " Using default theme." ) ;
53+ console. eprintln ( & format ! (
54+ "⚠️ Warning: Failed to load theme configuration: {}" ,
55+ e
56+ ) ) ?;
57+ console. eprintln ( " Using default theme." ) ?;
5258 }
5359
5460 // Session repository will be initialized in DatabaseInitStep during loading screen
@@ -57,16 +63,16 @@ pub fn run_game_session(cli: Cli) -> Result<()> {
5763
5864 if let Some ( langs) = cli. langs {
5965 if let Err ( unsupported_langs) = Languages :: validate_languages ( & langs) {
60- eprintln ! (
66+ console . eprintln ( & format ! (
6167 "❌ Unsupported language(s): {}" ,
6268 unsupported_langs. join( ", " )
63- ) ;
64- eprintln ! ( "💡 Supported languages:" ) ;
69+ ) ) ? ;
70+ console . eprintln ( "💡 Supported languages:" ) ? ;
6571 let supported = Languages :: get_supported_languages ( ) ;
6672 let mut supported_display = supported. clone ( ) ;
6773 supported_display. dedup ( ) ;
6874 for chunk in supported_display. chunks ( 6 ) {
69- eprintln ! ( " {}" , chunk. join( ", " ) ) ;
75+ console . eprintln ( & format ! ( " {}" , chunk. join( ", " ) ) ) ? ;
7076 }
7177 std:: process:: exit ( 1 ) ;
7278 }
@@ -127,108 +133,113 @@ pub fn run_game_session(cli: Cli) -> Result<()> {
127133 }
128134 Err ( e) => {
129135 log:: error!( "Game session failed with error: {}" , e) ;
130- handle_game_error ( e) ?;
136+ handle_game_error ( & console , e) ?;
131137 }
132138 }
133139
134140 Ok ( ( ) )
135141}
136142
137- fn handle_game_error ( e : GitTypeError ) -> Result < ( ) > {
143+ fn handle_game_error ( console : & impl Console , e : GitTypeError ) -> Result < ( ) > {
138144 // Log the error details for debugging before handling user-friendly output
139145 logging:: log_error_to_file ( & e) ;
140146
141147 match e {
142148 GitTypeError :: NoSupportedFiles => {
143- eprintln ! ( "❌ No code chunks found in the repository" ) ;
144- eprintln ! ( "💡 Try:" ) ;
145- eprintln ! ( " • Using a different repository path" ) ;
146- eprintln ! ( " • Adjusting --langs filter (e.g., --langs rust,python)" ) ;
149+ console . eprintln ( "❌ No code chunks found in the repository" ) ? ;
150+ console . eprintln ( "💡 Try:" ) ? ;
151+ console . eprintln ( " • Using a different repository path" ) ? ;
152+ console . eprintln ( " • Adjusting --langs filter (e.g., --langs rust,python)" ) ? ;
147153 std:: process:: exit ( 1 ) ;
148154 }
149155 GitTypeError :: RepositoryNotFound ( path) => {
150- eprintln ! ( "❌ Repository not found at path: {}" , path. display( ) ) ;
151- eprintln ! ( "💡 Ensure the path exists and is a valid repository" ) ;
156+ console. eprintln ( & format ! (
157+ "❌ Repository not found at path: {}" ,
158+ path. display( )
159+ ) ) ?;
160+ console. eprintln ( "💡 Ensure the path exists and is a valid repository" ) ?;
152161 std:: process:: exit ( 1 ) ;
153162 }
154163 GitTypeError :: RepositoryCloneError ( git_error) => {
155- eprintln ! ( "❌ Failed to clone repository: {}" , git_error) ;
156- eprintln ! ( "💡 Check:" ) ;
157- eprintln ! ( " • Repository URL is correct" ) ;
158- eprintln ! ( " • You have access to the repository" ) ;
159- eprintln ! ( " • Internet connection is available" ) ;
164+ console . eprintln ( & format ! ( "❌ Failed to clone repository: {}" , git_error) ) ? ;
165+ console . eprintln ( "💡 Check:" ) ? ;
166+ console . eprintln ( " • Repository URL is correct" ) ? ;
167+ console . eprintln ( " • You have access to the repository" ) ? ;
168+ console . eprintln ( " • Internet connection is available" ) ? ;
160169 std:: process:: exit ( 1 ) ;
161170 }
162171 GitTypeError :: ExtractionFailed ( msg) => {
163- eprintln ! ( "❌ Code extraction failed: {}" , msg) ;
164- eprintln ! ( "💡 Try using different --langs filter" ) ;
172+ console . eprintln ( & format ! ( "❌ Code extraction failed: {}" , msg) ) ? ;
173+ console . eprintln ( "💡 Try using different --langs filter" ) ? ;
165174 std:: process:: exit ( 1 ) ;
166175 }
167176 GitTypeError :: InvalidRepositoryFormat ( msg) => {
168- eprintln ! ( "❌ Invalid repository format: {}" , msg) ;
169- eprintln ! ( "💡 Supported formats:" ) ;
170- eprintln ! ( " • owner/repo" ) ;
171- eprintln ! ( " • https://github.com/owner/repo" ) ;
172- eprintln ! ( " • git@github.com:owner/repo.git" ) ;
177+ console . eprintln ( & format ! ( "❌ Invalid repository format: {}" , msg) ) ? ;
178+ console . eprintln ( "💡 Supported formats:" ) ? ;
179+ console . eprintln ( " • owner/repo" ) ? ;
180+ console . eprintln ( " • https://github.com/owner/repo" ) ? ;
181+ console . eprintln ( " • git@github.com:owner/repo.git" ) ? ;
173182 std:: process:: exit ( 1 ) ;
174183 }
175184 GitTypeError :: IoError ( io_error) => {
176- eprintln ! ( "❌ IO error: {}" , io_error) ;
185+ console . eprintln ( & format ! ( "❌ IO error: {}" , io_error) ) ? ;
177186 std:: process:: exit ( 1 ) ;
178187 }
179188 GitTypeError :: DatabaseError ( db_error) => {
180- eprintln ! ( "❌ Database error: {}" , db_error) ;
189+ console . eprintln ( & format ! ( "❌ Database error: {}" , db_error) ) ? ;
181190 std:: process:: exit ( 1 ) ;
182191 }
183192 GitTypeError :: GlobPatternError ( glob_error) => {
184- eprintln ! ( "❌ Invalid glob pattern: {}" , glob_error) ;
185- eprintln ! ( "💡 Check your glob patterns in ExtractionOptions" ) ;
193+ console . eprintln ( & format ! ( "❌ Invalid glob pattern: {}" , glob_error) ) ? ;
194+ console . eprintln ( "💡 Check your glob patterns in ExtractionOptions" ) ? ;
186195 std:: process:: exit ( 1 ) ;
187196 }
188197 GitTypeError :: SerializationError ( json_error) => {
189- eprintln ! ( "❌ Serialization error: {}" , json_error) ;
198+ console . eprintln ( & format ! ( "❌ Serialization error: {}" , json_error) ) ? ;
190199 std:: process:: exit ( 1 ) ;
191200 }
192201 GitTypeError :: TerminalError ( msg) => {
193- eprintln ! ( "❌ Terminal error: {}" , msg) ;
202+ console . eprintln ( & format ! ( "❌ Terminal error: {}" , msg) ) ? ;
194203 if msg. contains ( "No such device or address" ) {
195- eprintln ! ( "💡 This error often occurs in WSL or SSH environments where terminal features are limited." ) ;
196- eprintln ! ( " Try running GitType in a native terminal or GUI terminal emulator." ) ;
204+ console. eprintln ( "💡 This error often occurs in WSL or SSH environments where terminal features are limited." ) ?;
205+ console. eprintln (
206+ " Try running GitType in a native terminal or GUI terminal emulator." ,
207+ ) ?;
197208 }
198209 std:: process:: exit ( 1 ) ;
199210 }
200211 GitTypeError :: WalkDirError ( walk_error) => {
201- eprintln ! ( "❌ Directory walk error: {}" , walk_error) ;
202- eprintln ! ( "💡 Check directory permissions and try again" ) ;
212+ console . eprintln ( & format ! ( "❌ Directory walk error: {}" , walk_error) ) ? ;
213+ console . eprintln ( "💡 Check directory permissions and try again" ) ? ;
203214 std:: process:: exit ( 1 ) ;
204215 }
205216 GitTypeError :: TreeSitterLanguageError ( lang_error) => {
206- eprintln ! ( "❌ Language parsing error: {}" , lang_error) ;
207- eprintln ! ( "💡 This might be caused by unsupported language features" ) ;
217+ console . eprintln ( & format ! ( "❌ Language parsing error: {}" , lang_error) ) ? ;
218+ console . eprintln ( "💡 This might be caused by unsupported language features" ) ? ;
208219 std:: process:: exit ( 1 ) ;
209220 }
210221 GitTypeError :: PanicError ( msg) => {
211- eprintln ! ( "💥 Application panic occurred: {}" , msg) ;
212- eprintln ! ( "💡 This indicates an unexpected error. Please report this issue." ) ;
222+ console . eprintln ( & format ! ( "💥 Application panic occurred: {}" , msg) ) ? ;
223+ console . eprintln ( "💡 This indicates an unexpected error. Please report this issue." ) ? ;
213224 std:: process:: exit ( 1 ) ;
214225 }
215226 GitTypeError :: HttpError ( http_error) => {
216- eprintln ! ( "❌ HTTP request failed: {}" , http_error) ;
217- eprintln ! ( "💡 Check your internet connection and try again" ) ;
227+ console . eprintln ( & format ! ( "❌ HTTP request failed: {}" , http_error) ) ? ;
228+ console . eprintln ( "💡 Check your internet connection and try again" ) ? ;
218229 std:: process:: exit ( 1 ) ;
219230 }
220231 GitTypeError :: ApiError ( msg) => {
221- eprintln ! ( "❌ API error: {}" , msg) ;
222- eprintln ! ( "💡 The service may be temporarily unavailable" ) ;
232+ console . eprintln ( & format ! ( "❌ API error: {}" , msg) ) ? ;
233+ console . eprintln ( "💡 The service may be temporarily unavailable" ) ? ;
223234 std:: process:: exit ( 1 ) ;
224235 }
225236 GitTypeError :: ValidationError ( msg) => {
226- eprintln ! ( "❌ {}" , msg) ;
237+ console . eprintln ( & format ! ( "❌ {}" , msg) ) ? ;
227238 std:: process:: exit ( 1 ) ;
228239 }
229240 GitTypeError :: ScreenInitializationError ( msg) => {
230- eprintln ! ( "❌ Screen initialization error: {}" , msg) ;
231- eprintln ! ( "💡 This is an internal error. Please report this issue." ) ;
241+ console . eprintln ( & format ! ( "❌ Screen initialization error: {}" , msg) ) ? ;
242+ console . eprintln ( "💡 This is an internal error. Please report this issue." ) ? ;
232243 std:: process:: exit ( 1 ) ;
233244 }
234245 }
0 commit comments