@@ -286,6 +286,42 @@ gsh_post_closedb_clbk(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(
286
286
return BRLCAD_OK;
287
287
}
288
288
289
+ extern " C" int
290
+ gsh_db_search_callback (int argc, const char *argv[], void *UNUSED (u1), void *u2)
291
+ {
292
+ GshState *s = (GshState *)u2;
293
+ struct ged *gedp = s->gedp ;
294
+
295
+ // Stash any pre-existing non-exec output so it isn't mixed in with the
296
+ // results of the exec itself.
297
+ struct bu_vls tmp_rstr = BU_VLS_INIT_ZERO;
298
+ bu_vls_sprintf (&tmp_rstr, " %s" , bu_vls_cstr (gedp->ged_result_str ));
299
+
300
+ // Make sure the result string buffer is clear
301
+ bu_vls_trunc (gedp->ged_result_str , 0 );
302
+
303
+ // Do the actual command execution
304
+ int gret = ged_exec (gedp, argc, argv);
305
+
306
+ // Immediately report the output, if any - we're not waiting for the
307
+ // overall completion of the entire search command to provide user feedback
308
+ // on the exec results. Make sure to add a \n character at the end if the
309
+ // command didn't provide it.
310
+ if (bu_vls_strlen (gedp->ged_result_str )) {
311
+ std::string rstr (bu_vls_cstr (gedp->ged_result_str ));
312
+ if (rstr.length () && rstr.c_str ()[rstr.length () - 1 ] != ' \n ' )
313
+ rstr.append (" \n " );
314
+ bu_log (" %s" , rstr.c_str ());
315
+ }
316
+
317
+ /* Restore any non-exec output */
318
+ bu_vls_sprintf (gedp->ged_result_str , " %s" , bu_vls_cstr (&tmp_rstr));
319
+ bu_vls_free (&tmp_rstr);
320
+
321
+ return BRLCAD_OK == gret;
322
+ }
323
+
324
+
289
325
/* Cross platform I/O subprocess listening is tricky. Tcl and Qt both have
290
326
* specific logic necessary for their environments. Even the minimalist
291
327
* command line environment has some basic requirements that must be met.
@@ -348,6 +384,8 @@ GshState::GshState()
348
384
ged_clbk_set (gedp, " closedb" , BU_CLBK_PRE, &gsh_pre_closedb_clbk, (void *)this );
349
385
ged_clbk_set (gedp, " closedb" , BU_CLBK_POST, &gsh_post_closedb_clbk, (void *)this );
350
386
387
+ // Register search exec callback
388
+ ged_clbk_set (gedp, " search" , BU_CLBK_DURING, &gsh_db_search_callback, (void *)this );
351
389
352
390
// Assign gsh specific I/O handlers to the gedp
353
391
gedp->ged_create_io_handler = &gsh_create_io_handler;
@@ -389,7 +427,7 @@ GshState::eval(int argc, const char **argv)
389
427
return BRLCAD_ERROR;
390
428
}
391
429
392
- // We've got a valid GED command Before any BRL-CAD logic is executed;
430
+ // We've got a valid GED command. Before any BRL-CAD logic is executed,
393
431
// stash the state of the view info so we can recognize changes.
394
432
view_checkpoint ();
395
433
0 commit comments